title: precommit mercurial hook to stop commits to the wrong branch
body: <p>I have a piece of software in a Mercurial repository.</p>
  
  <p>I'm packaging my software project as a Debian package. 
  It seems the standard way to do this is to have a
  separate branch for the Debian package files, 
  which live in the <code>debian</code> sub-directory.</p>
  
  <p>One problem I keep having is that I forget which branch I am
  on and accidentally commit to the wrong branch. This happens
  frequently, and is really annoying. When this happens I usually
  push to remote before realising the problem, and then have
  to fix up the local and remote repositories manually, which is
  a pain.</p>
  
  <p>The only option I can think of is to have a pre-commit hook
  that aborts if I am trying to make commits to the wrong branch.</p>
  
  <p>To be concrete, let's say the main branch is called <code>default</code> and the branch
  containing Debian files is called <code>debian</code>. Then I want commits to the <code>default</code>
  branch to succeed only if none of the files in the commit are from the <code>debian</code>
  directory. I want commits to the <code>debian</code> directory to succeed only if all the
  files in the commit are in the <code>debian</code> directory.</p>
  
  <p>I spent some time reading the chapter on Mercurial Hooks and going through the examples
  in the Hg Book, but still have no idea how to go about this. I did get the strong impression
  that for something like this I should be calling out to an external Python script, probably
  in <code>.hg/</code>.</p>