Commits

Patrick Mézard  committed 296a0b1

mq: preserve --git flag when folding patches

Without this, folding a git patch into a regular one downgrades the resulting
patch to a regular patch.

  • Participants
  • Parent commits 7637fe4
  • Branches stable
  • Tags 1.4.2

Comments (0)

Files changed (3)

             diffopts = self.patchopts(diffopts, patchfn)
         return diffopts
 
-    def patchopts(self, diffopts, patchfn):
+    def patchopts(self, diffopts, *patches):
         """Return a copy of input diff options with git set to true if
         referenced patch is a git patch.
         """
         diffopts = diffopts.copy()
-        patchf = self.opener(patchfn, 'r')
-        # if the patch was a git patch, refresh it as a git patch
-        for line in patchf:
-            if line.startswith('diff --git'):
-                diffopts.git = True
-                break
-        patchf.close()
+        for patchfn in patches:
+            patchf = self.opener(patchfn, 'r')
+            # if the patch was a git patch, refresh it as a git patch
+            for line in patchf:
+                if line.startswith('diff --git'):
+                    diffopts.git = True
+                    break
+            patchf.close()
         return diffopts
 
     def join(self, *p):
     if opts['edit']:
         message = ui.edit(message, user or ui.username())
 
-    q.refresh(repo, msg=message)
+    diffopts = q.patchopts(q.diffopts(), *patches)
+    q.refresh(repo, msg=message, git=diffopts.git)
     q.delete(repo, patches, opts)
     q.save_dirty()
 

File tests/test-mq-qfold

 hg qpop p1
 hg qdiff | filterdiff
 hg qfold p2
+grep git .hg/patches/p1 && echo 'git patch found!'
 hg qser
 hg qdiff | filterdiff
 echo '% fold with local changes'
 echo d >> a
 hg qfold p3
 hg diff -c . | filterdiff
+hg revert -a --no-backup
+
+echo '% fold git patch into a regular patch, expect git patch'
+echo a >> a
+hg qnew -f regular
+hg cp a aa
+hg qnew --git -f git
+hg qpop
+hg qfold git
+cat .hg/patches/regular
+hg qpop
+hg qdel regular
+
+echo '% fold regular patch into a git patch, expect git patch'
+hg cp a aa
+hg qnew --git -f git
+echo b >> aa
+hg qnew -f regular
+hg qpop
+hg qfold regular
+cat .hg/patches/git
+
 cd ..
 
 

File tests/test-mq-qfold.out

  a
 +a
 +b
+reverting a
+% fold git patch into a regular patch, expect git patch
+popping git
+now at: regular
+diff --git a/a b/a
+--- a/a
++++ b/a
+@@ -1,3 +1,4 @@
+ a
+ a
+ b
++a
+diff --git a/a b/aa
+copy from a
+copy to aa
+--- a/a
++++ b/aa
+@@ -1,3 +1,4 @@
+ a
+ a
+ b
++a
+popping regular
+now at: p1
+% fold regular patch into a git patch, expect git patch
+popping regular
+now at: git
+diff --git a/a b/aa
+copy from a
+copy to aa
+--- a/a
++++ b/aa
+@@ -1,3 +1,4 @@
+ a
+ a
+ b
++b