Skip to content

Do not ensure HEAD is default_branch on snippets

John Cai requested to merge jc-snippets-do-not-change-head into master

What does this MR do and why?

Currently there is code to ensure that when a snippet is created, that HEAD is the default branch as configured in the application. It did this through calling gitaly's WriteRef RPC to change the ref HEAD pointed to. There was actually a bug in WriteRef that failed to do transactional voting, which we fixed.

This fix actually uncovered a bug with the way that snippets was calling it. It was doing so through a git access checker, which called WriteRef in a racy way before a call to UserCommitFiles finished. When two RPCs for the same repository that does locking are called simultaneously, the last one called will fail. This was leading to errors for snippet creation.

To fix the racy call to WriteRef, the best thing we can do is to completely remove the call. We are able to do this by modifying the CreateRepository call to pass in the default branch so that the repository is created with the default branch to begin with. This ability in Gitaly was added recently for this purpose. The change to repository.create_if_not_exists to pass in the branch name was done in !82219 (merged)

Now we can simply remove change_head_to_default_branch helper and its call sites.

related issue: #353935 (closed)

How to set up and validate locally

  1. Set default branch to something other than main: https://docs.gitlab.com/ee/user/project/repository/branches/default.html
  2. Create a new snippet
  3. Ensure the snippet is on the default branch

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 John Cai

Merge request reports

Loading