Improve new branches discovering in the PostReceive
Today I've pushed a branch and I've created the Merge Request using the URL printed on git's output. But when the MR was created I've found that a proper diff is showed, but:
- there is no pipeline for my branch,
- the MR widget says
source branch does not exist. Please restore it or use a different source branch.
What was even more strange, the branch was listed on the branches page and I could preview the commits pushed with the branch.
After investigating this with @stanhu we've found, that the branch was not reported in
PostReceive worker logs with a
When Stan mentioned this, I've remembered that in fact I've interrupted the push at the beginning. After writing
git push and hitting enter, I quickly remembered that I wanted to add one more change. So I pushed
ctrl+c which interrupted the git command:
$ git push -u origin use-codequality-report Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 8 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 797 bytes | 797.00 KiB/s, done. Total 3 (delta 2), reused 0 (delta 0) ^C
I've added required changes, and pushed it again a few minutes later, this time properly:
$ git push -u origin use-codequality-report Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 8 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 741 bytes | 741.00 KiB/s, done. Total 3 (delta 2), reused 0 (delta 0) remote: remote: To create a merge request for use-codequality-report, visit: remote: https://gitlab.com/gitlab-org/gitlab-runner/merge_requests/new?merge_request%5Bsource_branch%5D=use-codequality-report remote: To gitlab.com:gitlab-org/gitlab-runner.git ba2a13f7..75abfb6a use-codequality-report -> use-codequality-report Branch 'use-codequality-report' set up to track remote branch 'use-codequality-report' from 'origin'.
After this I've used the printed URL to open a new Merge Request form. In the logs however, the first entry that mentions my branch is only the second push, and it's logged as:
"args": [ "project-250833", "key-424958", "ba2a13f7cf62c8645797b3c3e6f806315f7cbc32 75abfb6a3467fbc1642226393066da3a4e4e0fcb refs/heads/use-codequality-report\n", "" ],
It looks like my interrupted push already created an entry in the repository, but was unnoticed by GitLab. When I next pushed new changes, the repository found an existing branch and reported a proper previous SHA. And this was enough to not invalidate the cached
branch_names list. The branch became visible after another MR was merged and, probably, the branch delete operation cleaned the cache.
As @stanhu mentioned in our slack conversation:
right, I think we should create an issue for this case
that would probably solve a number of people's mysterious missing source branch issue
we should be more robust and not rely on seeing the