diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -261,12 +261,21 @@ class queue(object): def diffopts(self, opts={}, patchfn=None): diffopts = patch.diffopts(self.ui, opts) if patchfn: - # if the patch was a git patch, refresh it as a git patch - patchf = self.opener(patchfn, 'r') - for line in patchf: - if line.startswith('diff --git'): - diffopts.git = True - break + diffopts = self.patchopts(diffopts, patchfn) + return diffopts + + def patchopts(self, diffopts, patchfn): + """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() return diffopts def join(self, *p): @@ -469,6 +478,7 @@ class queue(object): except: raise util.Abort(_("unable to read %s") % patch) + diffopts = self.patchopts(diffopts, patch) patchf = self.opener(patch, "w") comments = str(ph) if comments: diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py --- a/mercurial/mdiff.py +++ b/mercurial/mdiff.py @@ -55,6 +55,11 @@ class diffopts(object): raise util.Abort(_('diff context lines count must be ' 'an integer, not %r') % self.context) + def copy(self, **kwargs): + opts = dict((k, getattr(self, k)) for k in self.defaults) + opts.update(kwargs) + return diffopts(**opts) + defaultopts = diffopts() def wsclean(opts, text, blank=True): diff --git a/tests/test-mq-merge b/tests/test-mq-merge --- a/tests/test-mq-merge +++ b/tests/test-mq-merge @@ -56,18 +56,27 @@ echo echo % init t2 hg init t2 cd t2 +echo '[diff]' > .hg/hgrc +echo 'nodates = 1' >> .hg/hgrc echo a > a hg ci -Am init -echo b >> a +echo b > a hg ci -m changea hg up -C 0 +hg cp a aa echo c >> a -hg qnew -f -e patcha +hg qnew --git -f -e patcha +echo d >> a +hg qnew -d '0 0' -f -e patcha2 echo % create the reference queue hg qsave -c -e -n refqueue 2> /dev/null hg up -C 1 echo % merge -hg qpush -m -n refqueue 2>&1 | \ +HGMERGE=internal:other hg qpush -a -m -n refqueue 2>&1 | \ sed 's/merging with queue at.*refqueue/merging with queue at refqueue/' +echo % check patcha is still a git patch +cat .hg/patches/patcha +echo % check patcha2 is still a regular patch +grep git .hg/patches/patcha2 && echo 'git patch found!' cd .. diff --git a/tests/test-mq-merge.out b/tests/test-mq-merge.out --- a/tests/test-mq-merge.out +++ b/tests/test-mq-merge.out @@ -18,8 +18,35 @@ patch queue now empty adding a 1 files updated, 0 files merged, 0 files removed, 0 files unresolved % create the reference queue -1 files updated, 0 files merged, 0 files removed, 0 files unresolved +1 files updated, 0 files merged, 1 files removed, 0 files unresolved % merge merging with queue at refqueue applying patcha -now at: patcha +patching file a +Hunk #1 FAILED at 0 +1 out of 1 hunks FAILED -- saving rejects to file a.rej +patch failed, unable to continue (try -v) +patch failed, rejects left in working dir +patch didn't work out, merging patcha +1 files updated, 0 files merged, 1 files removed, 0 files unresolved +0 files updated, 2 files merged, 0 files removed, 0 files unresolved +(branch merge, don't forget to commit) +applying patcha2 +now at: patcha2 +% check patcha is still a git patch +diff --git a/a b/a +--- a/a ++++ b/a +@@ -1,1 +1,2 @@ +-b ++a ++c +diff --git a/a b/aa +copy from a +copy to aa +--- a/a ++++ b/aa +@@ -1,1 +1,1 @@ +-b ++a +% check patcha2 is still a regular patch