diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -3418,3 +3418,9 @@ except error.CorruptedState: nodes = repo.vfs.read('graftstate').splitlines() return {'nodes': nodes} + +def hgabortgraft(ui, repo, **opts): + """ abort logic for aborting graft using 'hg abort'""" + with repo.wlock(): + graftstate = statemod.cmdstate(repo, 'graftstate') + return abortgraft(ui, repo, graftstate) diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2677,6 +2677,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=cmdutil.hgabortgraft, + 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-graft.t b/tests/test-graft.t --- a/tests/test-graft.t +++ b/tests/test-graft.t @@ -1,9 +1,18 @@ +#testcases abortcommand abortflag + $ cat >> $HGRCPATH < [extdiff] > # for portability: > pdiff = sh "$RUNTESTDIR/pdiff" > EOF +#if abortflag + $ cat >> $HGRCPATH < [alias] + > abort = graft --abort + > EOF +#endif + Create a repo with some stuff in it: $ hg init a @@ -1986,8 +1995,9 @@ $ hg up 9150fe93bec6 2 files updated, 0 files merged, 0 files removed, 0 files unresolved - $ hg graft --abort - abort: no interrupted graft to abort + $ hg abort + abort: no interrupted graft to abort (abortflag !) + abort: no operation in progress (abortcommand !) [255] when stripping is required @@ -2016,7 +2026,13 @@ abort: cannot specify any other flag with '--abort' [255] - $ hg graft --abort +#if abortcommand +when in dry-run mode + $ hg abort --dry-run + graft in progress, will be aborted +#endif + + $ hg abort graft aborted working directory is now at 9150fe93bec6 $ hg log -GT "{rev}:{node|short} {desc}" @@ -2041,7 +2057,7 @@ (use 'hg resolve' and 'hg graft --continue') [255] - $ hg graft --abort + $ hg abort graft aborted working directory is now at 9150fe93bec6 $ hg log -GT "{rev}:{node|short} {desc}" @@ -2085,7 +2101,7 @@ $ hg phase -r 6 --public - $ hg graft --abort + $ hg abort cannot clean up public changesets 6ec71c037d94 graft aborted working directory is now at 6ec71c037d94 @@ -2162,7 +2178,7 @@ new changesets 311dfc6cf3bf (1 drafts) (run 'hg heads .' to see heads, 'hg merge' to merge) - $ hg graft --abort + $ hg abort new changesets detected on destination branch, can't strip graft aborted working directory is now at 6b98ff0062dd