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 = do |opts|
opts.on('-u', '--[no-]untrack', 'Include untracked files') { |v| options.untrack = v }
first = true
base = ARGV.fetch 0, '.'
Find.find base do |file|
next unless && 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}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment