git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Determining if a merge was produced automatically
@ 2024-06-30 18:06 Pavel Rappo
       [not found] ` <CANiSa6hVbrCpPtBCL_W8+43uWGL0LFJkFhSJYGtfFgxX75zE8w@mail.gmail.com>
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Pavel Rappo @ 2024-06-30 18:06 UTC (permalink / raw)
  To: Git mailing list

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-07-01 22:26 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-30 18:06 Determining if a merge was produced automatically Pavel Rappo
     [not found] ` <CANiSa6hVbrCpPtBCL_W8+43uWGL0LFJkFhSJYGtfFgxX75zE8w@mail.gmail.com>
2024-07-01  0:45   ` Martin von Zweigbergk
2024-07-01 15:11     ` Elijah Newren
2024-07-01 16:43       ` Pavel Rappo
2024-07-01 11:49 ` Jonathan Nieder
2024-07-01 13:13   ` Pavel Rappo
2024-07-01 15:43   ` Junio C Hamano
2024-07-01 15:39 ` Junio C Hamano
2024-07-01 16:08   ` Pavel Rappo
2024-07-01 18:16     ` Junio C Hamano
2024-07-01 22:26       ` Pavel Rappo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).