uncommit: allow power users to leave an empty commit around

Some power user workflow requires `uncommit` to leave an empty commit so
they can run `hg amend` afterwards. I don't find easy alternatives so let's
allow that if `ui.allowemptyconfig` is set.

Note: `ui.allowemptyconfig` is an internal config that is not documented for
end-users. Core Mercurial seems to be trying to prevent the empty commit
case from normal users (like, comment disallows that, rebase will skip a
commit if after rebasing it becomes empty). So it seems better to still use
that undocumented config instead of a more discoverable flag.

Differential Revision: https://phab.mercurial-scm.org/D156
This commit is contained in:
Jun Wu 2017-07-21 08:06:47 -07:00
parent 932d143025
commit 35b19c0b64
2 changed files with 24 additions and 1 deletions

View File

@ -57,7 +57,7 @@ def _commitfiltered(repo, ctx, match):
return None
files = (initialfiles - exclude)
if not files:
if not files and not repo.ui.configbool('ui', 'allowemptycommit'):
return ctx.parents()[0].node()
# Filter copies

View File

@ -5,6 +5,7 @@ Test uncommit - set up the config
> evolution=createmarkers
> [extensions]
> uncommit = $TESTDIR/../hgext3rd/uncommit.py
> drawdag=$RUNTESTDIR/drawdag.py
> EOF
Build up a repo
@ -200,3 +201,25 @@ Partial uncommit with public parent
14: draft
$ hg phase -r ".^"
10: public
Uncommit leaving an empty changeset
$ cd $TESTTMP
$ hg init repo1
$ cd repo1
$ hg debugdrawdag <<'EOS'
> Q
> |
> P
> EOS
$ hg up Q -q
$ hg uncommit --config ui.allowemptycommit=1
$ hg log -G -T '{desc} FILES: {files}'
@ Q FILES:
|
| x Q FILES: Q
|/
o P FILES: P
$ hg status
A Q