mq: autodetect an existing git patch during qrefresh (issue 491)
authorBryan O'Sullivan <bos@serpentine.com>
Mon, 16 Jul 2007 16:50:47 -0700
changeset 4890 bbdcacf7cef8
parent 4887 2f09df302f30
child 4891 2d545b98a7bc
mq: autodetect an existing git patch during qrefresh (issue 491)
hgext/mq.py
tests/test-mq
tests/test-mq.out
--- a/hgext/mq.py	Mon Jul 16 14:43:47 2007 -0700
+++ b/hgext/mq.py	Mon Jul 16 16:50:47 2007 -0700
@@ -909,7 +909,16 @@
         patchparent = self.qparents(repo, top)
         message, comments, user, date, patchfound = self.readheaders(patchfn)
 
-        patchf = self.opener(patchfn, "w")
+        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'):
+                self.diffopts().git = True
+                break
+        patchf.seek(0)
+        patchf.truncate()
+
         msg = opts.get('msg', '').rstrip()
         if msg:
             if comments:
--- a/tests/test-mq	Mon Jul 16 14:43:47 2007 -0700
+++ b/tests/test-mq	Mon Jul 16 16:50:47 2007 -0700
@@ -319,6 +319,8 @@
 hg qrefresh --git
 cat .hg/patches/bar
 hg log -vC --template '{rev} {file_copies%filecopy}\n' -r .
+hg qrefresh
+grep 'diff --git' .hg/patches/bar
 
 echo
 hg up -C 1
--- a/tests/test-mq.out	Mon Jul 16 14:43:47 2007 -0700
+++ b/tests/test-mq.out	Mon Jul 16 16:50:47 2007 -0700
@@ -325,6 +325,8 @@
 rename from foo
 rename to baz
 2 baz (foo)
+diff --git a/bar b/bar
+diff --git a/foo b/baz
 
 1 files updated, 0 files merged, 2 files removed, 0 files unresolved
 2 files updated, 0 files merged, 1 files removed, 0 files unresolved