mq: always require --force when pushing patches (issue2363) stable
authorPatrick Mezard <pmezard@gmail.com>
Wed, 22 Sep 2010 23:51:10 +0200
branchstable
changeset 12378 ab237534d800
parent 12360 4ae3e5dffa60
child 12379 6aa2c86db2eb
mq: always require --force when pushing patches (issue2363) --force was not necessary when passing --rev since 55578a8d7e84, but this behaviour is usually harmful when branch names are passed instead of explicit revisions.
hgext/mq.py
tests/test-mq-safety
tests/test-mq-safety.out
--- a/hgext/mq.py	Tue Sep 21 23:14:58 2010 +0200
+++ b/hgext/mq.py	Wed Sep 22 23:51:10 2010 +0200
@@ -2713,8 +2713,16 @@
                                               editor, extra)
 
         def push(self, remote, force=False, revs=None, newbranch=False):
-            if self.mq.applied and not force and not revs:
-                raise util.Abort(_('source has mq patches applied'))
+            if self.mq.applied and not force:
+                haspatches = True
+                if revs:
+                    # Assume applied patches have no non-patch descendants
+                    # and are not on remote already. If they appear in the
+                    # set of resolved 'revs', bail out.
+                    applied = set(e.node for e in self.mq.applied)
+                    haspatches = bool([n for n in revs if n in applied])
+                if haspatches:
+                    raise util.Abort(_('source has mq patches applied'))
             return super(mqrepo, self).push(remote, force, revs, newbranch)
 
         def _findtags(self):
--- a/tests/test-mq-safety	Tue Sep 21 23:14:58 2010 +0200
+++ b/tests/test-mq-safety	Wed Sep 22 23:51:10 2010 +0200
@@ -62,3 +62,29 @@
 hg up default
 hg log
 hg qpush
+cd ..
+
+echo '% testing applied patches, push and --force'
+hg init forcepush
+cd forcepush
+echo a > a
+hg ci -Am adda
+echo a >> a
+hg ci -m changea
+hg up 0
+hg branch branch
+echo b > b
+hg ci -Am addb
+hg up 0
+hg --cwd .. clone -r 0 forcepush forcepush2
+echo a >> a
+hg qnew patch
+echo '% pushing applied patch with --rev without --force'
+hg push -r default ../forcepush2
+echo '% pushing applied patch with branchhash, without --force'
+hg push ../forcepush2#default
+echo '% pushing revs excluding applied patch'
+hg push --new-branch -r branch -r 2 ../forcepush2
+echo '% pushing applied patch with --force'
+hg push --force -r default ../forcepush2
+cd ..
--- a/tests/test-mq-safety.out	Tue Sep 21 23:14:58 2010 +0200
+++ b/tests/test-mq-safety.out	Wed Sep 22 23:51:10 2010 +0200
@@ -45,3 +45,36 @@
 
 applying qp
 now at: qp
+% testing applied patches, push and --force
+adding a
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+marked working directory as branch branch
+adding b
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+requesting all changes
+adding changesets
+adding manifests
+adding file changes
+added 1 changesets with 1 changes to 1 files
+updating to branch default
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% pushing applied patch with --rev without --force
+pushing to ../forcepush2
+abort: source has mq patches applied
+% pushing applied patch with branchhash, without --force
+pushing to ../forcepush2
+abort: source has mq patches applied
+% pushing revs excluding applied patch
+pushing to ../forcepush2
+searching for changes
+adding changesets
+adding manifests
+adding file changes
+added 1 changesets with 1 changes to 1 files
+% pushing applied patch with --force
+pushing to ../forcepush2
+searching for changes
+adding changesets
+adding manifests
+adding file changes
+added 1 changesets with 1 changes to 1 files (+1 heads)