如何从git合并驱动程序中退出合并

huangapple go评论59阅读模式
英文:

How to bail out of a merge from a git merge driver

问题

我们陷入了一个情况,其中git合并驱动程序被错误配置为退化状态(基本上不运行代码)。这将git工作树置于退化状态,因为冲突的文件仍然是以前的文件(基本上是接受合并的一侧)。

如何以最简单、最愚蠢的方式告诉git merge在合并驱动程序内部退出合并,因为合并驱动程序无法正常工作?我真的希望答案是高退出代码(>> 1)。

英文:

We got ourselves into a situation where a git merge driver was misconfigured into a degenerate state (basically, not running code). This put the git working tree into a degenerate state because the conflicted file was just whatever it was before (that is, basically taking one side of the merge).

What's the simplest, stupidest way to tell git merge to bail out of the merge from within the merge driver because the merge driver cannot function? I'm really hoping the answer is a high exit code ( >> 1).

答案1

得分: 1

git merge --quit 在外部合并驱动程序运行时具有更好的工作机会:

在 Git 2.42(2023 年第 3 季度)中,当外部合并驱动程序被信号终止时,不应信任其输出作为驱动程序提出的具有冲突的解决方案,但是代码确实这样做了。

恭喜提问者 Joshua,他在Git 邮件列表上提出了这个问题!

请参见提交 34d765e(2023 年 6 月 23 日)和提交 2b7b788(2023 年 6 月 22 日)由Junio C Hamano (gitster)执行的。
<sup>(由Junio C Hamano -- gitster --合并于提交 3ea43bb,2023 年 6 月 29 日)</sup>

> ## ll-merge: 终止外部合并驱动程序将中止合并
> <sup>由 Elijah Newren 审查</sup>

> 当外部合并驱动程序因信号而终止时,我们不应该期望文件系统上留下的结果具有任何有用的状态。
> 然而,由于当前代码使用来自 run_command() 的返回值,并将任何正值声明为驱动程序成功留下冲突的标志,而 run_command() 的子进程在收到信号后的返回值是正值,因此我们最终将文件系统上的任何垃圾视为合并驱动程序希望留给我们的结果。
>
> run_command() 在注意到子进程因信号而终止时返回大于 128(确切地说是 WTERMSIG(status) + 128),因此请检测这种情况并从 ll_ext_merge() 返回 LL_MERGE_ERROR

gitattributes 现在在其手册页中包含以下信息:
> 当驱动程序崩溃时(例如,被 SEGV 终止),
> 预期它会以高于 128 的非零状态退出,
> 在这种情况下,合并将失败(这与产生冲突不同)。

英文:

A git merge --quit will have better chance of working when a merge driver is running:

With Git 2.42 (Q3 2023), when the external merge driver is killed by a signal, its output should not be trusted as a resolution with conflicts that is proposed by the driver, but the code did.

Well done to the OP Joshua, who asked on the Git mailing list about this!

See commit 34d765e (23 Jun 2023), and commit 2b7b788 (22 Jun 2023) by Junio C Hamano (gitster).
<sup>(Merged by Junio C Hamano -- gitster -- in commit 3ea43bb, 29 Jun 2023)</sup>

> ## ll-merge: killing the external merge driver aborts the merge
> <sup>Reviewed-by: Elijah Newren</sup>

> When an external merge driver dies with a signal, we should not expect that the result left on the filesystem is in any useful state.
> However, because the current code uses the return value from run_command() and declares any positive value as a sign that the driver successfully left conflicts in the result, and because the return value from run_command() for a subprocess that died upon a signal is positive, we end up treating whatever garbage left on the filesystem as the result the merge driver wanted to leave us.
>
> run_command() returns larger than 128 (WTERMSIG(status) + 128, to be exact) when it notices that the subprocess died with a signal, so detect such a case and return LL_MERGE_ERROR from ll_ext_merge().

gitattributes now includes in its man page:
> When the driver crashes (e.g. killed by SEGV),
> it is expected to exit with non-zero status that are higher than
> 128, and in such a case, the merge results in a failure (which is
> different from producing a conflict).

huangapple
  • 本文由 发表于 2023年6月22日 04:39:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76526972.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定