Skip to content

Instantly share code, notes, and snippets.

@SethMilliken
Created September 15, 2011 04:51
Show Gist options
  • Save SethMilliken/1218572 to your computer and use it in GitHub Desktop.
Save SethMilliken/1218572 to your computer and use it in GitHub Desktop.
git command to apply same command to multiple work trees
#!/usr/bin/env ruby
require 'open3'
include Open3
# TODO: use colors in output
def gitworld(command)
home = ENV["HOME"]
paths = [ \
"", \
"bin", \
".vim", \
".vim/bundle/vim-traitor", \
".vim/bundle/vimple", \
".pentadactyl", \
".oh-my-zsh" \
"sandbox/work", \
"sandbox/personal", \
]
paths.each do |path|
fullpath = "#{home}/#{path}"
if File.directory? fullpath
Dir.chdir("#{fullpath}")
popen3("git #{command}") do |stdin, stdout, stderr, wait_thr|
output = stdout.read
error = stderr.read
printf "============================[ %30s ]=======\n%s", path, output
puts "" if output.length > 0
print stderr.read
puts "" if error.length > 0
end
end
end
end
if ARGV[0].nil?
command = "state"
else
command = ARGV
end
puts "Running `git #{command}` on all repositories..."
gitworld command
# vim: set ft=ruby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment