{"thread":{"id":"61019","subject":"Bug: merge-driver not executed with ort and merge-tree","startedAt":"2024-02-27T17:04:36Z","lastAt":"2024-02-27T17:04:36Z","messageCount":1,"participants":["André Frimberger"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"489549","messageId":"FR2P281MB231375E73789D6DD5F8BECF6BC552@FR2P281MB2313.DEUP281.PROD.OUTLOOK.COM","threadId":"61019","inReplyTo":null,"subject":"Bug: merge-driver not executed with ort and merge-tree","fromName":"André Frimberger","fromEmail":"andre@frimberger.de","sentAt":"2024-02-27T17:04:33Z","receivedAt":"2024-02-27T17:04:36Z","isPatch":false,"sender":{"key":"andre@frimberger.de","avatar":null},"body":"Hi Git community,\n\nwe’re using a merge driver to automatically solve predictable merge conflicts in pom.xml files.\n\nIn our use-case Git is executed by Bitbucket. With the update of Bitbucket from 7.x to 8.x and Git from 2.23 to 2.43.2 the merge driver\nintegration breaks.\n\nBitbucket internally calls “merge-tree” on a Git repo without working directory (dirty details below). While digging down the rabbit hole we found\nthe following two bugs / inconsistencies:\n\n* The \"new\" default merge strategy ort implements its own lookup logic for the .gitattributes file and ignores HEAD:.gitattributes.\n  This behaviour is inconsistent to the default behaviour \"-s recursive\" prior to 2.34.\n* merge-tree ignores HEAD:.gitattributes.\n\n*Expected behavior:* merge-tree and “ort” respect HEAD:.gitattributes\n\n\nSteps to reproduce (aligned with the calls from Bitbucket, so please don’t blame me for the calls 😊):\nYou’ll find a demo repo and the instructions in https://github.com/afrimberger/mergedriver-test/blob/main/README.md\n\n------------------------------------------------------------------------------------------------------------------------\n```shell\n$ git --version\ngit version 2.43.2\n```\n\nClone this repo as bare repo to simulate Bitbucket's local repository storage\n\n```shell\n$ cd /tmp\n$ git clone --bare https://github.com/afrimberger/mergedriver-test.git mergedriver-test-bare\n```\n\nCopy and activate the test merge driver\n```shell\n$ cd /tmp/mergedriver-test-bare\n$ git show HEAD:custom-merge-driver.sh > /tmp/custom-merge-driver.sh\n$ chmod 777 /tmp/custom-merge-driver.sh\n$ /tmp/custom-merge-driver.sh\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\nMerge Driver is active\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n```\n\nDefine the merge driver settings in one of the \"global\" Git configs\n```shell\n$ cat <<EOF >> ~/.gitconfig\n[user]\n  name = John Doe\n  email = john@doe.com\n[merge \"keeplocalversion\"]\n  name = \"Keep local pom version\"\n  driver = /tmp/custom-merge-driver.sh\nEOF\n```\n\nCreate temporary Git repo to prevent changes in bare repo\n\n```shell\n$ mkdir /tmp/mergedriver-test\n$ cd /tmp/mergedriver-test\n$ git init\nInitialized empty Git repository in /tmp/mergedriver-test/.git/\n```\n\nReference objects from bare repo\n```shell\n$ echo \"/tmp/mergedriver-test-bare/objects\" > \".git/objects/info/alternates\"\n```\n\nThe working directory is empty\n```shell\n$ ls -al\ntotal 12\ndrwxr-xr-x 3 root root 4096 Feb 23 18:10 .\ndrwxrwxrwt 1 root root 4096 Feb 23 18:10 ..\ndrwxr-xr-x 8 root root 4096 Feb 23 18:10 .git\n```\n\nPrepare merge\n\n```shell\n$ git reset 4814fce142b95b910d0cbe87c3c304b15f279a0a –\nUnstaged changes after reset:\nD             .gitattributes\nD             .gitconfig-example\nD             custom-merge-driver.sh\nD             pom.xml\n```\n\n\nworking directory is empty, but `HEAD:.gitattributes` exists\n```shell\n$ git show HEAD:.gitattributes\n* merge=keeplocalversion\n```\n\nExecute `git merge-tree`. The merge driver isn't executed even though `HEAD:.gitattributes` exists.\n```shell\n$ git merge-tree --write-tree --allow-unrelated-histories --messages 561da86fa3990aa712aa3ec6681dfafd50def3a0 4814fce142b95b910d0cbe87c3c304b15f279a0a\n8c1c8d51a82b07712c8e64109717f615a5e4a81e\n100644 ded65fd3b11aa6a0b82f6ab170eaee5411c5ce2e 1            pom.xml\n100644 29418c82b95793ee6b688bf6761ee53d8f42c1c5 2            pom.xml\n100644 9bc48d5ca4b62d32cebf09f678148c8ef35b0820 3             pom.xml\n\nAuto-merging pom.xml\nCONFLICT (content): Merge conflict in pom.xml\n```\n\n**Expected Behaviour**: merge driver is executed\n\nProof merge driver is really active (Note: _ort_ doesn't respect `HEAD:.gitattributes`, but _recursive_ does)\n\n```shell\n$ git merge -s recursive -m \"Automatic merge\" --no-ff --no-log --allow-unrelated-histories --no-verify 561da86fa3990aa712aa3ec6681dfafd50def3a0 4814fce142b95b910d0cbe87c3c304b15f279a0a\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\nMerge Driver is active\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\nAuto-merging pom.xml\nMerge made by the 'recursive' strategy.\n```\n\nUse \"new\" default merge strategy _ort_. Changed with Git 2.34 (breaks backwards compatibility).\n_ort_ **doesn't** execute the merge driver\n\n```shell\n$ git merge -m 'Automatic merge' --no-ff --no-log --allow-unrelated-histories --no-verify 561da86fa3990aa712aa3ec6681dfafd50def3a0 4814fce142b95b910d0cbe87c3c304b15f279a0a\nAuto-merging pom.xml\nCONFLICT (content): Merge conflict in pom.xml\nAutomatic merge failed; fix conflicts and then commit the result.\n```\n------------------------------------------------------------------------------------------------------------------------\n\nKind Regards, André\n\nDiese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet.\nThis e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.\n"}]}