diff --git a/doc/hgrc.5.txt b/doc/hgrc.5.txt --- a/doc/hgrc.5.txt +++ b/doc/hgrc.5.txt @@ -878,6 +878,11 @@ User interface controls. be prompted to enter a username. If no username is entered, the default ``USER@HOST`` is used instead. Default is False. +``commitsubrepos`` + Whether to commit modified subrepositories when committing the + parent repository. If False and one subrepository has uncommitted + changes, abort the commit. + Default is True. ``debug`` Print debugging information. True or False. Default is False. ``editor`` diff --git a/mercurial/help/subrepos.txt b/mercurial/help/subrepos.txt --- a/mercurial/help/subrepos.txt +++ b/mercurial/help/subrepos.txt @@ -78,7 +78,10 @@ Interaction with Mercurial Commands :commit: commit creates a consistent snapshot of the state of the entire project and its subrepositories. It does this by first attempting to commit all modified subrepositories, then recording - their state and finally committing it in the parent repository. + their state and finally committing it in the parent + repository. Mercurial can be made to abort if any subrepository + content is modified by setting "ui.commitsubrepos=no" in a + configuration file (see :hg:`help config`). :diff: diff does not recurse in subrepos unless -S/--subrepos is specified. Changes are displayed as usual, on the subrepositories diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -933,6 +933,12 @@ class localrepository(repo.repository): if '.hgsubstate' not in changes[0]: changes[0].insert(0, '.hgsubstate') + if subs and not self.ui.configbool('ui', 'commitsubrepos', True): + changedsubs = [s for s in subs if wctx.sub(s).dirty(True)] + if changedsubs: + raise util.Abort(_("uncommitted changes in subrepo %s") + % changedsubs[0]) + # make sure all explicit patterns are matched if not force and match.files(): matched = set(changes[0] + changes[1] + changes[2]) diff --git a/tests/test-subrepo.t b/tests/test-subrepo.t --- a/tests/test-subrepo.t +++ b/tests/test-subrepo.t @@ -75,16 +75,19 @@ add sub sub commit: (clean) update: (current) -bump sub rev +bump sub rev (and check it is ignored by ui.commitsubrepos) $ echo b > s/a $ hg -R s ci -ms1 - $ hg ci -m3 + $ hg --config ui.commitsubrepos=no ci -m3 committing subrepository s -leave sub dirty +leave sub dirty (and check ui.commitsubrepos=no aborts the commit) $ echo c > s/a + $ hg --config ui.commitsubrepos=no ci -m4 + abort: uncommitted changes in subrepo s + [255] $ hg ci -m4 committing subrepository s $ hg tip -R s