abort: added support for graft
This adds support of `graft` to `hg abort` plan.
The patch creates a seperate function `cmdutil.hgabortgraft`
so that abort logic for graft can be called independently.
This logic is registered to the statedetection API as `abortfunc`.
Results are shown as tests.
Differential Revision: https://phab.mercurial-scm.org/D6567
--- a/mercurial/cmdutil.py Sun Jun 23 20:58:01 2019 +0530
+++ b/mercurial/cmdutil.py Sun Jun 23 22:31:31 2019 +0530
@@ -3419,3 +3419,9 @@
except error.CorruptedState:
nodes = repo.vfs.read('graftstate').splitlines()
return {'nodes': nodes}
+
+def hgabortgraft(ui, repo):
+ """ abort logic for aborting graft using 'hg abort'"""
+ with repo.wlock():
+ graftstate = statemod.cmdstate(repo, 'graftstate')
+ return abortgraft(ui, repo, graftstate)
--- a/mercurial/commands.py Sun Jun 23 20:58:01 2019 +0530
+++ b/mercurial/commands.py Sun Jun 23 22:31:31 2019 +0530
@@ -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) ')),
--- a/mercurial/state.py Sun Jun 23 20:58:01 2019 +0530
+++ b/mercurial/state.py Sun Jun 23 22:31:31 2019 +0530
@@ -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')
)
--- a/tests/test-graft.t Sun Jun 23 20:58:01 2019 +0530
+++ b/tests/test-graft.t Sun Jun 23 22:31:31 2019 +0530
@@ -1,9 +1,18 @@
+#testcases abortcommand abortflag
+
$ cat >> $HGRCPATH <<EOF
> [extdiff]
> # for portability:
> pdiff = sh "$RUNTESTDIR/pdiff"
> EOF
+#if abortflag
+ $ cat >> $HGRCPATH <<EOF
+ > [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