[PATCH] subrepo: add full revert support for git subrepos

Mathias De Maré mathias.demare at gmail.com
Sun Dec 28 09:50:31 UTC 2014


# HG changeset patch
# User Mathias De Maré <mathias.demare at gmail.com>
# Date 1419759745 -3600
#      Son Dez 28 10:42:25 2014 +0100
# Node ID 092bb321b2adc00ef207ffb15fcd7446203806e9
# Parent  67d63ec85eb72187508692e52f14be46101707a5
subrepo: add full revert support for git subrepos

Previously, revert was only possible if the '--no-backup'
switch was specified.
Now, to support backups, we explicitly go over all modified
files in the subrepo.

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -1653,20 +1653,24 @@ class gitsubrepo(abstractsubrepo):
             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, substate, *pats, **opts):
         self.ui.status(_('reverting subrepo %s\n') % substate[0])
         if not opts.get('no_backup'):
-            self.ui.warn('%s: reverting %s subrepos without '
-                         '--no-backup is unsupported\n'
-                         % (substate[0], substate[2]))
-            return []
+            status = self.status(None)
+            names = status.modified
+            for name in names:
+                bakname = "%s.orig" % name
+                self.ui.note(_('saving current version of %s as %s\n') %
+                        (name, bakname))
+                util.rename(os.path.join(self._abspath, name),
+                            os.path.join(self._abspath, bakname))
 
         self.get(substate, overwrite=True)
         return []
 
     def shortid(self, revid):
         return revid[:7]
 
 types = {
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
@@ -782,23 +782,22 @@ the output contains a regex, because git
 
 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
+  ? s/barfoo
+  ? s/foobar.orig
 
-  $ hg revert --no-backup --all
-  reverting subrepo ../gitroot (glob)
+  $ mv s/foobar.orig s/foobar
+
   $ hg revert --no-backup s
   reverting subrepo ../gitroot (glob)
 
   $ hg status --subrepos
   ? s/barfoo
 
   $ cd ..


More information about the Mercurial-devel mailing list