Skip to content

Instantly share code, notes, and snippets.

@nberger
Created April 19, 2015 21:39
Show Gist options
  • Save nberger/c69e8e7420e506d0b14a to your computer and use it in GitHub Desktop.
Save nberger/c69e8e7420e506d0b14a to your computer and use it in GitHub Desktop.
Pre-commit hook to enforce branch naming to play well with mercurial via git-remote-hg
#!/usr/bin/env ruby
def current_branch()
branches = `git branch --no-color`.split(/\n/)
branches.select{ |b| b =~ /\s*\*/ }.first.gsub(/[\*\s]/, "")
end
branch = current_branch
if branch != "master" && branch !~ /^branches\//
puts
puts " You are trying to commit on the *#{branch}* branch."
puts " To play well with hg, you should use branches named 'branches/...'"
puts
puts " If you really want to do this, force the commit by adding --no-verify to the command."
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment