Skip to content

Instantly share code, notes, and snippets.

@aeris
Created October 11, 2017 16:54
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 aeris/613ff86abe0c2e8bb0c5f7f3e81b5e87 to your computer and use it in GitHub Desktop.
Save aeris/613ff86abe0c2e8bb0c5f7f3e81b5e87 to your computer and use it in GitHub Desktop.
Detect uncommitted git changes
#!/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