Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Revision: 10/12/2011 9:13:05 AM
- # TODO recognize more git commands
- # TODO better handling of aliases as not all have my custom aliases :(
- # TODO code clean this little experiment
- # TODO enable full git subcommand options to be passed to git
- root = File.expand_path File.dirname(__FILE__)
- def usage_and_exit(msg=USAGE, code=-1)
- STDERR.puts msg
- exit(code)
- end
- USAGE = <<-EOT
- usage: git all GIT_COMMAND
- where GIT_COMMAND is one of:
- br branch
- fetch fetch
- st status
- EOT
- VALID_CMDS = [
- :br,
- :fetch,
- :st,
- ]
- usage_and_exit unless ARGV.length > 0
- options = {}
- options[:debug] = ARGV.delete('--debug') || ARGV.delete('-d')
- cmd = ARGV.shift.downcase.to_sym
- usage_and_exit unless VALID_CMDS.include?(cmd)
- require 'open3'
- begin
- require 'psych'
- rescue LoadError
- ensure
- require 'yaml'
- end
- begin
- excludes = YAML.load_file('.gitall_ignore')
- rescue ::Exception
- STDERR.puts %q[No '.gitall_ignore' found; processing all '*-git' dirs...]
- end
- updated = []
- Dir.glob('*-git').each do |dir|
- if excludes
- next if excludes.include?(dir)
- end
- Dir.chdir(dir) do
- puts "[#{cmd.upcase}] #{dir}"
- results, status = Open3.capture2e("git #{cmd}", :binmode => true)
- case cmd
- when :st, :br
- puts results
- when :fetch
- #unless results.empty?
- if results =~ /^From/
- updated << dir
- puts results
- end
- end
- print "Exit status: #{status.exitstatus}\n\n" if options[:debug]
- end
- end
- if updated.length > 0
- puts <<-EOT
- The following repos were updated:
- #{updated.join("\n")}
- EOT
- end
Add Comment
Please, Sign In to add comment