commit: create new amend changeset as secret correctly for "--secret" option
Before this patch, "hg commit --amend --secret" doesn't create new
amend changeset as secret, even though the internal function
"commitfunc()" passed to "cmdutil.amend()" make "phases.new-commit"
configuration as "secret" temporarily.
"cmdutil.amend()" uses specified "commitfunc" only for temporary amend
commit, and creates the final amend commit changeset by
"localrepository.commitctx()" directly with memctx.
This patch creates new amend changeset as secret correctly for
"--secret" option, by changing "phases.new-commit" configuration
temporarily before "localrepository.commitctx()".
--- a/mercurial/cmdutil.py Wed Mar 12 10:26:48 2014 +0200
+++ b/mercurial/cmdutil.py Thu Mar 13 19:48:41 2014 +0900
@@ -1797,7 +1797,11 @@
ph = repo.ui.config('phases', 'new-commit', phases.draft)
try:
- repo.ui.setconfig('phases', 'new-commit', old.phase())
+ if opts.get('secret'):
+ commitphase = 'secret'
+ else:
+ commitphase = old.phase()
+ repo.ui.setconfig('phases', 'new-commit', commitphase)
newid = repo.commitctx(new)
finally:
repo.ui.setconfig('phases', 'new-commit', ph)
--- a/mercurial/commands.py Wed Mar 12 10:26:48 2014 +0200
+++ b/mercurial/commands.py Thu Mar 13 19:48:41 2014 +0900
@@ -1397,6 +1397,7 @@
if opts.get('force_editor'):
e = cmdutil.commitforceeditor
+ # commitfunc is used only for temporary amend commit by cmdutil.amend
def commitfunc(ui, repo, message, match, opts):
editor = e
# message contains text from -m or -l, if it's empty,
@@ -1404,18 +1405,12 @@
if not message:
message = old.description()
editor = cmdutil.commitforceeditor
- try:
- if opts.get('secret'):
- ui.setconfig('phases', 'new-commit', 'secret')
-
- return repo.commit(message,
- opts.get('user') or old.user(),
- opts.get('date') or old.date(),
- match,
- editor=editor,
- extra=extra)
- finally:
- ui.setconfig('phases', 'new-commit', oldcommitphase)
+ return repo.commit(message,
+ opts.get('user') or old.user(),
+ opts.get('date') or old.date(),
+ match,
+ editor=editor,
+ extra=extra)
current = repo._bookmarkcurrent
marks = old.bookmarks()
--- a/tests/test-commit-amend.t Wed Mar 12 10:26:48 2014 +0200
+++ b/tests/test-commit-amend.t Thu Mar 13 19:48:41 2014 +0900
@@ -765,3 +765,14 @@
$ hg ci --close-branch -m'open and close'
abort: can only close branch heads
[255]
+
+Test that amend with --secret creates new secret changeset forcibly
+---------------------------------------------------------------------
+
+ $ hg phase '.^::.'
+ 35: draft
+ 36: draft
+ $ hg commit --amend --secret -m 'amend as secret' -q
+ $ hg phase '.^::.'
+ 35: draft
+ 38: secret