Patchwork [3,of,3] revert: evaluate subrepos to revert against the working directory

login
register
mail settings
Submitter Matt Harbison
Date March 26, 2015, 4:20 a.m.
Message ID <778b68235d61acc9920f.1427343657@Envy>
Download mbox | patch
Permalink /patch/8289/
State Accepted
Commit 30ddc3cf76df464f7b4ad38eb49e4d1f49457f01
Headers show

Comments

Matt Harbison - March 26, 2015, 4:20 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1427336444 14400
#      Wed Mar 25 22:20:44 2015 -0400
# Node ID 778b68235d61acc9920f83694adb2e59c88121ce
# Parent  781d27e7fcd3a438d02bf2e1a9ba0a85537da6b9
revert: evaluate subrepos to revert against the working directory

Reverting to a revision where the subrepo didn't exist will now abort, and
matching subrepos against the working directory is consistent with how filesets
are evaluated since 5b85a5bc5bbb.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -3047,14 +3047,14 @@ 
             _performrevert(repo, parents, ctx, actions, interactive)
 
         # get the list of subrepos that must be reverted
-        subrepomatch = scmutil.match(ctx, pats, opts)
-        targetsubs = sorted(s for s in ctx.substate if subrepomatch(s))
+        subrepomatch = wmatch
+        targetsubs = sorted(s for s in wctx.substate if subrepomatch(s))
 
         if targetsubs:
             # Revert the subrepos on the revert list
             for sub in targetsubs:
                 try:
-                    ctx.sub(sub).revert(ctx.substate[sub], *pats, **opts)
+                    wctx.sub(sub).revert(ctx.substate[sub], *pats, **opts)
                 except KeyError:
                     raise util.Abort("subrepository '%s' does not exist in %s!"
                                       % (sub, short(ctx.node())))
diff --git a/tests/test-subrepo-recursion.t b/tests/test-subrepo-recursion.t
--- a/tests/test-subrepo-recursion.t
+++ b/tests/test-subrepo-recursion.t
@@ -528,9 +528,19 @@ 
   $ hg init test
   $ cd test
   $ hg init x
+  $ echo abc > abc.txt
+  $ hg ci -Am "abc"
+  adding abc.txt
   $ echo "x = x" >> .hgsub
   $ hg add .hgsub
   $ touch a x/a
   $ hg add a x/a
 
+  $ hg ci -Sm "added x"
+  committing subrepository x
+  $ echo abc > x/a
+  $ hg revert --rev '.^' "set:subrepo('glob:x*')"
+  abort: subrepository 'x' does not exist in 25ac2c9b3180!
+  [255]
+
   $ cd ..