git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Determining if a merge was produced automatically

From
PRPavel Rappo <pavel.rappo@gmail.com>
Date
Jun 30, 2024, 18:06 UTC
Message-ID
<CAChcVu=Kwqj7JhXqQW6Ni9+3TdSfdmHfSTJQWm1_uO2kczSm8g@mail.gmail.com>
Hello,

I'm looking for a robust way to determine if a given merge commit could've been produced automatically by `git merge`, without any manual intervention or tampering, such as:

  - resolving conflicts,
  - stopping (`--no-commit`) and modifying,
  - amending the commit.

My initial idea was to re-enact the merge. If the merge failed, I would conclude that the original merge couldn't have been produced automatically. If the merge succeeded, I would compare it with the original merge. Any differences would indicate that the original merge couldn't have been produced automatically. Otherwise, I would conclude that it could've been. This approach is simple, but involves multiple steps and requires clean-up.

My second idea was to use `git show --diff-merges=dense-combined`, which only prints hunks that come from neither parent. If nothing is printed, I would conclude that the merge could've been produced automatically. This approach is simple, single-step, but seems to have an issue. In my experiments, I found that if some hunks from different parents were located closely enough, output was produced. So, checking if nothing is output could lead to false negatives: a merge that could've been produced automatically might look like it was tampered with.

My third idea was to use a recently added feature, `git show --remerge-diff`, which seemingly embodies my first idea and is immune to the issue of the second. It is also single-step and requires no clean-up:

> Remerge two-parent merge commits to create a temporary tree object—potentially containing files with conflict markers and such. A diff is then shown between that temporary tree and the actual merge commit.
However, this bit means that I shouldn't entirely trust its output:
> The output emitted when this option is used is subject to change, and so is its interaction with other options (unless explicitly documented).
What is my best course of action?

Thanks, -Pavel

Next: Jonathan Nieder
Message 1 of 11 in “Determining if a merge was produced automatically”
  1. Pavel RappoJun 30, 2024
  2. Jonathan NiederJul 1, 2024
  3. Pavel RappoJul 1, 2024
  4. Junio C HamanoJul 1, 2024
  5. Junio C HamanoJul 1, 2024
  6. Pavel RappoJul 1, 2024
  7. Junio C HamanoJul 1, 2024
  8. Pavel RappoJul 1, 2024
  9. Martin von ZweigbergkJul 1, 2024
  10. Elijah NewrenJul 1, 2024
  11. Pavel RappoJul 1, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.