[PATCH] commit: abort if a subrepo is modified and ui.commitsubrepos=no

Patrick Mezard pmezard at gmail.com
Tue Feb 15 15:35:56 CST 2011


# HG changeset patch
# User Patrick Mezard <pmezard at gmail.com>
# Date 1297805148 -3600
# Node ID 229dc38881f4ebc6827fd3fa8e0ed8c6927101b5
# Parent  682edefe7dbbefabbd56090de40d04709af21edb
commit: abort if a subrepo is modified and ui.commitsubrepos=no

The default behaviour is to commit subrepositories with uncommitted changes. In
my experience this is usually undesirable:

- Changes to dependencies are often debugging leftovers
- Real changes should generally be applied on the source project directly,
  tested then committed. This is not always possible, subversion subrepos may
  include only a small part of the source project, without the tests.

Setting ui.commitsubrepos=no will now abort commits containing such modified
subrepositories like:

  $ hg --config ui.commitsubrepos=no ci -m msg
  abort: uncommitted changes in subrepo sub

I ruled out the hook solution because it does not easily take --include/exclude
options in account. Also, my main concern is whether this flag could cause
problems with extensions. If there are legitimate reasons for callers to
override this behaviour (I could not find any), they might either override at ui
level, or we could add an argument to localrepo.commit() later.

v2:
- Renamed ui.commitsubs to ui.commitsubrepos
- Mention the configuration entry in hg help subrepos

diff -r 682edefe7dbb -r 229dc38881f4 doc/hgrc.5.txt
--- a/doc/hgrc.5.txt	Tue Feb 15 02:17:43 2011 +0100
+++ b/doc/hgrc.5.txt	Tue Feb 15 22:25:48 2011 +0100
@@ -878,6 +878,11 @@
     be prompted to enter a username. If no username is entered, the
     default ``USER at 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 -r 682edefe7dbb -r 229dc38881f4 mercurial/help/subrepos.txt
--- a/mercurial/help/subrepos.txt	Tue Feb 15 02:17:43 2011 +0100
+++ b/mercurial/help/subrepos.txt	Tue Feb 15 22:25:48 2011 +0100
@@ -78,7 +78,10 @@
 :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 -r 682edefe7dbb -r 229dc38881f4 mercurial/localrepo.py
--- a/mercurial/localrepo.py	Tue Feb 15 02:17:43 2011 +0100
+++ b/mercurial/localrepo.py	Tue Feb 15 22:25:48 2011 +0100
@@ -933,6 +933,12 @@
                 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 -r 682edefe7dbb -r 229dc38881f4 tests/test-subrepo.t
--- a/tests/test-subrepo.t	Tue Feb 15 02:17:43 2011 +0100
+++ b/tests/test-subrepo.t	Tue Feb 15 22:25:48 2011 +0100
@@ -75,16 +75,19 @@
   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


More information about the Mercurial-devel mailing list