Patchwork D7786: update: add --abort option in hg update command (issue4404)

login
register
mail settings
Submitter phabricator
Date Jan. 3, 2020, 3:06 p.m.
Message ID <differential-rev-PHID-DREV-rolew3oydepphduflvj3-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/44145/
State New
Headers show

Comments

phabricator - Jan. 3, 2020, 3:06 p.m.
khanchi97 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Here is, what --abort option is basically doing:
  
  1. hg resolve --unmark, then
  2. hg resolve --all --tool :local
  3. hg up <original ctx> --tool :local
  
  Where,
  step 1) is to mark all the files conflicted as unresolved (marking *all*
  files to make sure that it also mark the files which might have been
  resolved by user in meantime)
  
  step 2) resolve all the conflicting files using `--tool :local`
  
  step 3) update to the revision where it was checkedout before running the
  hg update, using `--tool :local`
  
  Use of `--tool :local` while updating to old revision (step3) make sure that
  it will not hit merge conflict at the time of update. And since we are using
  the same tool (:local) as we used at the time of resolution (step2) it makes
  sure that we have exact changes in working directory as it was before IIUC.
  
  Added tests demonstrate the behaviour of new flag.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/commands.py
  tests/test-completion.t
  tests/test-update-branches.t

CHANGE DETAILS




To: khanchi97, #hg-reviewers
Cc: mercurial-devel
phabricator - Jan. 4, 2020, 7 a.m.
This revision now requires changes to proceed.
mharbison72 added a comment.
mharbison72 requested changes to this revision.


  This looks like a respin of D6735 <https://phab.mercurial-scm.org/D6735>.  Can you take a look at my comments in there about subrepos, and incorporate the appropriate tests?  (I also didn't side by side compare the existing tests, so I'm not sure if there are things tested in that revision that aren't tested here.)

REPOSITORY
  rHG Mercurial

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

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

To: khanchi97, #hg-reviewers, mharbison72
Cc: mharbison72, mercurial-devel

Patch

diff --git a/tests/test-update-branches.t b/tests/test-update-branches.t
--- a/tests/test-update-branches.t
+++ b/tests/test-update-branches.t
@@ -676,3 +676,80 @@ 
   [255]
   $ hg co --no-check 2
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ cd ..
+
+Test hg update --abort option
+  $ hg init issue4404
+  $ cd issue4404
+  $ echo "before\nmiddle" > file
+  $ hg add file
+  $ hg commit -mbefore
+  $ echo "after\nmiddle" > file
+  $ hg commit -mafter
+  $ echo "edited\nmiddle\nlast" > file
+  $ echo foo > foo
+  $ hg add foo
+
+  $ hg diff
+  diff -r fd93e7c2e3ea file
+  --- a/file	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/file	Thu Jan 01 00:00:00 1970 +0000
+  @@ -1,2 +1,3 @@
+  -after
+  +edited
+   middle
+  +last
+  diff -r fd93e7c2e3ea foo
+  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/foo	Thu Jan 01 00:00:00 1970 +0000
+  @@ -0,0 +1,1 @@
+  +foo
+
+  $ hg update 0 --no-check
+  merging file
+  warning: conflicts while merging file! (edit, then use 'hg resolve --mark')
+  0 files updated, 0 files merged, 0 files removed, 1 files unresolved
+  use 'hg resolve' to retry unresolved file merges
+  [1]
+  $ hg diff
+  diff -r f013c8cc5b24 file
+  --- a/file	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/file	Thu Jan 01 00:00:00 1970 +0000
+  @@ -1,2 +1,7 @@
+  +<<<<<<< working copy: fd93e7c2e3ea - test: after
+  +edited
+  +=======
+   before
+  +>>>>>>> destination:  f013c8cc5b24 - test: before
+   middle
+  +last
+  diff -r f013c8cc5b24 foo
+  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/foo	Thu Jan 01 00:00:00 1970 +0000
+  @@ -0,0 +1,1 @@
+  +foo
+
+  $ hg up --abort
+  update aborted
+
+Make sure diff is same as it was before running hg update
+  $ hg diff
+  diff -r fd93e7c2e3ea file
+  --- a/file	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/file	Thu Jan 01 00:00:00 1970 +0000
+  @@ -1,2 +1,3 @@
+  -after
+  +edited
+   middle
+  +last
+  diff -r fd93e7c2e3ea foo
+  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/foo	Thu Jan 01 00:00:00 1970 +0000
+  @@ -0,0 +1,1 @@
+  +foo
+
+Error out if there is no interrupted update
+  $ hg up --abort
+  abort: no interrupted update exists
+  [255]
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -357,7 +357,7 @@ 
   tip: patch, git, style, template
   unbundle: update
   unshelve: abort, continue, interactive, keep, name, tool, date
-  update: clean, check, merge, date, rev, tool
+  update: abort, clean, check, merge, date, rev, tool
   verify: full
   version: template
 
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -7590,6 +7590,7 @@ 
 @command(
     b'update|up|checkout|co',
     [
+        (b'a', b'abort', None, _(b'abort the interrupted update')),
         (b'C', b'clean', None, _(b'discard uncommitted changes (no backup)')),
         (b'c', b'check', None, _(b'require clean working directory')),
         (b'm', b'merge', None, _(b'merge uncommitted changes')),
@@ -7661,9 +7662,26 @@ 
     clean = opts.get('clean')
     check = opts.get('check')
     merge = opts.get('merge')
+    abort = opts.get('abort')
     if rev and node:
         raise error.Abort(_(b"please specify just one revision"))
 
+    if abort:
+        overrides = {(b'ui', b'forcemerge'): b':local', (b'ui', 'quiet'): True}
+        with repo.wlock(), ui.configoverride(overrides, b'update'):
+            ms = mergemod.mergestate.read(repo)
+            if not ms.active():
+                raise error.Abort(_(b'no interrupted update exists'))
+            resolve(ui, repo, **{'unmark': True})
+            resolve(ui, repo, **{'all': True, 'tool':':local'})
+            # hg update to orig revision
+            local = ms.localctx
+            updatecheck = b'none'
+            hg.updatetotally(ui, repo, local, local, updatecheck=updatecheck)
+            ms.clean(repo)
+        ui.status(_(b'update aborted\n'))
+        return 0
+
     if ui.configbool(b'commands', b'update.requiredest'):
         if not node and not rev and not date:
             raise error.Abort(