5 if IO.popen(["git", "ls-files", "--unmerged"]).read.empty?
6 need_stash = IO.popen(%w(git diff)).read.length > 0
8 system("git", "stash", "save", "--keep-index", "--quiet") if need_stash
10 files = IO.popen(["git", "diff", "--staged", "--name-only"]).readlines.map(&:chomp)
12 ruby_files = files.select do |file|
13 file =~ /\.rb$/ || `file --brief --mime-type #{file}` == "text/x-ruby\n"
16 ok &&= system("rubocop", *ruby_files) unless ruby_files.empty?
18 cookbooks = files.grep(%r{(cookbooks/[^/]+)/}) { Regexp.last_match(1) }.uniq
20 ok &&= system("foodcritic", "-f", "any", *cookbooks) unless cookbooks.empty?
22 system("git", "stash", "pop", "--quiet") if need_stash
24 puts "Unmerged files. Resolve before committing."