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 system("git", "stash", "pop", "--quiet") if need_stash
20 puts "Unmerged files. Resolve before committing."