diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -250,6 +250,7 @@ class queue(object): self.ui = ui self.applied_dirty = 0 self.series_dirty = 0 + self.added = [] self.series_path = "series" self.status_path = "status" self.guards_path = "guards" @@ -1622,7 +1623,7 @@ class queue(object): if (len(files) > 1 or len(rev) > 1) and patchname: raise util.Abort(_('option "-n" not valid when importing multiple ' 'patches')) - added = [] + self.added = [] if rev: # If mq patches are applied, we can only import revisions # that form a linear path to qbase. @@ -1672,10 +1673,11 @@ class queue(object): se = statusentry(n, patchname) self.applied.insert(0, se) - added.append(patchname) + self.added.append(patchname) patchname = None self.parse_series() self.applied_dirty = 1 + self.series_dirty = True for i, filename in enumerate(files): if existing: @@ -1709,13 +1711,10 @@ class queue(object): index = self.full_series_end() + i self.full_series[index:index] = [patchname] self.parse_series() + self.series_dirty = True self.ui.warn(_("adding %s to series file\n") % patchname) - added.append(patchname) + self.added.append(patchname) patchname = None - self.series_dirty = 1 - qrepo = self.qrepo() - if qrepo: - qrepo[None].add(added) def delete(ui, repo, *patches, **opts): """remove patches from queue @@ -1805,10 +1804,15 @@ def qimport(ui, repo, *filename, **opts) using the --name flag. """ q = repo.mq - q.qimport(repo, filename, patchname=opts['name'], + try: + q.qimport(repo, filename, patchname=opts['name'], existing=opts['existing'], force=opts['force'], rev=opts['rev'], git=opts['git']) - q.save_dirty() + finally: + q.save_dirty() + qrepo = q.qrepo() + if qrepo: + qrepo[None].add(q.added) if opts.get('push') and not opts.get('rev'): return q.push(repo, None) diff --git a/tests/test-mq-qimport-fail-cleanup b/tests/test-mq-qimport-fail-cleanup new file mode 100755 --- /dev/null +++ b/tests/test-mq-qimport-fail-cleanup @@ -0,0 +1,33 @@ +#!/bin/sh +#failed qimport of patches from files should cleanup by recording successfully +#imported patches in series file. + +echo "[extensions]" >> $HGRCPATH +echo "mq=" >> $HGRCPATH + +hg init repo +cd repo + +echo a > a +hg ci -Am'add a' + +cat >b.patch<