[PATCH] subrepo: add revert support without backup for git subrepos

Mathias De Maré mathias.demare at gmail.com
Sun Dec 14 15:29:05 UTC 2014


# HG changeset patch
# User Mathias De Maré <mathias.demare at gmail.com>
# Date 1418553291 -3600
#      Son Dez 14 11:34:51 2014 +0100
# Node ID cd6707c55245bf83d45767b0e685b137f9662e04
# Parent  e33179ad88c9aa4ff241d57d37c227381a38098e
subrepo: add revert support without backup for git subrepos

Previously, git subrepos did not support reverting.
This change adds basic support for reverting
when '--no-backup' is specified.
A warning is given (and the current state is kept)
when a revert is done without the '--no-backup' flag.

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -1651,16 +1651,27 @@ class gitsubrepo(abstractsubrepo):
         if match.always():
             ui.write(self._gitcommand(cmd))
         elif match.files():
             for f in match.files():
                 ui.write(self._gitcommand(cmd + [f]))
         elif match(gitprefix): #Subrepo is matched
             ui.write(self._gitcommand(cmd))
 
+    def revert(self, ui, substate, *pats, **opts):
+        ui.status(_('reverting subrepo %s\n') % substate[0])
+        if not opts.get('no_backup'):
+            ui.warn('%s: reverting %s subrepos without ' \
+                    '--no-backup is unsupported\n' \
+                % (substate[0], substate[2]))
+            return []
+
+        self.get(substate, overwrite=True)
+        return []
+
     def shortid(self, revid):
         return revid[:7]
 
 types = {
     'hg': hgsubrepo,
     'svn': svnsubrepo,
     'git': gitsubrepo,
     }
diff --git a/tests/test-subrepo-git.t b/tests/test-subrepo-git.t
--- a/tests/test-subrepo-git.t
+++ b/tests/test-subrepo-git.t
@@ -787,9 +787,27 @@ the output contains a regex, because git
   \s*barfoo |\s*1 + (re)
   \s*foobar |\s*2 +- (re)
    2 files changed, 2 insertions(+), 2 deletions(-) (no-eol)
 
 ensure adding include/exclude ignores the subrepo
   $ hg diff --subrepos -I s/foobar
   $ hg diff --subrepos -X s/foobar
 
+
+revert the subrepository
+  $ hg revert --all
+  reverting subrepo ../gitroot (glob)
+  ../gitroot: reverting git subrepos without --no-backup is unsupported (glob)
+
+  $ hg status --subrepos
+  M s/foobar
+  A s/barfoo
+
+  $ hg revert --no-backup --all
+  reverting subrepo ../gitroot (glob)
+  $ hg revert --no-backup s
+  reverting subrepo ../gitroot (glob)
+
+  $ hg status --subrepos
+  ? s/barfoo
+
   $ cd ..


More information about the Mercurial-devel mailing list