Ensure default_branch from settings is not blank
What does this MR do?
We can change the default branch for repositories at an instance level. Nevertheless, if we remove it and leave it blank, the value in the database will be stored as an empty string. In HasRepository#default_branch
(https://gitlab.com/gitlab-org/gitlab/blob/fj-disallow-empty-strings-in-default-branch/app/models/concerns/has_repository.rb#L82) we get the default branch for a repository. If it is not empty, then we get the root_ref
but, if it is, we get the default branch from the instance settings in default_branch_from_preferences
(https://gitlab.com/gitlab-org/gitlab/blob/fj-disallow-empty-strings-in-default-branch/app/models/concerns/has_repository.rb#L86).
Nevertheless, if the setting is an actual blank string, this means that the default branch will be ""
. If the repository is empty and we execute for example an repository.ls_files
with an empty string, Gitaly will return the error repository does not have a default branch
.
Therefore, we have to ensure that the default branch from the preferences is not returned as an empty string.