diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -3089,13 +3089,20 @@ return b"\n".join(edittext) -def commitstatus(repo, node, branch, bheads=None, opts=None): +def commitstatus(repo, node, branch, bheads=None, tip=None, opts=None): if opts is None: opts = {} ctx = repo[node] parents = ctx.parents() - if ( + if tip is not None and repo.changelog.tip() == tip: + # avoid reporting something like "committed new head" when + # recommitting old changesets, and issue a helpful warning + # for most instances + repo.ui.warn( + _("warning: commit already existed in the repository!\n"), + ) + elif ( not opts.get(b'amend') and bheads and node not in bheads diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -850,11 +850,14 @@ message, opts.get(b'user'), opts.get(b'date'), match, editor=e ) + # save to detect changes + tip = repo.changelog.tip() + newnode = cmdutil.commit(ui, repo, commitfunc, [], opts) if not newnode: ui.status(_(b"nothing changed\n")) return 1 - cmdutil.commitstatus(repo, newnode, branch, bheads) + cmdutil.commitstatus(repo, newnode, branch, bheads, tip) def nice(node): return b'%d:%s' % (repo.changelog.rev(node), short(node)) @@ -2024,6 +2027,7 @@ branch = repo[None].branch() bheads = repo.branchheads(branch) + tip = repo.changelog.tip() extra = {} if opts.get(b'close_branch') or opts.get(b'force_close_branch'): @@ -2113,7 +2117,7 @@ ui.status(_(b"nothing changed\n")) return 1 - cmdutil.commitstatus(repo, node, branch, bheads, opts) + cmdutil.commitstatus(repo, node, branch, bheads, tip, opts) if not ui.quiet and ui.configbool(b'commands', b'commit.post-status'): status( diff --git a/mercurial/commit.py b/mercurial/commit.py --- a/mercurial/commit.py +++ b/mercurial/commit.py @@ -79,6 +79,9 @@ if repo.changelog._copiesstorage == b'extra': extra = _extra_with_copies(repo, extra, files) + # save the tip to check whether we actually committed anything + oldtip = repo.changelog.tiprev() + # update changelog repo.ui.note(_(b"committing changelog\n")) repo.changelog.delayupdate(tr) @@ -99,7 +102,11 @@ ) # set the new commit is proper phase targetphase = subrepoutil.newcommitphase(repo.ui, ctx) - if targetphase: + + # prevent unmarking changesets as public on recommit + waspublic = oldtip == repo.changelog.tiprev() and not repo[n].phase() + + if targetphase and not waspublic: # retract boundary do not alter parent changeset. # if a parent have higher the resulting phase will # be compliant anyway diff --git a/tests/test-backout.t b/tests/test-backout.t --- a/tests/test-backout.t +++ b/tests/test-backout.t @@ -819,5 +819,5 @@ 1 files updated, 0 files merged, 1 files removed, 0 files unresolved $ hg backout 2 removing 3 - created new head + warning: commit already existed in the repository! changeset 3:8f188de730d9 backs out changeset 2:cccc23d9d68f diff --git a/tests/test-phases.t b/tests/test-phases.t --- a/tests/test-phases.t +++ b/tests/test-phases.t @@ -999,3 +999,56 @@ date: Thu Jan 01 00:00:00 1970 +0000 summary: A + $ cd .. + +Recommitting an exact match of a public commit shouldn't change it to +draft: + + $ cd initialrepo + $ hg phase -r 2 + 2: public + $ hg up -C 1 + 0 files updated, 0 files merged, 4 files removed, 0 files unresolved + $ mkcommit C + warning: commit already existed in the repository! + $ hg phase -r 2 + 2: public + +Same, but for secret: + + $ hg up 7 + 3 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ mkcommit F -s + test-debug-phase: new rev 8: x -> 2 + test-hook-close-phase: de414268ec5ce2330c590b942fbb5ff0b0ca1a0a: -> secret + $ hg up 7 + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + $ hg phase + 7: draft + $ mkcommit F + test-debug-phase: new rev 8: x -> 2 + warning: commit already existed in the repository! + test-hook-close-phase: de414268ec5ce2330c590b942fbb5ff0b0ca1a0a: -> secret + $ hg phase -r tip + 8: secret + +But what about obsoleted changesets? + + $ hg up 4 + 0 files updated, 0 files merged, 2 files removed, 0 files unresolved + $ mkcommit H + test-debug-phase: new rev 5: x -> 2 + warning: commit already existed in the repository! + test-hook-close-phase: a030c6be5127abc010fcbff1851536552e6951a8: -> secret + $ hg phase -r 5 + 5: secret + $ hg par + changeset: 5:a030c6be5127 + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + obsolete: pruned + summary: H + + $ hg up tip + 2 files updated, 0 files merged, 1 files removed, 0 files unresolved + $ cd .. diff --git a/tests/test-unamend.t b/tests/test-unamend.t --- a/tests/test-unamend.t +++ b/tests/test-unamend.t @@ -405,8 +405,10 @@ $ hg co -q 0 $ hg mv a b $ hg ci -qm 'move to a b' + warning: commit already existed in the repository! $ hg mv b c $ hg amend + warning: commit already existed in the repository! $ hg mv c d $ hg unamend $ hg st --copies --change .