Skip to content

Instantly share code, notes, and snippets.

@sdhull
Created April 17, 2012 23:36
Show Gist options
  • Save sdhull/2409918 to your computer and use it in GitHub Desktop.
Save sdhull/2409918 to your computer and use it in GitHub Desktop.
.git/hooks/pre-commit
#!/usr/bin/env ruby
file_names = `git diff-index --cached -Sdebugger --name-only HEAD`
file_names += `git diff-index --cached -Ssave_and_open_page --name-only HEAD`
file_names = file_names.strip
if file_names != ""
puts "The following files have 'debugger' or 'save_and_open_page' statements in them: "
puts file_names
raise "Please complete your merge prior to committing" unless ENV["FORCE"]
end
file_names = `git diff-index --cached -S'<<<<<<<' --name-only HEAD`.chomp.split
file_names += `git diff-index --cached -S'=======' --name-only HEAD`.chomp.split
file_names += `git diff-index --cached -S'>>>>>>>' --name-only HEAD`.chomp.split
file_names = file_names.uniq.join("\n")
if file_names != ""
puts "The following files have incomplete merges: "
puts file_names
raise "Please complete your merge prior to committing" unless ENV["FORCE"]
end
@sdhull
Copy link
Author

sdhull commented May 4, 2012

Edited so that you can force a commit to happen if you (for instance) remove a debugger and commit that, or if you just really really want to commit a debugger, save_and_open_page, or unmerged file.

@sdhull
Copy link
Author

sdhull commented May 4, 2012

so do FORCE=true git commit -m 'Committing a debugger!'

@jrichardlai
Copy link

yeah!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment