Mercurial > hg
changeset 45812:976b26bdd0d8
commit: warn the user when a commit already exists
Sometimes, a commit will result in an exact match of a preexisting
commit, and if that commit isn't a branch head, hg will incorrectly
note that it created a new head. Instead, we should warn the user that
commit already existed in the repository.
In practice, this bug is rather uncommon, and will only occur when the
usr explicitly sets the date.
Please note that this commit contains an API change to
cmdutil.commitstatus()
Differential Revision: https://phab.mercurial-scm.org/D9257
author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
---|---|
date | Thu, 29 Oct 2020 13:54:25 +0100 |
parents | 4404f129341e |
children | 57dc78861196 |
files | mercurial/cmdutil.py mercurial/commands.py tests/test-backout.t tests/test-merge-tools.t tests/test-phases.t tests/test-remotefilelog-local.t tests/test-unamend.t |
diffstat | 7 files changed, 21 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Tue Oct 06 13:34:51 2020 +0200 +++ b/mercurial/cmdutil.py Thu Oct 29 13:54:25 2020 +0100 @@ -3113,13 +3113,18 @@ 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
--- a/mercurial/commands.py Tue Oct 06 13:34:51 2020 +0200 +++ b/mercurial/commands.py Thu Oct 29 13:54:25 2020 +0100 @@ -851,11 +851,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(
--- a/tests/test-backout.t Tue Oct 06 13:34:51 2020 +0200 +++ b/tests/test-backout.t Thu Oct 29 13:54:25 2020 +0100 @@ -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
--- a/tests/test-merge-tools.t Tue Oct 06 13:34:51 2020 +0200 +++ b/tests/test-merge-tools.t Thu Oct 29 13:54:25 2020 +0100 @@ -1868,6 +1868,7 @@ $ hg update -q -C 1 $ hg mv f f.txt $ hg ci -qm "f.txt" + warning: commit already existed in the repository! $ hg update -q -C 2 $ hg merge -y -r tip --tool echo \ > --config merge-tools.echo.args='$base $local $other $output' \
--- a/tests/test-phases.t Tue Oct 06 13:34:51 2020 +0200 +++ b/tests/test-phases.t Thu Oct 29 13:54:25 2020 +0100 @@ -1010,7 +1010,7 @@ $ hg up -C 1 0 files updated, 0 files merged, 4 files removed, 0 files unresolved $ mkcommit C - created new head + warning: commit already existed in the repository! $ hg phase -r 2 2: public @@ -1027,6 +1027,7 @@ 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 @@ -1037,7 +1038,7 @@ 0 files updated, 0 files merged, 2 files removed, 0 files unresolved $ mkcommit H test-debug-phase: new rev 5: x -> 2 - created new head + warning: commit already existed in the repository! test-hook-close-phase: a030c6be5127abc010fcbff1851536552e6951a8: -> secret $ hg phase -r 5 5: secret
--- a/tests/test-remotefilelog-local.t Tue Oct 06 13:34:51 2020 +0200 +++ b/tests/test-remotefilelog-local.t Thu Oct 29 13:54:25 2020 +0100 @@ -204,5 +204,6 @@ $ hg update -r '.^' -q $ echo 1 > A $ hg commit -m foo -A A + warning: commit already existed in the repository! $ hg log -r . -T '{node}\n' 383ce605500277f879b7460a16ba620eb6930b7f
--- a/tests/test-unamend.t Tue Oct 06 13:34:51 2020 +0200 +++ b/tests/test-unamend.t Thu Oct 29 13:54:25 2020 +0100 @@ -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 .