diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2509,7 +2509,7 @@ opts.get('currentuser'), opts.get('rev'))): raise error.Abort(_("cannot specify any other flag with '--abort'")) - return _abortgraft(ui, repo, graftstate) + return _abortgraft(ui, repo) elif opts.get('continue'): cont = True if revs: @@ -2686,9 +2686,10 @@ return 0 -def _abortgraft(ui, repo, graftstate): +def _abortgraft(ui, repo): """abort the interrupted graft and rollbacks to the state before interrupted graft""" + graftstate = statemod.cmdstate(repo, 'graftstate') if not graftstate.exists(): raise error.Abort(_("no interrupted graft to abort")) statedata = _readgraftstate(repo, graftstate) @@ -2760,6 +2761,12 @@ ui.status(_("working directory is now at %s\n") % pctx.hex()[:12]) return 0 +statemod.addunfinished( + 'graft', fname='graftstate', clearable=True, stopflag=True, + continueflag=True, abortfunc=_abortgraft, + cmdhint=_("use 'hg graft --continue' or 'hg graft --stop' to stop") +) + @command('grep', [('0', 'print0', None, _('end fields with NUL')), ('', 'all', None, _('print all revisions that match (DEPRECATED) ')), diff --git a/mercurial/state.py b/mercurial/state.py --- a/mercurial/state.py +++ b/mercurial/state.py @@ -194,11 +194,6 @@ _unfinishedstates.insert(0, statecheckobj) addunfinished( - 'graft', fname='graftstate', clearable=True, stopflag=True, - continueflag=True, - cmdhint=_("use 'hg graft --continue' or 'hg graft --stop' to stop") -) -addunfinished( 'unshelve', fname='shelvedstate', continueflag=True, cmdmsg=_('unshelve already in progress') ) diff --git a/tests/test-abort.t b/tests/test-abort.t new file mode 100644 --- /dev/null +++ b/tests/test-abort.t @@ -0,0 +1,139 @@ + +####TEST `hg abort` operation graft + +Testing the hg abort for `hg graft` which aborts and rollback to state +before the graft + + $ hg init abortgraft + $ cd abortgraft + $ for ch in a b c d; do echo $ch > $ch; hg add $ch; hg ci -Aqm "added "$ch; done; + + $ hg up '.^^' + 0 files updated, 0 files merged, 2 files removed, 0 files unresolved + + $ echo x > x + $ hg ci -Aqm "added x" + $ hg up '.^' + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + $ echo foo > c + $ hg ci -Aqm "added foo to c" + + $ hg log -GT "{rev}:{node|short} {desc}" + @ 5:36b793615f78 added foo to c + | + | o 4:863a25e1a9ea added x + |/ + | o 3:9150fe93bec6 added d + | | + | o 2:155349b645be added c + |/ + o 1:5f6d8a4bf34a added b + | + o 0:9092f1db7931 added a + + $ hg up 9150fe93bec6 + 2 files updated, 0 files merged, 0 files removed, 0 files unresolved + + $ hg abort + abort: no operation in progress + [255] + +when stripping is required + $ hg graft -r 4 -r 5 + grafting 4:863a25e1a9ea "added x" + grafting 5:36b793615f78 "added foo to c" (tip) + merging c + warning: conflicts while merging c! (edit, then use 'hg resolve --mark') + abort: unresolved conflicts, can't continue + (use 'hg resolve' and 'hg graft --continue') + [255] + +when in dry-run mode + $ hg abort --dry-run + abort: aborting graft + [255] + +when in no-backup mode + $ hg abort --no-backup + abort: graft does not support no-backup + [255] + +when dry-run mode is used with no backup + $ hg abort --dry-run --no-backup + abort: graft does not support no-backup + [255] + +normal abort + $ hg abort + graft aborted + working directory is now at 9150fe93bec6 + $ hg log -GT "{rev}:{node|short} {desc}" + o 5:36b793615f78 added foo to c + | + | o 4:863a25e1a9ea added x + |/ + | @ 3:9150fe93bec6 added d + | | + | o 2:155349b645be added c + |/ + o 1:5f6d8a4bf34a added b + | + o 0:9092f1db7931 added a + +when stripping is not required + $ hg graft -r 5 + grafting 5:36b793615f78 "added foo to c" (tip) + merging c + warning: conflicts while merging c! (edit, then use 'hg resolve --mark') + abort: unresolved conflicts, can't continue + (use 'hg resolve' and 'hg graft --continue') + [255] + + $ hg abort + graft aborted + working directory is now at 9150fe93bec6 + $ hg log -GT "{rev}:{node|short} {desc}" + o 5:36b793615f78 added foo to c + | + | o 4:863a25e1a9ea added x + |/ + | @ 3:9150fe93bec6 added d + | | + | o 2:155349b645be added c + |/ + o 1:5f6d8a4bf34a added b + | + o 0:9092f1db7931 added a + +when some of the changesets became public + + $ hg graft -r 4 -r 5 + grafting 4:863a25e1a9ea "added x" + grafting 5:36b793615f78 "added foo to c" (tip) + merging c + warning: conflicts while merging c! (edit, then use 'hg resolve --mark') + abort: unresolved conflicts, can't continue + (use 'hg resolve' and 'hg graft --continue') + [255] + + $ hg log -GT "{rev}:{node|short} {desc}" + @ 6:6ec71c037d94 added x + | + | o 5:36b793615f78 added foo to c + | | + | | o 4:863a25e1a9ea added x + | |/ + o | 3:9150fe93bec6 added d + | | + o | 2:155349b645be added c + |/ + o 1:5f6d8a4bf34a added b + | + o 0:9092f1db7931 added a + + $ hg phase -r 6 --public + + $ hg abort + cannot clean up public changesets 6ec71c037d94 + graft aborted + working directory is now at 6ec71c037d94