Created
October 11, 2017 16:54
-
-
Save aeris/613ff86abe0c2e8bb0c5f7f3e81b5e87 to your computer and use it in GitHub Desktop.
Detect uncommitted git changes
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 | |
require 'find' | |
require 'open3' | |
require 'optparse' | |
require 'ostruct' | |
options = OpenStruct.new | |
OptionParser.new do |opts| | |
opts.on('-u', '--[no-]untrack', 'Include untracked files') { |v| options.untrack = v } | |
end.parse! | |
first = true | |
base = ARGV.fetch 0, '.' | |
Find.find base do |file| | |
next unless File.directory?(file) && File.basename(file) == '.git' | |
repo = File.expand_path File.dirname file | |
cmd = ['git', '-C', repo, '-c', 'color.status=always', 'status', '-s'] | |
cmd += ['-uno'] unless options.untrack | |
o, * = Open3.capture2 *cmd | |
next if o.empty? | |
first ? first = false : puts | |
puts repo | |
o.lines.each { |l| puts " #{l}" } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment