changeset 4930:fc502517d68d

mq: autodetect an existing git patch during qrefresh (issue 491)
author Bryan O'Sullivan <bos@serpentine.com>
date Mon, 16 Jul 2007 16:50:47 -0700
parents 22fcd6444ad9
children c4dd58af0fc8
files hgext/mq.py tests/test-mq tests/test-mq.out
diffstat 3 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/mq.py	Wed Jul 11 00:53:44 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	Wed Jul 11 00:53:44 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	Wed Jul 11 00:53:44 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