Mercurial > evolve
changeset 3389:eacf6149b678
uncommit: add a new flag `--revert` to discard wdir changes after uncommit
This patch adds a new flag to `hg uncommit` using which one can discard the wdir
changes which are left after the operation. Both the changes, the ones which
were before the uncommit and the ones which were added to wdir as a result of
uncommit as cleared out.
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Tue, 09 Jan 2018 20:01:50 +0530 |
parents | be41e4740a25 |
children | b3dbba6e34c9 |
files | CHANGELOG hgext3rd/evolve/cmdrewrite.py tests/test-tutorial.t tests/test-uncommit.t |
diffstat | 4 files changed, 60 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGELOG Tue Jan 09 15:39:47 2018 +0530 +++ b/CHANGELOG Tue Jan 09 20:01:50 2018 +0530 @@ -15,6 +15,7 @@ dropped, please update both clients and servers. The new approach is still hidden behind and experimental flag for now. + * uncommit: `--revert` flag added to clean the wdir after uncommit * preserve phase information during interrupted `hg evolve` (issue5720) topic (0.7.1)
--- a/hgext3rd/evolve/cmdrewrite.py Tue Jan 09 15:39:47 2018 +0530 +++ b/hgext3rd/evolve/cmdrewrite.py Tue Jan 09 20:01:50 2018 +0530 @@ -302,6 +302,7 @@ [('a', 'all', None, _('uncommit all changes when no arguments given')), ('i', 'interactive', False, _('interactive mode to uncommit (EXPERIMENTAL)')), ('r', 'rev', '', _('revert commit content to REV instead')), + ('', 'revert', False, _('discard working directory changes after uncommit')), ('n', 'note', '', _('store a note on uncommit')), ] + commands.walkopts + commitopts + commitopts2 + commitopts3, _('[OPTION]... [NAME]')) @@ -388,9 +389,12 @@ obsolete.createmarkers(repo, [(old, (repo[newid],))], metadata=metadata) phases.retractboundary(repo, tr, oldphase, [newid]) - with repo.dirstate.parentchange(): - repo.dirstate.setparents(newid, node.nullid) - _uncommitdirstate(repo, old, match, interactive) + if opts.get('revert'): + hg.updaterepo(repo, newid, True) + else: + with repo.dirstate.parentchange(): + repo.dirstate.setparents(newid, node.nullid) + _uncommitdirstate(repo, old, match, interactive) updatebookmarks(newid) if not repo[newid].files(): ui.warn(_("new changeset is empty\n"))
--- a/tests/test-tutorial.t Tue Jan 09 15:39:47 2018 +0530 +++ b/tests/test-tutorial.t Tue Jan 09 20:01:50 2018 +0530 @@ -937,6 +937,7 @@ -a --all uncommit all changes when no arguments given -r --rev VALUE revert commit content to REV instead + --revert discard working directory changes after uncommit -n --note VALUE store a note on uncommit -I --include PATTERN [+] include names matching the given patterns -X --exclude PATTERN [+] exclude names matching the given patterns
--- a/tests/test-uncommit.t Tue Jan 09 15:39:47 2018 +0530 +++ b/tests/test-uncommit.t Tue Jan 09 20:01:50 2018 +0530 @@ -461,3 +461,54 @@ R g R m R n + +Testing the --revert flag of `hg uncommit` + +When working directory before uncommit is clean + + $ hg amend + $ hg status + ? b + + $ hg diff -c . --stat + aa | 1 + + b | 1 - + c | 1 - + d | 1 + + e | 1 + + f | 1 - + ff | 1 + + g | 1 - + h | 1 + + j | 1 + + k | 1 + + l | 1 + + m | 1 - + n | 1 - + o | 1 + + 15 files changed, 9 insertions(+), 6 deletions(-) + $ hg uncommit --revert --all + new changeset is empty + (use 'hg prune .' to remove it) + $ hg status + +When working directory is dirty before uncommit + + $ echo foo > a + $ echo foo > b + $ echo foo > c + $ hg status + M a + M b + M c + $ hg amend + $ echo foo > foo + $ hg add foo + $ hg status + A foo + + $ hg uncommit --revert --all + new changeset is empty + (use 'hg prune .' to remove it) + $ hg status + ? foo