# HG changeset patch # User FUJIWARA Katsunori # Date 1394707721 -32400 # Node ID b0153cb8b64efb546cbf3bd6bba5a6770ab2563f # Parent 58c32a9c8e7be52b5c820be502340cdaf98dfa4c 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()". diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -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) diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -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() diff --git a/tests/test-commit-amend.t b/tests/test-commit-amend.t --- a/tests/test-commit-amend.t +++ b/tests/test-commit-amend.t @@ -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