How can I tell when Mercurial merge was trivial?

Sometimes when I do hg merge and then check hg status , nothing is printed. In other cases, I see actual changes from another branch. Why is this happening? Can you explain the differences between mergers?

The point of this question is this: we connect Mercurial to Jira and guarantee that each commit must contain the task identifier and that each such commit will be checked by the code before it is clicked. However, we do not require reviews for “trivial” mergers, so we check our commit hook:

 if not ctx.files(): return ALLOW_COMMIT 

However, I came across situations where the commit was trivial (i.e. Mercurial did all the work, and I did not need to resolve any conflicts), but the ctx.files() list is not empty. However, in most cases, everything works fine. I would like to publish an example for each case, but I just can’t understand what is the difference between the two situations.

Basically I ask: how can I tell when a Mercurial merge was trivial?

+4
source share
3 answers

This actually turns out to be a more difficult problem than you expected. A year or two ago, I tried to write a plugin to create a "diff merge", showing only the changes made to the merge: https://www.mercurial-scm.org/wiki/MergediffExtension

It has some errors ... But if it shows an empty diff merge, it definitely means that the merge was “trivial” (although there are some trivial merges for which it will show diff).

Alternatively, this question / answer may help: How to check for possible merge / redirect conflicts in Mercurial?

+1
source

You can replay the merge. If it fails, it is not trivial. If this succeeds, compare the result with the previously performed merge. If both merge results are identical, it was trivial, otherwise there were manual settings.

However, this assumes that the reuse uses the same merge algorithm as the original merge. Different versions and configurations of Mercurial may contradict this assumption.

UPDATE

If you want to perform these checks before performing a merge, you can use the pre-merge, which “views” the merge (instead of replaying it later). On the hook, do the proposed merge automatically and check for conflicts. Conflicts are not potentially trivial, save the diff merge in a temporary file. Do not forget about working copy changes caused by automatic merging ( hg up -r . -C ). Then, when a person wants to make her actual merge, use the pre-commit hook to check if the manual merge is different from the automatic one stored in a temporary file. If it is different, a review is required.

However, although this should work in principle, IMHO is a kind of over-engineering.

+1
source

Why is this happening? Can you explain the differences between mergers?

  • If it was a manual merge, the merge may prefer only its own changes and discard the changes from the merged branch, i.e. have a fictitious merge (it can also be a non-interactive merge with tool=internal:local )
  • A rare case - in both files the changes (from the common parent) can be the same, the merge target will not be changed in this case

PS : I don’t know what ctx.files() , but if it’s “files changed in the changeset”, disabling the commit in case of existing such files - Bad Idea (tm) - the files can be changed due to merging (without conflicts) and in this situation Martin’s idea of responding to combining and checking the list of permissions seems to be a pretty good approach

0
source

All Articles