4

Is there any simple way to prevent commits to a repository if it has dirty subrepos?

It's really annoying when a subrepo is accidentally committed along with a parent repository.

David Wolever
  • 148,955
  • 89
  • 346
  • 502
  • 1
    I have wanted this as well, and discussed it some time ago on the Mercurial mailing list (and hacked up some patches to do it), but I know of no supported way at present. If someone has one, I would love to see it as well. – Michael Ekstrand Jan 18 '11 at 22:22

2 Answers2

1

I don't know where your line for simple lands but you could do a hook like this:

for subrepo in $(find $(hg root) -type d -name .hg) ; do
  if [ "$(hg --repository ${subrepo$$.hg} status -mard)" != "" ] ; then
    echo Uncommitted subrepo changes in ${subrepo%%.hg}
    exit 1
  fi
done

Save that in something like ~/bin/dirtysubrepos and then add this to your ~/.hgrc:

[hooks]
precommit.dirtysuprepos = ~/bin/dirtysubrepos

Disclaimer: This code has never been typed anywhere except this textbox, so it almost certainly has syntax bugs.

Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
0

I can't comment on Ry4an's answer for some reason (no "Add comment" link for me to click on), but there's a minor typo in his answer: there's an ${subrepo$$.hg} that should be ${subrepo%%.hg}.

Michael Norrish
  • 412
  • 2
  • 11