Guest User

Untitled

a guest
Jan 19th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1.  
  2. # Revision: 10/12/2011 9:13:05 AM
  3.  
  4. # TODO recognize more git commands
  5. # TODO better handling of aliases as not all have my custom aliases :(
  6. # TODO code clean this little experiment
  7. # TODO enable full git subcommand options to be passed to git
  8.  
  9. root = File.expand_path File.dirname(__FILE__)
  10.  
  11. def usage_and_exit(msg=USAGE, code=-1)
  12. STDERR.puts msg
  13. exit(code)
  14. end
  15.  
  16. USAGE = <<-EOT
  17. usage: git all GIT_COMMAND
  18.  
  19. where GIT_COMMAND is one of:
  20. br branch
  21. fetch fetch
  22. st status
  23. EOT
  24.  
  25. VALID_CMDS = [
  26. :br,
  27. :fetch,
  28. :st,
  29. ]
  30.  
  31. usage_and_exit unless ARGV.length > 0
  32.  
  33. options = {}
  34. options[:debug] = ARGV.delete('--debug') || ARGV.delete('-d')
  35.  
  36. cmd = ARGV.shift.downcase.to_sym
  37. usage_and_exit unless VALID_CMDS.include?(cmd)
  38.  
  39. require 'open3'
  40.  
  41. begin
  42. require 'psych'
  43. rescue LoadError
  44. ensure
  45. require 'yaml'
  46. end
  47.  
  48. begin
  49. excludes = YAML.load_file('.gitall_ignore')
  50. rescue ::Exception
  51. STDERR.puts %q[No '.gitall_ignore' found; processing all '*-git' dirs...]
  52. end
  53.  
  54. updated = []
  55.  
  56. Dir.glob('*-git').each do |dir|
  57. if excludes
  58. next if excludes.include?(dir)
  59. end
  60.  
  61. Dir.chdir(dir) do
  62. puts "[#{cmd.upcase}] #{dir}"
  63.  
  64. results, status = Open3.capture2e("git #{cmd}", :binmode => true)
  65.  
  66. case cmd
  67. when :st, :br
  68. puts results
  69. when :fetch
  70. #unless results.empty?
  71. if results =~ /^From/
  72. updated << dir
  73. puts results
  74. end
  75. end
  76.  
  77. print "Exit status: #{status.exitstatus}\n\n" if options[:debug]
  78. end
  79. end
  80.  
  81. if updated.length > 0
  82. puts <<-EOT
  83.  
  84. The following repos were updated:
  85.  
  86. #{updated.join("\n")}
  87. EOT
  88. end
Add Comment
Please, Sign In to add comment