Skip to content

repository: Add updateHeadFromBundle in CreateRepositoryFromBundle

LI Zhennan requested to merge nanmu42/gitaly:nanmu42-update-head into master

Related Issues

Closes #4086 (closed) and replaces gitlab!80698 (closed) .

Background

CreateRepositoryFromBundle currently does not handle the importing bundle's HEAD, which may bring suprise to the user if the bundled repo's default branch(HEAD) is not main or master. This also affects "creating repo from custom template" scenario.

Add updateHeadFromBundle() to CreateRepositoryFromBundle should resolve this problem and the unit test is updated to reflect the change.

This MR is related with feature flag transactional_symbolic_ref_updates, thus #4074 (closed) , and related unit tests are updated to use the feature flag.

A Known Issue

Since updateHeadFromBundle() uses GuessHead()(its corresponding twin in git), the default branch(aka, HEAD) may not be determined correctly if:

  • the repo's default branch is not main or master
  • there are more than one branches and the HEAD shares the same commit that they points to.

The steps reproduce this problem:

  1. Download and decompress this repo
  2. Goes into this bare-typed repo and check packed-refs, we have prepare three branches sharing one commit
e63f41fe459e62e1228fcef60d7189127aeba95a refs/heads/gitaly-test-ref
e63f41fe459e62e1228fcef60d7189127aeba95a refs/heads/png-lfs
e63f41fe459e62e1228fcef60d7189127aeba95a refs/heads/ʕ•ᴥ•ʔ
  1. The HEAD is at branch png-lfs:
$ cat HEAD 
ref: refs/heads/png-lfs
  1. create a bundle of the described repo:
git bundle create ../project.bundle --all
  1. Go up the directory, use git to initialize a new repo from the bundle. Check its HEAD:
$ git version
git version 2.20.1
$ git clone project.bundle
$ cd project
$ cat .git/HEAD 
ref: refs/heads/ʕ•ᴥ•ʔ
$ git symbolic-ref HEAD
refs/heads/ʕ•ᴥ•ʔ # instead of expected refs/heads/png-lfs

Considering this known issue, a user's related satisfication before and after this MR may be following:

repo to import before after
use main/master as default branch 😃 😃
use their own default branch 😒 😃
use their own default branch and
has multiple branches shares their pointing commit
with the default branch
😒 😒

So overall we may make users happier. 🤣

Edited by Toon Claes

Merge request reports