Replacing a pull mirror does not result in a change to the type of mirrored branches

Summary

Removing & recreating a mirror relationship does not change the type of mirror branches.

Steps to reproduce

  1. Create a new, blank project

  2. Add a new mirror repository (Settings > Repository > Mirroring repositories)

  3. Set the mirror to 'Pull' and ensure the 'Mirror only protected branches will be mirrored' radio button is checked:

    pull_mirror_all_protected_branches.jpg

  4. Delete the mirror, recreate it checking the 'Mirror all branches' radio button instead.

  5. Note that the label will not have changed to reflect that All branches are now mirrored, and only protected branches will continue to be mirrored.

Example Project

https://gitlab.com/tmarsh1/example-mirror-behaviour

What is the current bug behavior?

Some mild database debugging (h/t @bprescott_) suggests that the database does not get updated to reflect the updated options when this change is made via the WebUI.

What is the expected correct behavior?

Ideally - we don't need to delete the mirror to update the behaviour, but at least, recreating the mirror should result in the branch preference being updated.

Relevant logs and/or screenshots

The behaviour can be confirmed via the API:

 curl -s --request GET \
  --header "PRIVATE-TOKEN: $pat" \
  "https://gitlab.com/api/v4/projects/62895197/mirror/pull" | jq
{
  "id": 12328914,
  "update_status": "finished",
  "url": "https://github.com/gitlabhq/terraform-provider-gitlab",
  "last_error": null,
  "last_update_at": "2024-10-23T08:33:35.776Z",
  "last_update_started_at": "2024-10-23T08:33:15.353Z",
  "last_successful_update_at": "2024-10-23T08:33:35.776Z",
  "enabled": true,
  "mirror_trigger_builds": false,
  "only_mirror_protected_branches": true,
  "mirror_overwrites_diverged_branches": false,
  "mirror_branch_regex": null
}

Deleting and recreating the mirror does not result in 'only_mirror_protected_branches' being updated.

Output of checks

This bug happens on GitLab.com

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of: \\\`sudo gitlab-rake gitlab:env:info\\\`) (For installations from source run and paste the output of: \\\`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production\\\`)

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

Not a Fix, per se, but a work around - the mirror behaviour can be manipulated via the API:

curl --request PUT \
  --header "PRIVATE-TOKEN: $pat" \
  --header "Content-Type: application/json" \
  --data '{
    "mirror": true,
    "mirror_trigger_builds": true,
    "only_mirror_protected_branches": true
  }' \
  "https://gitlab.example.com/api/v4/projects/<project_id>"

Toggling only_mirror_protected_branches will result in the behaviour correctly updating.