Created
December 1, 2014 01:48
-
-
Save quark-zju/fe164294fc478fdb9fff to your computer and use it in GitHub Desktop.
Revisions
-
quark-zju created this gist
Dec 1, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ #!/usr/bin/env ruby # Find git root while !File.exists?('.git/config') Dir.chdir('..') raise 'git root not found' if Dir.pwd == '/' end args = ARGV if args.empty? args = File.read('.pushf').split rescue [] end args.each do |arg| # Run git push hostname, path = arg.split(':') if !path || path.empty? path = File.basename(Dir.pwd) end if path.empty? puts 'unsupported' exit 1 end if system 'git', 'push', '-f', "#{hostname}:#{path}" system 'git', 'push', '--tags', '-f', "#{hostname}:#{path}" else system "ssh #{hostname} '[ ! -e #{path}/.git ] && mkdir -p #{path} && cd #{path} && git init && git config receive.denyCurrentBranch ignore'" system 'git', 'push', '-f', "#{hostname}:#{path}" end head = `git rev-parse HEAD`.chomp system "ssh #{hostname} 'cd #{path} && echo #{head} > .git/HEAD && git reset --hard HEAD'" end if args.empty? puts 'git pushf host1[:path] [host2[:path]] ...' end