changeset 2848:307439d6fede

mq: do not allow to push from repo with patches applied
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Thu, 10 Aug 2006 16:10:59 -0700
parents 2ff57e3113a4
children 3b21013e7680
files hgext/mq.py tests/test-mq tests/test-mq.out
diffstat 3 files changed, 29 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/mq.py	Thu Aug 10 15:44:05 2006 -0700
+++ b/hgext/mq.py	Thu Aug 10 16:10:59 2006 -0700
@@ -1832,18 +1832,28 @@
 
 def reposetup(ui, repo):
     class mqrepo(repo.__class__):
+        def abort_if_wdir_patched(self, errmsg, force=False):
+            if self.mq.applied and not force:
+                parent = revlog.hex(self.dirstate.parents()[0])
+                if parent in [s.rev for s in self.mq.applied]:
+                    raise util.Abort(errmsg)
+            
         def commit(self, *args, **opts):
             if len(args) >= 6:
                 force = args[5]
             else:
                 force = opts.get('force')
-            if self.mq.applied and not force:
-                parent = revlog.hex(self.dirstate.parents()[0])
-                if parent in [s.rev for s in self.mq.applied]:
-                    raise util.Abort(_('cannot commit over an applied mq patch'))
+            self.abort_if_wdir_patched(
+                _('cannot commit over an applied mq patch'),
+                force)
 
             return super(mqrepo, self).commit(*args, **opts)
 
+        def push(self, remote, force=False, revs=None):
+            if self.mq.applied and not force:
+                raise util.Abort(_('source has mq patches applied'))
+            return super(mqrepo, self).push(remote, force, revs)
+            
         def tags(self):
             if self.tagscache:
                 return self.tagscache
--- a/tests/test-mq	Thu Aug 10 15:44:05 2006 -0700
+++ b/tests/test-mq	Thu Aug 10 16:10:59 2006 -0700
@@ -10,6 +10,10 @@
 hg init a
 cd a
 echo a > a
+hg ci -Ama
+
+hg clone . ../k
+
 mkdir b
 echo z > b/z
 hg ci -Ama
@@ -106,9 +110,16 @@
 echo % commit should fail
 hg commit
 
+echo % push should fail
+hg push ../../k
+
 echo % qunapplied
 hg qunapplied
 
+echo % push should succeed
+hg qpop -a
+hg push ../../k
+
 echo % strip
 cd ../../b
 echo x>x
--- a/tests/test-mq.out	Thu Aug 10 15:44:05 2006 -0700
+++ b/tests/test-mq.out	Thu Aug 10 16:10:59 2006 -0700
@@ -49,6 +49,7 @@
  qunapplied   print the patches not yet applied
  strip        strip a revision and all later revs on the same branch
 adding a
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 adding b/z
 % qinit
 % -R qinit
@@ -104,6 +105,9 @@
 test.patch
 % commit should fail
 abort: cannot commit over an applied mq patch
+% push should fail
+pushing to ../../k
+abort: source has mq patches applied
 % qunapplied
 test2.patch
 % strip