Skip to content

Instantly share code, notes, and snippets.

@zegervdv
Last active December 16, 2015 02:19
Show Gist options
  • Save zegervdv/5361927 to your computer and use it in GitHub Desktop.
Save zegervdv/5361927 to your computer and use it in GitHub Desktop.
Find conflicts that are wrongfully committed
#!/usr/bin/env ruby
# INSTALLATION
# put in /usr/bin or /usr/local/bin as git-conflict
# add permissions if necessary
# $ chmod +x git-conflict
# run
# $ git conflict
#
conflicted = Array.new
Dir["**/*"].each do |source|
if source.match(/.(c|h|m|rb|php|html|css|xml)$/) && !File.directory?(source)
if RUBY_VERSION > '1.8.7'
content = IO.read(source).force_encoding("ISO-8859-1").encode("utf-8", :replace => nil)
else
content = IO.read(source)
end
conflicted << source if content.match /(<+) HEAD/
end
end
if conflicted.empty?
puts %q{No conflicts found.}
else
verb = "are"
number = conflicted.size
noun = "conflicts"
if conflicted.size == 1
verb = "is"
number = "a"
noun = "conflict"
end
puts "There #{verb} #{number} #{noun}:"
conflicted.each {|c| puts "\t #{c}" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment