Patchwork D6567: abort: added support for graft

login
register
mail settings
Submitter phabricator
Date July 4, 2019, 3 p.m.
Message ID <7d752afdcb2386e49088ead6611b7584@localhost.localdomain>
Download mbox | patch
Permalink /patch/40766/
State Not Applicable
Headers show

Comments

phabricator - July 4, 2019, 3 p.m.
taapas1128 edited the summary of this revision.
taapas1128 retitled this revision from "abort: added functionality for graft" to "abort: added support for graft".
taapas1128 updated this revision to Diff 15751.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6567?vs=15732&id=15751

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6567/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6567

AFFECTED FILES
  mercurial/commands.py
  mercurial/state.py
  tests/test-abort.t

CHANGE DETAILS




To: taapas1128, #hg-reviewers
Cc: pulkit, mercurial-devel

Patch

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
+  aborting graft
+
+when in no-backup mode
+  $ hg abort --no-backup
+  abort: graft does not support no-backup flag
+  [255]
+
+when dry-run mode is used with no backup
+  $ hg abort --dry-run --no-backup
+  aborting graft
+  abort: graft does not support no-backup flag
+  [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
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/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2730,6 +2730,15 @@ 
     graftstate.delete()
     return 0
 
+def hgabortgraft(ui, repo, **opts):
+    if opts.get('no_backup'):
+        raise error.Abort(_("graft does not support no-backup flag"))
+    if opts.get('dry_run'):
+        return 0
+    with repo.wlock():
+        graftstate = statemod.cmdstate(repo, 'graftstate')
+        return _abortgraft(ui, repo, graftstate)
+
 def _readgraftstate(repo, graftstate):
     """read the graft state file and return a dict of the data stored in it"""
     try:
@@ -2749,6 +2758,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=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) ')),