uncommit: don't allow dirty working copy with PATH (
issue5977)
On a dirty PATH, uncommit was working without even setting the config
`experimental.uncommitondirtydir` to `True`. Ideally, it should abort
as it does for a dirty dir. This patch makes uncommit to require the
config option `experimental.uncommitondirtydir` on a dirty PATH.
Original patch to evolve extension authored by Dan Villiom Podlaski Christiansen:
https://bitbucket.org/octobus/evolve-devel/pull-requests/8/bug-5977-uncommit-dirtiness/diff
Differential Revision: https://phab.mercurial-scm.org/D5940
--- a/hgext/uncommit.py Tue Mar 05 09:51:57 2019 -0500
+++ b/hgext/uncommit.py Tue Feb 12 00:17:42 2019 +0530
@@ -158,9 +158,12 @@
with repo.wlock(), repo.lock():
- if not pats and not repo.ui.configbool('experimental',
- 'uncommitondirtywdir'):
- cmdutil.bailifchanged(repo)
+ m, a, r, d = repo.status()[:4]
+ isdirtypath = any(set(m + a + r + d) & set(pats))
+ if (not repo.ui.configbool('experimental', 'uncommitondirtywdir') and
+ (not pats or isdirtypath)):
+ cmdutil.bailifchanged(repo, hint=_('requires '
+ 'experimental.uncommitondirtywdir to uncommit'))
old = repo['.']
rewriteutil.precheck(repo, [old.rev()], 'uncommit')
if len(old.parents()) > 1:
--- a/tests/test-uncommit.t Tue Mar 05 09:51:57 2019 -0500
+++ b/tests/test-uncommit.t Tue Feb 12 00:17:42 2019 +0530
@@ -156,9 +156,12 @@
M files
$ hg uncommit
abort: uncommitted changes
+ (requires experimental.uncommitondirtywdir to uncommit)
[255]
$ hg uncommit files
- note: keeping empty commit
+ abort: uncommitted changes
+ (requires experimental.uncommitondirtywdir to uncommit)
+ [255]
$ cat files
abcde
foo
@@ -169,6 +172,7 @@
$ echo "bar" >> files
$ hg uncommit
abort: uncommitted changes
+ (requires experimental.uncommitondirtywdir to uncommit)
[255]
$ hg uncommit --config experimental.uncommitondirtywdir=True
$ hg commit -m "files abcde + foo"
@@ -192,16 +196,16 @@
+abc
$ hg bookmark
- foo 10:48e5bd7cd583
+ foo 9:48e5bd7cd583
$ hg uncommit
3 new orphan changesets
$ hg status
M files
A file-abc
$ hg heads -T '{rev}:{node} {desc}'
- 10:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo (no-eol)
+ 9:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo (no-eol)
$ hg bookmark
- foo 10:48e5bd7cd583
+ foo 9:48e5bd7cd583
$ hg commit -m 'new abc'
created new head
@@ -223,38 +227,36 @@
+ab
$ hg bookmark
- foo 10:48e5bd7cd583
+ foo 9:48e5bd7cd583
$ hg uncommit file-ab
1 new orphan changesets
$ hg status
A file-ab
$ hg heads -T '{rev}:{node} {desc}\n'
- 12:8eb87968f2edb7f27f27fe676316e179de65fff6 added file-ab
- 11:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc
- 10:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo
+ 11:8eb87968f2edb7f27f27fe676316e179de65fff6 added file-ab
+ 10:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc
+ 9:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo
$ hg bookmark
- foo 10:48e5bd7cd583
+ foo 9:48e5bd7cd583
$ hg commit -m 'update ab'
$ hg status
$ hg heads -T '{rev}:{node} {desc}\n'
- 13:f21039c59242b085491bb58f591afc4ed1c04c09 update ab
- 11:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc
- 10:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo
+ 12:f21039c59242b085491bb58f591afc4ed1c04c09 update ab
+ 10:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc
+ 9:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo
$ hg log -G -T '{rev}:{node} {desc}' --hidden
- @ 13:f21039c59242b085491bb58f591afc4ed1c04c09 update ab
+ @ 12:f21039c59242b085491bb58f591afc4ed1c04c09 update ab
|
- o 12:8eb87968f2edb7f27f27fe676316e179de65fff6 added file-ab
+ o 11:8eb87968f2edb7f27f27fe676316e179de65fff6 added file-ab
|
- | * 11:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc
+ | * 10:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc
| |
- | | * 10:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo
+ | | * 9:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo
| | |
- | | | x 9:8a6b58c173ca6a2e3745d8bd86698718d664bc6c files abcde + foo
- | | |/
- | | | x 8:39ad452c7f684a55d161c574340c5766c4569278 update files for abcde
+ | | | x 8:84beeba0ac30e19521c036e4d2dd3a5fa02586ff files abcde + foo
| | |/
| | | x 7:0977fa602c2fd7d8427ed4e7ee15ea13b84c9173 update files for abcde
| | |/
@@ -276,7 +278,7 @@
$ hg uncommit
$ hg phase -r .
- 12: draft
+ 11: draft
$ hg commit -m 'update ab again'
Phase is preserved
@@ -284,7 +286,7 @@
$ hg uncommit --keep --config phases.new-commit=secret
note: keeping empty commit
$ hg phase -r .
- 15: draft
+ 14: draft
$ hg commit --amend -m 'update ab again'
Uncommit with public parent
@@ -292,7 +294,7 @@
$ hg phase -p "::.^"
$ hg uncommit
$ hg phase -r .
- 12: public
+ 11: public
Partial uncommit with public parent
@@ -303,9 +305,9 @@
$ hg status
A xyz
$ hg phase -r .
- 18: draft
+ 17: draft
$ hg phase -r ".^"
- 12: public
+ 11: public
Uncommit with --keep or experimental.uncommit.keep leaves an empty changeset
@@ -393,6 +395,7 @@
$ hg uncommit
abort: outstanding uncommitted merge
+ (requires experimental.uncommitondirtywdir to uncommit)
[255]
$ hg uncommit --config experimental.uncommitondirtywdir=True
@@ -463,3 +466,49 @@
a
A c
a
+ $ cd ..
+
+experimental.uncommitondirtywdir should also work on a dirty PATH
+
+ $ hg init issue5977
+ $ cd issue5977
+ $ echo 'super critical info!' > a
+ $ hg ci -Am 'add a'
+ adding a
+ $ echo 'foo' > b
+ $ hg add b
+ $ hg status
+ A b
+ $ hg unc a
+ note: keeping empty commit
+ $ hg unc b
+ abort: uncommitted changes
+ (requires experimental.uncommitondirtywdir to uncommit)
+ [255]
+ $ cat a
+ super critical info!
+ $ hg log
+ changeset: 1:656ba143d384
+ tag: tip
+ parent: -1:000000000000
+ user: test
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: add a
+
+ $ hg ci -Am 'add b'
+ $ echo 'foo bar' > b
+ $ hg unc --config experimental.uncommitondirtywdir=True b
+ $ hg log
+ changeset: 3:30fa958635b2
+ tag: tip
+ parent: 1:656ba143d384
+ user: test
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: add b
+
+ changeset: 1:656ba143d384
+ parent: -1:000000000000
+ user: test
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: add a
+