#!/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