[PATCH STABLE V2] record: prevent commits that don't pick up dirty subrepo changes (issue6102)

Matt Harbison mharbison72 at gmail.com
Sun Mar 17 18:28:21 EDT 2019


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1552761621 14400
#      Sat Mar 16 14:40:21 2019 -0400
# Branch stable
# Node ID 5a94b002b3e6f0929321be7eacd28c2bb256b358
# Parent  25fc5b96d1c30468417ee0d690c2979db362edd0
record: prevent commits that don't pick up dirty subrepo changes (issue6102)

This path covers interactive mode for commit, amend, and shelve, as well as the
deprecated record extension.  Since shelf creation uses commit without -S in the
non-interactive case, aborting here should be OK.  (I didn't check what happens
to non interactive shelve creation if `ui.commitsubrepos=True` is set.)

subrepoutil.precommit() will abort on a dirty subrepo if the config option isn't
set, but the hint recommends using --subrepos to commit.  Since only the commit
command currently supports that option, the error has to be raised here to omit
the hint.

Doing the check before asking about all of the hunks in the MQ test seems like
an improvement on its own.  There's probably an additional check on this path
that can be removed.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -7,6 +7,7 @@
 
 from __future__ import absolute_import
 
+import copy as copymod
 import errno
 import os
 import re
@@ -270,6 +271,28 @@ def dorecord(ui, repo, commitfunc, cmdsu
             raise error.Abort(_('cannot partially commit a merge '
                                '(use "hg commit" instead)'))
 
+        status = repo.status(match=match)
+
+        overrides = {(b'ui', b'commitsubrepos'): True}
+
+        with repo.ui.configoverride(overrides, b'record'):
+            # subrepoutil.precommit() modifies the status
+            tmpstatus = scmutil.status(copymod.copy(status[0]),
+                                       copymod.copy(status[1]),
+                                       copymod.copy(status[2]),
+                                       copymod.copy(status[3]),
+                                       copymod.copy(status[4]),
+                                       copymod.copy(status[5]),
+                                       copymod.copy(status[6]))
+
+            # Force allows -X subrepo to skip the subrepo.
+            subs, commitsubs, newstate = subrepoutil.precommit(
+                repo.ui, wctx, tmpstatus, match, force=True)
+            for s in subs:
+                if s in commitsubs:
+                    dirtyreason = wctx.sub(s).dirtyreason(True)
+                    raise error.Abort(dirtyreason)
+
         def fail(f, msg):
             raise error.Abort('%s: %s' % (f, msg))
 
@@ -279,7 +302,6 @@ def dorecord(ui, repo, commitfunc, cmdsu
             match.explicitdir = vdirs.append
             match.bad = fail
 
-        status = repo.status(match=match)
         if not force:
             repo.checkcommitpatterns(wctx, vdirs, match, status, fail)
         diffopts = patch.difffeatureopts(ui, opts=opts, whitespace=True)
diff --git a/tests/test-amend-subrepo.t b/tests/test-amend-subrepo.t
--- a/tests/test-amend-subrepo.t
+++ b/tests/test-amend-subrepo.t
@@ -121,9 +121,22 @@ add new commit to be amended
   $ echo a >> a
   $ hg ci -m3
 
+  $ echo 't = t' > .hgsub
+
+--interactive won't silently ignore dirty subrepos
+
+  $ echo modified > t/b
+  $ hg amend --interactive --config ui.interactive=True
+  abort: uncommitted changes in subrepository "t"
+  [255]
+  $ hg amend --interactive --config ui.interactive=True --config ui.commitsubrepos=True
+  abort: uncommitted changes in subrepository "t"
+  [255]
+
+  $ hg -R t revert -q --all --no-backup
+
 amend with one subrepo dropped
 
-  $ echo 't = t' > .hgsub
   $ hg amend
   saved backup bundle to * (glob) (obsstore-off !)
   $ hg status --change .
diff --git a/tests/test-mq-subrepo.t b/tests/test-mq-subrepo.t
--- a/tests/test-mq-subrepo.t
+++ b/tests/test-mq-subrepo.t
@@ -295,16 +295,6 @@ handle subrepos safely on qrecord
   A .hgsub
   A sub/a
   % qrecord --config ui.interactive=1 -m0 0.diff
-  diff --git a/.hgsub b/.hgsub
-  new file mode 100644
-  examine changes to '.hgsub'? [Ynesfdaq?] y
-  
-  @@ -0,0 +1,1 @@
-  +sub = sub
-  record this change to '.hgsub'? [Ynesfdaq?] y
-  
-  warning: subrepo spec file '.hgsub' not found
-  warning: subrepo spec file '.hgsub' not found
   abort: uncommitted changes in subrepository "sub"
   [255]
   % update substate when adding .hgsub w/clean updated subrepo
@@ -333,15 +323,6 @@ handle subrepos safely on qrecord
   M .hgsub
   A sub2/a
   % qrecord --config ui.interactive=1 -m1 1.diff
-  diff --git a/.hgsub b/.hgsub
-  1 hunks, 1 lines changed
-  examine changes to '.hgsub'? [Ynesfdaq?] y
-  
-  @@ -1,1 +1,2 @@
-   sub = sub
-  +sub2 = sub2
-  record this change to '.hgsub'? [Ynesfdaq?] y
-  
   abort: uncommitted changes in subrepository "sub2"
   [255]
   % update substate when modifying .hgsub w/clean updated subrepo


More information about the Mercurial-devel mailing list