Skip to content

Ensure update_project_templates always initializes with master

Brian Williams requested to merge bwill/fix-update-templates-rake-task into master

What does this MR do and why?

Describe in detail what your merge request does and why.

Currently, the update_project_templates rake task does a bare git init and then attempts to push to master. This task will not work if the git config has init.defaultbranch set to something other than master. For example, with init.defaultbranch set to main, running the tasks fails with the following backtrace:

$ bundle exec rake gitlab:update_project_templates\[cluster_management\]
Creating temporary namespace tmp-project-import-1651850040
Creating project for GitLab Cluster Management
Destroying temporary namespace tmp-project-import-1651850040
rake aborted!
Gitlab::TaskFailedError: error: src refspec master does not match any
error: failed to push some refs to 'file:///Users/bwilliams/gitlab-development-kit/repositories/@hashed/49/d1/49d180ecf56132819571bf39d9b7b342522a2ac6d23c1418d3338251bfe469c8.git'
/Users/bwilliams/gitlab-development-kit/gitlab/lib/gitlab/task_helpers.rb:112:in `run_command!'
/Users/bwilliams/gitlab-development-kit/gitlab/lib/tasks/gitlab/update_templates.rake:90:in `block (6 levels) in <main>'
/Users/bwilliams/gitlab-development-kit/gitlab/lib/tasks/gitlab/update_templates.rake:81:in `chdir'
/Users/bwilliams/gitlab-development-kit/gitlab/lib/tasks/gitlab/update_templates.rake:81:in `block (5 levels) in <main>'
/Users/bwilliams/gitlab-development-kit/gitlab/lib/tasks/gitlab/update_templates.rake:77:in `chdir'
/Users/bwilliams/gitlab-development-kit/gitlab/lib/tasks/gitlab/update_templates.rake:77:in `block (4 levels) in <main>'
/Users/bwilliams/gitlab-development-kit/gitlab/lib/tasks/gitlab/update_templates.rake:76:in `block (3 levels) in <main>'
/Users/bwilliams/gitlab-development-kit/gitlab/lib/tasks/gitlab/update_templates.rake:43:in `each'
/Users/bwilliams/gitlab-development-kit/gitlab/lib/tasks/gitlab/update_templates.rake:43:in `block (2 levels) in <main>'
/Users/bwilliams/.asdf/installs/ruby/2.7.5/bin/bundle:23:in `load'
/Users/bwilliams/.asdf/installs/ruby/2.7.5/bin/bundle:23:in `<main>'
Tasks: TOP => gitlab:update_project_templates
(See full trace by running task with --trace)

The default branch name is also subject to change in the future.

This MR initializes the repository with --initial-branch=master so that any git configurations will be overridden. #350659 (closed) also exists to ensure that templates are updated to respect the default branch setting configured on the GitLab instance.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. git config --global init.defaultbranch main
  2. bundle exec rake gitlab:update_project_templates\[cluster_management\]
  3. Task should succeed

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Brian Williams

Merge request reports