Stash always shows incorrect Merge Conflict in PRs
問題
When a user tries to merge a pull request when Stash is hosted on Windows, they see one of:
- The Merge button is deactivated and the warning "This pull request can't be merged" is visible, but the pull request's diff page does not show conflicts.
- The Merge button is deactivated, the warning "This pull request can't be merged" is visible and the pull request's diff page does not show files with long paths.
原因
Cause #1:
Since Stash uses Git to check out files when performing the merge in a pull request they can can fail on Windows because Windows applies an absolute limit to the length (260 characters) of a directory's path. Contributing factors include files in the pull request that:
- Are located in deeply nested directories (or
STASH_HOME
is deeply nested). - Have long file names.
Cause #2:
The disk where STASH_HOME
is mounted is full. Stash needs to doing some testing to check for merge conflicts and to do that we clone out the repository. If we can't clone the repository (due to disk space) then this could cause an error and the merge conflict that that is displayed.
Cause #3
STASH_HOME
is a defined as a UNC (\\network\path\here) path.
Cause #4
Root cause is unknown but this tends to occur with older versions of Bitbucket Server and/or git (server side). Git processes are prematurely killed and thus are unable to clean-up .lock
files on the server side repository so subsequent git operations fail. The following error is logged to atlassian-bitbucket.log:
2015-09-25 00:47:13,869 INFO [drift:thread-2] c.a.s.i.s.g.p.DefaultPullRequestAutoMergeStrategy atlas/charlie[23]: Pull request 1666@173 failed automatic merging: '/usr/bin/git fetch /stash/home/tmp/git/repo691390098980685340.git +HEAD:' exited with code 0 saying: From /stash/home/tmp/git/aim-work691390098980685340
* branch HEAD -> FETCH_HEAD
Auto packing the repository for optimum performance. You may also
run "git gc" manually. See "git help gc" for more information.
fatal: Unable to create '/stash/home/shared/data/repositories/23/refs/heads/test.lock': File exists.
If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.
error: failed to run reflog
回避策
原因 #1
Because this problem arises from Windows APIs used by Git, there is no fix. Possible workarounds:
- Change the location of the
<Stash home directory>
to reduce the length of the directory path forSTASH_HOME
- Restructuring the Git repository so that the files in the pull request have shorter directory paths.
- Migrate Stash to a different server running Linux.
There is a feature request open in Stash that you may watch/vote for.
原因 #2
- Free up disk space.
For Cause #3
- Map a network drive or use the mklink command to create a symbolic link to the networked location and update
STASH_HOME
to reference the new drive letter/path.
For Cause #4
Ideally, you should upgrade to the latest version of both applications. To resolve this once it has occurred you have to manually delete the lock files from the file system. The path in the error that is logged identifies where these lock files are located so from the example log file above you would delete /stash/home/shared/data/repositories/23/refs/heads/test.lock
where "23" is the location of the repo on disk.