Manually merged MR being updated to Closed instead of Merged
Summary
Manually merging MRs on the command line generally works. We have an external automation rebasing and pushing MR branches, then merging them to the target branch, then finally deleting the MR branch. That gives us a linear history while letting GitLab realize that the new commits on the target branch are coming from a given MR. Unfortunately it failed once. I noticed that the e-mails about the rebased commits being pushed arrived later than the e-mail about the MR being closed. My hypothesis is that the MR branch deletion event was processed before the event for the rebased commits being pushed.
Steps to reproduce
In a quick succession, perhaps with some parallel load on GitLab:
git checkout <mr_branch> # checkout MR branch to be rebased
git fetch # Fetch data from the remote, make sure the target branch is up todate
git rebase origin/<target_branch> # Rebase MR branch over the target to get a FF merge and linear history
git push --force-with-lease # Sync the rebased branch with GitLab, so it can see that the next push is actually a merge
git push origin HEAD:origin/<target_branch> # Push commits to target directly, completing a FF merge
git push -d origin <mr_branch> # Cleanup MR branch after successful merge. If push failed, try rebasing/push/merge again.What is the current bug behavior?
MR is marked as Closed.
What is the expected correct behavior?
MR is marked as Merged.
Relevant logs and/or screenshots
I could paste some screenshots of the e-mail notifications, but I don't think it will be relevant. As GitLab didn't see the merge coming in, it will be hard to match timestamps assertively. I can see that the commit is on <target_branch>, the one listed by GitLab, but it still marked the MR as closed.
Automation logs doing the Git operations:
15:02:15 [Pipeline] {
15:02:15 [Pipeline] echo
15:02:15 [gitPush] Attempt #1
15:02:15 [Pipeline] sh (Check if source branch exists)
15:02:15 + git ls-remote --heads --quiet --exit-code <repo> refs/heads/<mr_branch>
15:02:16 2f1e1368d0ce217870010d2d255721f485833270 refs/heads/<mr_branch>
15:02:16 [Pipeline] sh ([gitPush] Rebase)
15:02:16 + git pull --rebase origin +refs/heads/master:refs/remotes/origin/master
15:02:18 First, rewinding head to replay your work on top of it...
15:02:18 Applying: <commit_title>
15:02:18 [Pipeline] sh ([gitPush] Push rebased branch)
15:02:19 + git push --force origin <mr_branch>
15:02:20 remote: # <automation_user> pushing branch <mr_branch> (update) to <repo>
15:02:24 To <gitlab_host>:<repo>.git
15:02:24 + 2f1e1368d0ce...b34fbf0a7f17 <mr_branch> -> <mr_branch> (forced update)
15:02:24 [Pipeline] sh ([gitPush] Get current commit hash)
15:02:24 + git rev-parse HEAD
15:02:24 [Pipeline] sh ([gitPush] Get previous commit hash)
15:02:25 + git rev-parse origin/master
15:02:25 [Pipeline] sh ([gitPush] Get pushed commits count)
15:02:25 + git rev-list --count --no-merges 159d55261de93813c43db25e75951ab46a4e2505...b34fbf0a7f1766637bc7b203394ae6dc3ef68ca7
15:02:25 [Pipeline] sh ([gitPush] Diff)
15:02:25 + git diff --stat origin/master HEAD
15:02:25 <some_file> | 2 +-
15:02:25 1 file changed, 1 insertion(+), 1 deletion(-)
15:02:25 [Pipeline] sh ([gitPush] Push)
15:02:26 + git push origin HEAD:master
15:02:26 To <gitlab_host>:<repo>.git
15:02:26 ! [rejected] HEAD -> master (fetch first)
15:02:26 error: failed to push some refs to '<repo>'
15:02:26 hint: Updates were rejected because the remote contains work that you do
15:02:26 hint: not have locally. This is usually caused by another repository pushing
15:02:26 hint: to the same ref. You may want to first integrate the remote changes
15:02:26 hint: (e.g., 'git pull ...') before pushing again.
15:02:26 hint: See the 'Note about fast-forwards' in 'git push --help' for details.
15:02:26 [Pipeline] echo
15:02:26 [gitPush] Failed
15:02:26 [Pipeline] echo
15:02:26 [gitPush] Attempt #2
15:02:26 [Pipeline] sh (Check if source branch exists)
15:02:26 + git ls-remote --heads --quiet --exit-code <repo> refs/heads/<mr_branch>
15:02:27 b34fbf0a7f1766637bc7b203394ae6dc3ef68ca7 refs/heads/<mr_branch>
15:02:27 [Pipeline] sh ([gitPush] Rebase)
15:02:27 + git pull --rebase origin +refs/heads/master:refs/remotes/origin/master
15:02:29 From <gitlab_host>:<repo>
15:02:29 159d55261de9..a1ef483fff44 master -> origin/master
15:02:29 First, rewinding head to replay your work on top of it...
15:02:29 Applying: <commit_title>
15:02:29 [Pipeline] sh ([gitPush] Push rebased branch)
15:02:30 + git push --force origin <mr_branch>
15:02:32 remote: # <automation_user> pushing branch <mr_branch> (update) to <repo>
15:02:35 To <gitlab_host>:<repo>.git
15:02:35 + b34fbf0a7f17...d1a198c63bdb <mr_branch> -> <mr_branch> (forced update)
15:02:35 [Pipeline] sh ([gitPush] Get current commit hash)
15:02:35 + git rev-parse HEAD
15:02:35 [Pipeline] sh ([gitPush] Get previous commit hash)
15:02:36 + git rev-parse origin/master
15:02:36 [Pipeline] sh ([gitPush] Get pushed commits count)
15:02:36 + git rev-list --count --no-merges a1ef483fff447717f9e6c2a84ed7ff2e9c22e294...d1a198c63bdb0650be9147ca08bd0951b4e2ef79
15:02:36 [Pipeline] sh ([gitPush] Diff)
15:02:37 + git diff --stat origin/master HEAD
15:02:37 <some_file> | 2 +-
15:02:37 1 file changed, 1 insertion(+), 1 deletion(-)
15:02:37 [Pipeline] sh ([gitPush] Push)
15:02:37 + git push origin HEAD:master
15:02:39 remote: # <automation_user> pushing branch master (update) to <repo>
15:02:39 To <gitlab_host>:<repo>.git
15:02:39 a1ef483fff44..d1a198c63bdb HEAD -> master
15:02:39 [Pipeline] echo
15:02:39 [gitPush] Success (d1a198c63bdb0650be9147ca08bd0951b4e2ef79)
15:02:39 [Pipeline] sh ([gitPush] Delete branch)
15:02:40 + git push --delete origin <mr_branch>
15:02:40 remote: # <automation_user> pushing branch <mr_branch> (delete) to <repo>
15:02:41 To <gitlab_host>:<repo>.git
15:02:41 - [deleted] <mr_branch>I don't have direct access to GitLab logs but they can be acquired. Please let me know which logs are useful.
Output of checks
Results of GitLab environment info
On-premises GitLab running version GitLab Enterprise Edition 14.3.0-ee