Skip to content

Instantly share code, notes, and snippets.

@fujimura
Created July 4, 2013 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fujimura/5924289 to your computer and use it in GitHub Desktop.
Save fujimura/5924289 to your computer and use it in GitHub Desktop.
show current branches of git repo under current directory
#! /usr/bin/env ruby
# Pull all directory under current directory, if it's on master, has no local changes, can be pulled fast-forward.
def git_repo?
`git status`.chomp !~ /Not a git repository/
end
def not_changed?
`git status -s`.chomp.empty?
end
def master?
# .gitconfig
# current-branch = "!sh -c \"git branch | grep '*' | awk '{ print \\$2 }' \""
`git current-branch`.chomp == 'master'
end
list = Dir['./*'].select {|d| File.directory? d }.map do |d|
Dir.chdir(d) { git_repo? && [d, `git current-branch`.strip ] }
end.compact
l = list.map(&:first).map(&:length).max + 1
list.each {|dir, branch|
puts "#{dir.ljust(l)}: #{branch}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment