Fix E2E flake to ensure repo uses same default branch as project
What does this MR do and why?
See: gitlab-qa!1057 (comment 1141375267)
We can sometimes find ourselves in a position where we create a project that may end up using a default branch of main
but the usage of Git::Repository
can end up attempting to push a branch named master
.
This causes errors in the test such as https://gitlab.com/gitlab-org/gitlab-qa/-/pipelines/664430171/test_report where we are attempting to push a branch master
which does not exist.
This appears to only happen in the gitlab-org/gitlab-qa
for this specific test which is presumably caused due to the specific value for QA_DEFAULT_BRANCH
variable on that specific environment - but regardless of the value we want the test to be resilient so it doesn't fail just because a variable changed.
The command HOME="/tmp/qa-netrc-credentials/39" git push http://root@gitlab-ee-23df41d4.test/gitlab-qa-sandbox-group-4/qa-test-2022-10-12-04-57-32-1007becfbc0e34a4/repository-usage-a6bdd98be554d0c3-1bb3fd7075e4203e.git master 2>&1 failed (1) with the following output:
error: src refspec master does not match any
error: failed to push some refs to 'http://gitlab-ee-23df41d4.test/gitlab-qa-sandbox-group-4/qa-test-2022-10-12-04-57-32-1007becfbc0e34a4/repository-usage-a6bdd98be554d0c3-1bb3fd7075e4203e.git'
How to set up and validate locally
Prior to this change, we can see how various values for the QA_DEFAULT_BRANCH
impacts the test result.
With this change in place all combinations should pass.
✓ QA_DEFAULT_BRANCH='main' bundle exec bin/qa Test::Instance::All http://gdk.test:3000/ -- qa/specs/features/api/3_create/repository/storage_size_spec.rb
✓ unset QA_DEFAULT_BRANCH && bundle exec bin/qa Test::Instance::All http://gdk.test:3000/ -- qa/specs/features/api/3_create/repository/storage_size_spec.rb
✗ QA_DEFAULT_BRANCH='foobar' bundle exec bin/qa Test::Instance::All http://gdk.test:3000/ -- qa/specs/features/api/3_create/repository/storage_size_spec.rb
✗ QA_DEFAULT_BRANCH='master' bundle exec bin/qa Test::Instance::All http://gdk.test:3000/ -- qa/specs/features/api/3_create/repository/storage_size_spec.rb
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.