Check out specific branch
What does this MR do?
Check out a specific branch
Why was this MR needed?
Since we are just initializing a repository, fetch from a remote and checking out a specific commit, git no longer knows anything about the branch locally. Which causes CI job to fail if they are trying to push the branch to another remote for example for heroku deploys.
closes #4097 (closed)
Tests
Below I have ran some tests for the .gitlab-ci.yml
:
.gitlab-ci.yml
stages:
- test
test:
image: ruby:2.6
stage: test
script:
- git branch
GitLab Runner 11.9 job log
Running with gitlab-runner development version (HEAD)
on docker-local c7zJEHBv
Using Docker executor with image ruby:2.6 ...
Pulling docker image ruby:2.6 ...
Using docker image sha256:8d6721e9290e96cc34faeee7a525311a400598e7fee170190c73ce103dd621ce for ruby:2.6 ...
Running on runner-c7zJEHBv-project-28-concurrent-0 via steve-mbp-gitlab.local...
Reinitialized existing Git repository in /builds/root/ci-scratch-pad/.git/
Fetching changes...
fatal: remote origin already exists.
Clean repository
From http://192.168.1.79:3000/root/ci-scratch-pad
* [new branch] custom-project-dir -> origin/custom-project-dir
edd6281..d7a4659 dirty-repo -> origin/dirty-repo
* [new branch] git-log -> origin/git-log
Checking out 41dd3815 as git-log...
Skipping Git submodules setup
$ git branch
* (HEAD detached at 41dd381) <---- Notice how there is no branch
Job succeeded
GitLab Runner 11.8 job log
Running with gitlab-runner development version (HEAD)
on docker-local c7zJEHBv
Using Docker executor with image ruby:2.6 ...
Pulling docker image ruby:2.6 ...
Using docker image sha256:8d6721e9290e96cc34faeee7a525311a400598e7fee170190c73ce103dd621ce for ruby:2.6 ...
Running on runner-c7zJEHBv-project-28-concurrent-0 via steve-mbp-gitlab.local...
Cloning repository...
Cloning into '/builds/root/ci-scratch-pad'...
Checking out 41dd3815 as git-log...
Skipping Git submodules setup
$ git branch
* (HEAD detached at 41dd381)
master <- Notice how we have master available as a branch
Job succeeded
With this MR
Running with gitlab-runner development version (HEAD)
on docker-local c7zJEHBv
Using Docker executor with image ruby:2.6 ...
Pulling docker image ruby:2.6 ...
Using docker image sha256:8d6721e9290e96cc34faeee7a525311a400598e7fee170190c73ce103dd621ce for ruby:2.6 ...
Running on runner-c7zJEHBv-project-28-concurrent-0 via steve-mbp-gitlab.local...
Initialized empty Git repository in /builds/root/ci-scratch-pad/.git/
Fetching changes...
Created fresh repository.
From http://192.168.1.79:3000/root/ci-scratch-pad
* [new branch] cache -> origin/cache
* [new branch] custom-project-dir -> origin/custom-project-dir
* [new branch] dirty-repo -> origin/dirty-repo
* [new branch] forever-build -> origin/forever-build
* [new branch] git-log -> origin/git-log
* [new branch] master -> origin/master
* [new branch] scripts -> origin/scripts
* [new branch] services -> origin/services
* [new branch] windows-docker-executor -> origin/windows-docker-executor
Checking out 41dd3815 as git-log...
Skipping Git submodules setup
$ git branch
* git-log <- Notice how the current branch is the branch we want.
Are there points in the code the reviewer needs to double check?
Since we are not explicitly checking out a branch not sure if this breaks anything.
Does this MR meet the acceptance criteria?
-
Documentation created/updated -
Added tests for this feature/bug -
In case of conflicts with master
- branch was rebased
What are the relevant issue numbers?
Closes #4097 (closed)