Skip to content

Instantly share code, notes, and snippets.

@spikeheap
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save spikeheap/227be6f9664bc92b7378 to your computer and use it in GitHub Desktop.

Select an option

Save spikeheap/227be6f9664bc92b7378 to your computer and use it in GitHub Desktop.
Get the Git status of all subdirectories of a directory. Prints a simple summary. Not recursive...
#!/usr/bin/env ruby
ARGV.each do |arg|
not_repo = []
unstaged = []
untracked = []
puts "Looking in #{arg}"
all_dirs = Dir.entries(arg).select {|entry| File.directory? File.join(arg,entry) and !(entry =='.' || entry == '..') }
all_dirs.each do |dir|
Dir.chdir File.join(arg,dir)
git_output = `git st 2>&1`
if git_output =~ /fatal: Not a git repository \(or any of the parent directories\):/
not_repo.push(dir)
elsif git_output =~ /nothing to commit, working directory clean/
# Do nothing, yay
else
if git_output =~ /Changes not staged for commit:/
unstaged.push(dir)
elsif git_output =~ /Untracked files:/
untracked.push(dir)
else
puts git_output
end
end
Dir.chdir '..'
end
puts "Untracked changes:"
untracked.each do |dir|
puts "\t#{dir}"
end
puts "Unstaged changes:"
unstaged.each do |dir|
puts "\t#{dir}"
end
puts "Not a git repo:"
not_repo.each do |dir|
puts "\t#{dir}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment