{"thread":{"id":"61225","subject":"Feature request: a merge strategy that makes any file difference a merge conflict","startedAt":"2024-03-29T19:21:12Z","lastAt":"2024-04-01T11:21:42Z","messageCount":4,"participants":["Michael Ernst","Junio C Hamano","Thomas Braun"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"491845","messageId":"CAAJCdQQB3_DWOTCTbb-TAkLUX_XVd5TBd3z0M2_KrHxKxr69Kw@mail.gmail.com","threadId":"61225","inReplyTo":null,"subject":"Feature request: a merge strategy that makes any file difference a merge conflict","fromName":"Michael Ernst","fromEmail":"mernst@cs.washington.edu","sentAt":"2024-03-29T19:20:59Z","receivedAt":"2024-03-29T19:21:12Z","isPatch":false,"sender":{"key":"mernst@cs.washington.edu","avatar":null},"body":"Git's built-in merge strategies, such as ort, sometimes create a\nclean-but-incorrect merge.  A merge driver or a mergetool cannot be\nused to correct such problems, because a merge driver or mergetool is\nonly called when the strategy resulted in a conflict (so far as I\nunderstand).  It is challenging to write a merge strategy, but it is\nmuch easier to write a merge driver or a mergetool.\n\nIf git had a strategy that always caused a merge conflict (even when\nthe differences are mergeable), then a merge driver or mergetool would\nbe called on every file difference.  This effectively permits a user\nto completely replace git's merge strategy, without the difficulty of\nwriting a merge strategy.\n\nI realize that the proposed strategy would likely only create merge\nconflicts when no two of {parent1,parent2,base} are the same -- that\nis, only when the low-level merge driver `git merge-file` is called.\nThat is fine with me.\n\nWhat do you think of this feature request?\n\nThanks in advance,\n-Mike\n"},{"id":"491848","messageId":"xmqqfrw8ygg2.fsf@gitster.g","threadId":"61225","inReplyTo":"CAAJCdQQB3_DWOTCTbb-TAkLUX_XVd5TBd3z0M2_KrHxKxr69Kw@mail.gmail.com","subject":"Re: Feature request: a merge strategy that makes any file difference a merge conflict","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-03-29T19:40:45Z","receivedAt":"2024-03-29T19:40:48Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael Ernst <mernst@cs.washington.edu> writes:\n\n> Git's built-in merge strategies, such as ort, sometimes create a\n> clean-but-incorrect merge.  A merge driver or a mergetool cannot be\n> used to correct such problems, because a merge driver or mergetool is\n> only called when the strategy resulted in a conflict (so far as I\n> understand).\n\nA custom low-level merge driver is always called when selected via\nthe attribute mechansism (see how merge-ll.c:ll_merge() calls\nfind_ll_merge_driver()) and participates in a content-level 3-way\nmerge.\n\nIf you are trying to interfere with cases that a content-level 3-way\nmerge does not kick in (e.g., your side did not change anything in\nthe file since their history forked, and they modified the file; the\ntree level 3-way merge will resolve it to take their version), then\nit is true that the low-level merge driver is not invoked, but I\nsomehow get an impression from the above description that it is not\nwhat you are trying to do.\n\n> It is challenging to write a merge strategy, but it is\n> much easier to write a merge driver or a mergetool.\n\nA merge strategy is about performing three-way merge at the tree\nlevel, figuring out which three variants of contents to hand to a\nmerge driver that handles the content-level three-way merge.  They\nserve totally different purposes and comparing them is like\ncomparing apples and oranges.\n"},{"id":"491851","messageId":"CAAJCdQQceA7yANHCPzUGbANR-XKVDUzfN5ym6Rb-oEWgcq=4Uw@mail.gmail.com","threadId":"61225","inReplyTo":"xmqqfrw8ygg2.fsf@gitster.g","subject":"Re: Feature request: a merge strategy that makes any file difference a merge conflict","fromName":"Michael Ernst","fromEmail":"mernst@cs.washington.edu","sentAt":"2024-03-29T20:43:53Z","receivedAt":"2024-03-29T20:44:06Z","isPatch":false,"sender":{"key":"mernst@cs.washington.edu","avatar":null},"body":"Junio-\n\nThank you for the clarification.  There is a lot of misleading\ninformation about this on the Internet.\n\nI was mistaken about when a merge driver is called.  Now I see that\nthe merge driver is called anytime that no two of\n{base,parent1,parent2} are the same.  This means that a merge driver\n*can* prevent a clean-but-incorrect merge.  I was right that a\nmergetool cannot be used to correct a clean-but-incorrect merge.\n\n-Mike\n"},{"id":"491956","messageId":"17b55da7-42d0-48df-95a6-8433e1c028b0@virtuell-zuhause.de","threadId":"61225","inReplyTo":"CAAJCdQQB3_DWOTCTbb-TAkLUX_XVd5TBd3z0M2_KrHxKxr69Kw@mail.gmail.com","subject":"Re: Feature request: a merge strategy that makes any file difference a merge conflict","fromName":"Thomas Braun","fromEmail":"thomas.braun@virtuell-zuhause.de","sentAt":"2024-04-01T11:00:59Z","receivedAt":"2024-04-01T11:21:42Z","isPatch":false,"sender":{"key":"thomas.braun@virtuell-zuhause.de","avatar":"https://avatars.githubusercontent.com/u/1185677?v=4"},"body":"On 29.03.2024 20:20, Michael Ernst wrote:\n\n[...]\n\n> What do you think of this feature request?\n\nI wanted to propose to mark the relevant files as binary as that should \nprevent the merge to happen. But this is not working.\n\ngit init\n\necho \"*.txt binary\" > .gitattributes\ngit add .gitattributes\ngit commit -m \".gitattributes: Add it\" .gitattributes\n\necho \"a\" > test.txt\ngit add test.txt\ngit commit -m \"test.txt: main\" test.txt\n\ngit checkout -b feature\necho \"ab\" > test.txt\ngit commit -m \"test.txt: feature\" test.txt\n\ngit checkout main\ngit merge --no-ff --stat --no-edit  feature\n\nMerge made by the 'ort' strategy.\n  test.txt | Bin 22 -> 3 bytes\n  1 file changed, 0 insertions(+), 0 deletions(-)\n\ngit log -p test.txt\ncommit ec7cab2fa30c26738c6254202a399a616959a661 (feature)\nAuthor: Thomas Braun <thomas.braun@byte-physics.de>\nDate:   Mon Apr 1 12:56:07 2024 +0200\n\n     test.txt: feature\n\ndiff --git a/test.txt b/test.txt\nindex 346a56a..81bf396 100644\nBinary files a/test.txt and b/test.txt differ\n\ncommit 61e195554351dada7494e4eb4935d96120680420\nAuthor: Thomas Braun <thomas.braun@byte-physics.de>\nDate:   Mon Apr 1 12:50:29 2024 +0200\n\n     test.txt: main\n\ndiff --git a/test.txt b/test.txt\nnew file mode 100644\nindex 0000000..346a56a\nBinary files /dev/null and b/test.txt differ\n\nI would have expected to see a merge conflict as git can't know how to \nmerge binaries. Or am I misunderstanding something here?\n"}]}