diff --git a/hgext/rebase.py b/hgext/rebase.py index e37199a1f9d4e474b97c41d56c0cfe0729e8eb35_aGdleHQvcmViYXNlLnB5..b9f51f49bf2a296ab857aff0b2bc39005027979b_aGdleHQvcmViYXNlLnB5 100644 --- a/hgext/rebase.py +++ b/hgext/rebase.py @@ -446,6 +446,7 @@ mqrebase = {} mq = repo.mq original_series = mq.fullseries[:] + skippedpatches = set() for p in mq.applied: rev = repo[p.node].rev() @@ -453,6 +454,9 @@ repo.ui.debug('revision %d is an mq patch (%s), finalize it.\n' % (rev, p.name)) mqrebase[rev] = (p.name, isagitpatch(repo, p.name)) + else: + # Applied but not rebased, not sure this should happen + skippedpatches.add(p.name) if mqrebase: mq.finish(repo, mqrebase.keys()) @@ -464,4 +468,7 @@ repo.ui.debug('import mq patch %d (%s)\n' % (state[rev], name)) mq.qimport(repo, (), patchname=name, git=isgit, rev=[str(state[rev])]) + else: + # Rebased and skipped + skippedpatches.add(mqrebase[rev][0]) @@ -467,11 +474,11 @@ - # restore missing guards - for s in original_series: - pname = mq.guard_re.split(s, 1)[0] - if pname in mq.fullseries: - repo.ui.debug('restoring guard for patch %s' % (pname)) - mq.fullseries[mq.fullseries.index(pname)] = s - mq.series_dirty = True + # Patches were either applied and rebased and imported in + # order, applied and removed or unapplied. Discard the removed + # ones while preserving the original series order and guards. + newseries = [s for s in original_series + if mq.guard_re.split(s, 1)[0] not in skippedpatches] + mq.fullseries[:] = newseries + mq.seriesdirty = True mq.savedirty() def updatebookmarks(repo, nstate, originalbookmarks, **opts): diff --git a/tests/test-rebase-mq.t b/tests/test-rebase-mq.t index e37199a1f9d4e474b97c41d56c0cfe0729e8eb35_dGVzdHMvdGVzdC1yZWJhc2UtbXEudA==..b9f51f49bf2a296ab857aff0b2bc39005027979b_dGVzdHMvdGVzdC1yZWJhc2UtbXEudA== 100644 --- a/tests/test-rebase-mq.t +++ b/tests/test-rebase-mq.t @@ -247,7 +247,12 @@ Create mq repo with guarded patches foo and bar and empty patch: $ hg qinit - $ hg qnew foo - $ hg qguard foo +baz + $ echo guarded > guarded + $ hg add guarded + $ hg qnew guarded + $ hg qnew empty-important -m 'important commit message' + $ echo bar > bar + $ hg add bar + $ hg qnew bar $ echo foo > foo $ hg add foo @@ -252,5 +257,5 @@ $ echo foo > foo $ hg add foo - $ hg qref - $ hg qpop + $ hg qnew foo + $ hg qpop -a popping foo @@ -256,2 +261,5 @@ popping foo + popping bar + popping empty-important + popping guarded patch queue now empty @@ -257,6 +265,3 @@ patch queue now empty - - $ hg qnew empty-important -m 'important commit message' - - $ hg qnew bar + $ hg qguard guarded +guarded $ hg qguard bar +baz @@ -262,6 +267,11 @@ $ hg qguard bar +baz - $ echo bar > bar - $ hg add bar - $ hg qref + $ hg qguard foo +baz + $ hg qselect baz + number of unguarded, unapplied patches has changed from 1 to 3 + $ hg qpush bar + applying empty-important + patch empty-important is empty + applying bar + now at: bar $ hg qguard -l @@ -266,7 +276,8 @@ $ hg qguard -l + guarded: +guarded empty-important: unguarded bar: +baz foo: +baz $ hg tglog @@ -268,9 +279,9 @@ empty-important: unguarded bar: +baz foo: +baz $ hg tglog - @ 2: '[mq]: bar' tags: bar qtip tip + @ 2: 'imported patch bar' tags: bar qtip tip | o 1: 'important commit message' tags: empty-important qbase | @@ -303,9 +314,10 @@ removed from the series): $ hg qseries + guarded empty-important bar foo $ [ -f .hg/patches/empty-important ] $ hg -q rebase -d 2 $ hg qseries @@ -306,12 +318,13 @@ empty-important bar foo $ [ -f .hg/patches/empty-important ] $ hg -q rebase -d 2 $ hg qseries + guarded bar foo $ [ -f .hg/patches/empty-important ] [1] $ hg qguard -l @@ -312,9 +325,10 @@ bar foo $ [ -f .hg/patches/empty-important ] [1] $ hg qguard -l + guarded: +guarded bar: +baz foo: +baz