MR may remain opened if pushed from command line
Summary
When pushing a rebased branch and the target branch very closely (or with the same command), the MR may remain opened
Steps to reproduce
- Create a new project
- Push some commit(s) on its
master
branch - Push some commit(s) on a divergent
topic
branch - Create a Merge Request from
topic
tomaster
- Rebase the
topic
branch onto themaster
branch
git rebase master topic
- Fast-forward
master
totopic
git checkout master
git merge --ff-only topic
- Push both branches at the same time
git push -f origin master topic
The same behavior may be observed if you push both branches separately but fast enough, like git push -f origin topic && git push origin master
on a local network. However, it is more rare than if they are pushed using a single command.
Example Project
The attached script reproduces the problem by creating a new project, creating a MR and pushing things to it. However, you need to provide your token key, username and password to the script (pro-tip: use it on a dedicated docker image!)
What is the current bug behavior?
The MR usually (but not always) remains opened more than 30s after the double push.
What is the expected correct behavior?
The MR should always become merged after a few seconds (less than 5), just like it usually does if we push the branches separately.
Relevant logs and/or screenshots
get https://gitlab.com/api/v4/projects {'private-token': 'XXX'} {}
post https://gitlab.com/api/v4/projects {'private-token': 'XXX'} {'json': {'name': 'test_project'}}
+ git init /tmp/tmpoyelg6of
Initialized empty Git repository in /tmp/tmpoyelg6of/.git/
+ cd /tmp/tmpoyelg6of
+ git config --local user.name 'Paul Morelle'
+ git config --local user.email paul.morelle@octobus.net
+ git -C /tmp/tmpoyelg6of remote add origin https://gitlab.com/madprog/test_project.git
+ cd /tmp/tmpoyelg6of
+ echo 'A lion is stronger than a kitten'
+ git add kitten
+ git commit -m 'Initial sentence'
[master (root-commit) 27791eb] Initial sentence
1 file changed, 1 insertion(+)
create mode 100644 kitten
+ git branch topic
+ echo 'A lion is stronger than a horse'
+ git add horse
+ git commit -m 'Even a horse!'
[master 9a13b0f] Even a horse!
1 file changed, 1 insertion(+)
create mode 100644 horse
+ git push origin -u master
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (6/6), 481 bytes | 240.00 KiB/s, done.
Total 6 (delta 1), reused 0 (delta 0)
To https://gitlab.com/madprog/test_project.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
+ git checkout topic
Switched to branch 'topic'
+ echo 'A lion is stronger than an antelope'
+ git add antelope
+ git commit -m 'Even an antelope!'
[topic 1848210] Even an antelope!
1 file changed, 1 insertion(+)
create mode 100644 antelope
+ git push origin -u topic
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 313 bytes | 313.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: To create a merge request for topic, visit:
remote: https://gitlab.com/madprog/test_project/merge_requests/new?merge_request%5Bsource_branch%5D=topic
remote:
To https://gitlab.com/madprog/test_project.git
* [new branch] topic -> topic
Branch 'topic' set up to track remote branch 'topic' from 'origin'.
post https://gitlab.com/api/v4/projects/10042324/merge_requests {'private-token': 'XXX'} {'json': {'id': 10042324, 'source_branch': 'topic', 'target_branch': 'master', 'title': 'Test Merge Request'}}
+ cd /tmp/tmpoyelg6of
+ git rebase master topic
First, rewinding head to replay your work on top of it...
Applying: Even an antelope!
+ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
+ git merge --ff-only topic
Updating 9a13b0f..03f3a78
Fast-forward
antelope | 1 +
1 file changed, 1 insertion(+)
create mode 100644 antelope
+ git push -f origin master topic
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 346 bytes | 346.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: View merge request for topic:
remote: https://gitlab.com/madprog/test_project/merge_requests/1
remote:
To https://gitlab.com/madprog/test_project.git
9a13b0f..03f3a78 master -> master
+ 1848210...03f3a78 topic -> topic (forced update)
get https://gitlab.com/api/v4/projects/10042324/merge_requests/1 {'private-token': 'XXX'} {}
[7.062984943389893] mr.state: 'opened'
get https://gitlab.com/api/v4/projects/10042324/merge_requests/1 {'private-token': 'XXX'} {}
[14.06041169166565] mr.state: 'opened'
get https://gitlab.com/api/v4/projects/10042324/merge_requests/1 {'private-token': 'XXX'} {}
[19.145711660385132] mr.state: 'opened'
get https://gitlab.com/api/v4/projects/10042324/merge_requests/1 {'private-token': 'XXX'} {}
[24.163811206817627] mr.state: 'opened'
get https://gitlab.com/api/v4/projects/10042324/merge_requests/1 {'private-token': 'XXX'} {}
[29.155690670013428] mr.state: 'opened'
get https://gitlab.com/api/v4/projects/10042324/merge_requests/1 {'private-token': 'XXX'} {}
[34.193565368652344] mr.state: 'opened'
delete https://gitlab.com/api/v4/projects/10042324 {'private-token': 'XXX'} {}
get https://gitlab.com/api/v4/projects/10042324 {'private-token': 'XXX'} {}
Traceback (most recent call last):
File "./test_gitlab_rebase_push", line 183, in <module>
assert mr['state'] == 'merged'
AssertionError
Output of checks
This bug happens on GitLab.com
Results of GitLab environment info
Expand for output related to GitLab environment info
> bundle exec rake gitlab:env:info RAILS_ENV=developmentSystem information System: Debian 9.5 Current User: git Using RVM: yes RVM Version: 1.29.4 Ruby Version: 2.5.3p105 Gem Version: 2.7.8 Bundler Version:1.17.2 Rake Version: 12.3.1 Redis Version: 3.2.6 Git Version: 2.11.0 Sidekiq Version:5.2.3 Go Version: go1.11.1 linux/amd64
GitLab information Version: 11.6.0-pre Revision: 7c4940b702 Directory: /home/git/gitlab-development-kit/gitlab DB Adapter: postgresql URL: http://localhost:3000 HTTP Clone URL: http://localhost:3000/some-group/some-project.git SSH Clone URL: ssh://git@localhost:2222/some-group/some-project.git Using LDAP: no Using Omniauth: yes Omniauth Providers:
GitLab Shell Version: 8.4.3 Repository storage paths:
- default: /home/git/gitlab-development-kit/repositories Hooks: /home/git/gitlab-development-kit/gitlab-shell/hooks Git: /usr/bin/git
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true
)(we will only investigate if the tests are passing)
Possible fixes
(If you can, link to the line of code that might be responsible for the problem)