DefaultBranchName returns an arbitrary branch if HEAD points to a non-existing branch
A Geo customer ran into an issue where the RPC for retrieving the default branch was incorrectly returning the wrong branch name. The sequence of events that led to this:
- The Geo primary had a default branch of
v1.0
. - On the Geo secondary, a new project was created with a default
HEAD
pointing torefs/heads/master
. - The Geo secondary issued a
FetchRemote
for the primary project, removing the branchmaster
. - The Geo secondary sent a
DefaultBranchName
request and got backv1.0
, even thoughHEAD
pointed to a non-existentrefs/heads/master
.
Step 4 happens because in https://gitlab.com/gitlab-org/gitaly/blob/55c8f124608b22288b2fee99ec8295d3fd980e12/internal/service/ref/refs.go#L160, DefaultBranchName
will always return the first branch if there is only one.
This is confusing behavior because it doesn't match with what HEAD
reports.
We may want another RPC that will returns the branch pointed by HEAD
or fails if it doesn't exist.
Edited by Stan Hu