Created
July 4, 2013 01:40
-
-
Save fujimura/5924289 to your computer and use it in GitHub Desktop.
show current branches of git repo under current directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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