Last active
August 29, 2015 14:04
-
-
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...
This file contains hidden or 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 | |
| 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