Skip to content

Instantly share code, notes, and snippets.

@yterajima yterajima/remoterepo.sh
Last active Dec 20, 2015

Embed
What would you like to do?
remoterepo.shのコード公開版
#!/usr/bin/env ruby
# coding: utf-8
conf_dir = '/path/to/gitlite/path/conf_dir/'
conf = conf_dir + 'gitolite.conf'
current = Dir::pwd.split('/').pop
new_repo = ARGV[0].to_s
if new_repo.empty?
puts "作成したいリポジトリ名を指定してください"
exit
end
if new_repo == '-l' || new_repo == '--list' || new_repo == 'list'
list = []
File.open(conf) {|f|
f.each_line {|line|
list << line.gsub(/^repo\s/, '').strip if /^repo/ =~ line
}
}
puts list.join("\n")
exit
end
# 存在しない場合には終了
if !File.exist?(conf)
puts "gitolite.conf が存在しません"
exit
end
exist_flag = false
File.open(conf) {|f|
f.each_line {|line|
repo = line.gsub(/^repo\s/, '').strip if /^repo/ =~ line
if repo == new_repo
exist_flag = true
break
end
}
}
if !exist_flag
# 更新を pull
Dir.chdir(conf_dir) {
system('git pull --rebase origin master')
print 1
str = "\nrepo " + new_repo
str += "\n RW+ = @develop @design\n"
open(conf, 'a') {|file|
file.write(str)
}
system("git add . ")
system("git commit -m 'Added #{new_repo}'")
system("git push origin master")
}
puts "新しいリモートリポジトリを追加しました"
puts "次を実行: git remote add origin git@your_server_domain.com:#{new_repo}.git"
else
puts "同名のリポジトリが定義されています"
exit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.