diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -264,18 +264,19 @@ class queue(object): 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): @@ -2070,7 +2071,8 @@ def fold(ui, repo, *files, **opts): 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() diff --git a/tests/test-mq-qfold b/tests/test-mq-qfold --- a/tests/test-mq-qfold +++ b/tests/test-mq-qfold @@ -25,12 +25,35 @@ echo '% fold in the middle of the queue' 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 .. diff --git a/tests/test-mq-qfold.out b/tests/test-mq-qfold.out --- a/tests/test-mq-qfold.out +++ b/tests/test-mq-qfold.out @@ -25,3 +25,40 @@ abort: local changes found, refresh firs 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