Pipeline Association missing with Merge Requests for Shared Commit SHAs
Summary
Pipelines can fail to associate with merge requests (MRs) when a commit exists in multiple branches, leading to these pipelines not being displayed in the MR's Pipelines tab. This issue arises from shared commit SHAs across different branches while merging.
Steps to reproduce
Setup
- Create a project, initialize with README.md for intial commit
- Clone locally, create a branch, make some changes, add and commit
- Checkout main branch, merge the new branch
- Create another branch from main
- Push both to GitLab
$ git switch feature-branch
Switched to branch 'feature-branch'
$ vim README.md
$ git add .
$ git commit -m "Add feature"
[feature-branch 0154598] Add feature
1 file changed, 1 insertion(+), 93 deletions(-)
rewrite README.md (100%)
$ git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
$ git merge feature-branch
Updating c5cbc4f..0154598
Fast-forward
README.md | 94 +-----------------------------------------------------------------------------------
1 file changed, 1 insertion(+), 93 deletions(-)
$ git checkout -b another-branch
Switched to a new branch 'another-branch'
$ git push origin feature-branch
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 20 threads
Compressing objects: 100% (1/1), done.
Writing objects: 100% (3/3), 269 bytes | 269.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: To create a merge request for feature-branch, visit:
remote: https://gitlab.com/edwardhilgendorf_ultimate_group/pipelines-shared-commit-sha/-/merge_requests/new?merge_request%5Bsource_branch%5D=feature-branch
remote:
To gitlab.com:edwardhilgendorf_ultimate_group/pipelines-shared-commit-sha.git
* [new branch] feature-branch -> feature-branch
$ git push origin another-branch
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: To create a merge request for another-branch, visit:
remote: https://gitlab.com/edwardhilgendorf_ultimate_group/pipelines-shared-commit-sha/-/merge_requests/new?merge_request%5Bsource_branch%5D=another-branch
remote:
To gitlab.com:edwardhilgendorf_ultimate_group/pipelines-shared-commit-sha.git
* [new branch] another-branch -> another-branch
This results in two branches with the same commit SHA
Create Merge Requests in GitLab
Create a MR for feature-branch
and another-branch
, noting these have the same commit SHA: 01545984
Set the commit status via API
curl --request POST --header "PRIVATE-TOKEN: glpat-SECRET" "https://gitlab.com/api/v4/projects/52141316/statuses/015459842a09384bbb5634cb47398885b06b3e8e?state=success"
Compare MR tab
Only merge request 4
shows the commit status, despite the SHA commit being the same for both MRs
What is the current bug behavior?
Only one merge request gets associated with the pipeline
What is the expected correct behavior?
An error or warning about several matching source branches
Possible fixes
Add a warning when multiple source branches match a commit SHA
Edited by Edward Hilgendorf