Skip to content

Instantly share code, notes, and snippets.

@yuya-matsushima
Last active December 20, 2015 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuya-matsushima/6106788 to your computer and use it in GitHub Desktop.
Save yuya-matsushima/6106788 to your computer and use it in GitHub Desktop.
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