Skip to content

Instantly share code, notes, and snippets.

@joaocunha
Forked from Simbul/pre-commit
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joaocunha/fbb690e3a11134eb3a5b to your computer and use it in GitHub Desktop.
Save joaocunha/fbb690e3a11134eb3a5b to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# This pre-commit hook will prevent any commit to forbidden branches
# (by default, "staging" and "production").
# Put this file in your local repo, in the .git/hooks folder
# and make sure it is executable.
# The name of the file *must* be "pre-commit" for Git to pick it up.
FORBIDDEN_BRANCHES = ["staging", "production"]
def current_branch()
branches = `git branch --no-color`.split(/\n/)
current = branches.select{ |b| b =~ /\s*\*/ }.first
current.gsub(/[\*\s]/, "")
end
branch = current_branch
if (FORBIDDEN_BRANCHES.include?(branch))
puts
puts " STOP THE PRESS!"
puts " You are trying to commit on the *#{branch}* branch."
puts " Surely you don't mean that?"
puts
puts " If you really do, force the commit by adding --no-verify to the command."
puts
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment