Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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