Uploaded image for project: 'Bitbucket Data Center'
  1. Bitbucket Data Center
  2. BSERV-19791

Merging the pull request from the fork repository to the main repository results in the repository corruption

XMLWordPrintable

      Issue Summary

      Starting Bitbucket version 8.18 , the pull requests are merged using git merge-tree command as implemented by BSERV_14066 . On merging the pull request from fork repository to main repository, if the result of a git merge-tree yields a tree object that already exists on a different branch in the source repo, then git merge-tree will not create that tree object in the target repo. This results in the target repo corruption

      This is reproducible on Data Center: yes

      Steps to Reproduce

      Step 1. Create origin repository, put this content into file testdirectory/file.txt on the main branch:

      remove
      
      change 1
      
      change 2

      Step 2. Fork the repository

      Step 3. On the origin repository, edit the testdirectory/file.txt and add a "change 3" line at the bottom:

      remove
      
      change 1
      
      change 2
      
      change 3

      Step 4. On the fork, edit the testdirectory/file.txt and remove the "remove" line (note, this file should NOT have the "change 3" line as we forked the repository after we created the additional commit on step 3):

      change 1
      
      change 2

      Step 5. On the fork, create a new branch "testbranch" and edit the testdirectory/file.txt to match what will be on the main branch of the origin repository once we merge fork/main -> origin/main:

      change 1
      
      change 2
      
      change 3

      This is the main problem - the fork, in a different branch, now has a tree object that matches what will be on the origin once the pull request is merged.

      Step 6. Create a PR for fork/main -> origin/main, the diff will just show the removal of the "remove" line, but not show "change 3" - this is because we don't do 3 way diffs anymore.

      Step 7.  Merge the PR - here is where git merge-tree performs the merge and the result of testdirectory/file.txt matches exactly what's already in the fork on "testbranch". This is because we setup git merge-tree to have the fork as an alternate, it already has access to that tree object and therefore doesn't create it in the target. We do fetch all objects from the source branch of the merge (fork/main ), however, since that branch actually does not have that object, it won't be fetched.

      This results in a new merge commit in the origin that references a tree object that only exists in the fork and not in the origin.

      Expected Results

      The target repository should not be corrupted

      Actual Results

      The target repository gets corrupted. When trying to make updates in the repository following exception is thrown in the atlassian-bitbucket.log file:

      com.atlassian.bitbucket.scm.ProcessFailedException: 'git http-backend <repository-id> exited with code 1 saying: error: git upload-pack: git-pack-objects died with error.
      fatal: git upload-pack: aborting due to possible repository corruption on the remote side.
        

      Workaround

      Disable the git merge-tree functionality

      • Stop the Bitbucket application
      • Update the configuration file mesh.properties located in  BITBUCKET_HOME/mesh/mesh.properties and add following property. This property disables merge-tree strategy and use git merge for the pull request merge 
        merge.merge-tree=false
      • Start the Bitbucket application

              wkritzinger Wolfgang Kritzinger
              57730852f533 Jaya Mantri
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

                Created:
                Updated:
                Resolved: