Unable to create merge diff for pull request

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

    

Summary

On attempting to merge a pull request, the following error is received on the front-end:

Bitbucket Server could not create the merge diff for this pull request
To resolve this warning you could try to push a new commit to update the pull request, attempt to merge the pull request anyway, or ask a system administrator to review the logs. 
Read more about this warning.

Environment

  • Bitbucket Server and Data Center versions 6.0+

Diagnosis

On attempting to execute the merge, the following error message can be seen within the atlassian-bitbucket.log file:

'/usr/bin/git update-ref stash-refs/pull-requests/667/from 81df933db8964ee2d4737b1a0d80f383798e2e1f' exited with code 128 saying: fatal: update_ref failed for ref 'stash-refs/pull-requests/667/from': cannot lock ref 'stash-refs/pull-requests/667/from': Unable to create 'BITBUCKET_HOME/shared/data/repositories/116/./stash-refs/pull-requests/667/from.lock': Permission denied

Cause

On attempting to update the needed git repository files on the filesystem, the user running Bitbucket encounters a permission error because the file was created or is owned by a user other than the Bitbucket service account (likely root).

The reason for this happening is oftentimes because the Bitbucket process was previously executed as the root user or some other user with elevated permissions other than the Bitbucket service account. Then, during the time when Bitbucket was running as root, the application created git repository objects under this elevated account, making it so that these permission issues occurred when Bitbucket went back to running as the intended user and tried to edit this file.

Solution

Recursively set the owning user and group to the Bitbucket service account for the entire BITBUCKET_INSTALL and BITBUCKET_HOME directory, and set the read/write/execute permissions appropriately.

An example script to accomplish this can be found as follows:

#confirm the user currently running the Bitbucket Java process(es) (should be 'atlbitbucket' or something similar)
ps -aux | grep bitbucket

#change owning user/group to 'atlbitbucket' and set to r/w/x for only owning user and group for $BITBUCKET_INSTALL directory
chown -R atlbitbucket:atlbitbucket /path/to/bitbucket/install/directory
chmod -R og-rwx /path/to/bitbucket/install/directory

#change owning user/group to 'atlbitbucket' and set to r/w/x for only owning user and group for $BITBUCKET_HOME directory
chown -R atlbitbucket:atlbitbucket /path/to/bitbucket/home/directory
chmod -R og-rwx /path/to/bitbucket/home/directory

Last modified on Jun 29, 2021

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.