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( 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/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]