gitbitbucketbitbucket-server

Git Custom Merge Driver isn't executed anymore by Bitbucket Server 8 / Git 2.39


We updated our Bitbucket Server from 7.21.X to 8.9.10 and the underlying Git from 2.23 to 2.39.

Since then the Custom Merge Driver isn't started anymore.

I couldn't find anything in the Release Notes of Bitbucket or Git that would explain the missing execution of the Merge Driver.

The global .gitconfig:

[merge "keeplocalversion"]
    name = "Keep local version"
    driver = /path/to/mergedriver.sh %A %B %O %P

The .gitattributes from the repo:

* merge=keeplocalversion

Solution

  • Deep dive:

    What is Bitbucket doing on a pull request?

    1. It initializes a completely empty temp repository

    2. It adds a ".git/objects/info/alternates" containing a file system link to the original repository

    3. Doing a reset mixed to the source hash of the pull request (git reset --quiet --)

    4. Doing a merge tree (git merge-tree --write-tree --allow-unrelated-histories --messages

    The problem here is: This merge is completely happening without any contents in the workdir!

    That was not a problem prior to Git v2.34 but in this version Git changed it's default merge strategy from "recursive" to "ort" (Ostensibly Recursive’s Twin).

    The main difference for this issue is how recursive and ort are evaluating the .gitattributes. While recursive is reading .gitattributes from index ort is expecting the .gitattributes to be in the working directory.

    For a "git merge" it's possible to enforce the merge strategy by either setting "-s recursive" on the command or to set an environment variable, for ort there doesn't seem to be an option to fall back.

    So it's Git 2.34 that broke compatibility.