diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2021-03-17 16:27:38 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2021-03-17 17:04:43 +0300 |
commit | d30f1cbe7454055f53a2cdd725a6a8a3706f7abd (patch) | |
tree | a10a9e80cf296acc78099cb69d78c9b7d8ffd181 | |
parent | 891fd3074e37864b46fe8e48c8f715edea687d82 (diff) |
repository: Explicitly set the default branch
With Git soon changing their default branch GitLab might be caught
off-guard as we're not setting anything explicit. Neither is it in
Gitaly's control right now.
This change sets the default branch explicitly to later be able to
change it when required.
-rw-r--r-- | internal/git/repository.go | 5 | ||||
-rw-r--r-- | internal/gitaly/service/repository/create.go | 1 | ||||
-rw-r--r-- | internal/gitaly/service/repository/create_test.go | 8 |
3 files changed, 13 insertions, 1 deletions
diff --git a/internal/git/repository.go b/internal/git/repository.go index 27fc4fc84..6eb2655b8 100644 --- a/internal/git/repository.go +++ b/internal/git/repository.go @@ -5,9 +5,12 @@ import ( "errors" ) +// DefaultBranch now defaults to master, as that's the Git default +const DefaultBranch = "master" + // DefaultRef is the reference that GitLab will use if HEAD of the bare repository // is not found, or other edge cases to detect the default branch. -var DefaultRef = []byte("refs/heads/master") +var DefaultRef = []byte("refs/heads/" + DefaultBranch) var ( // ErrReferenceNotFound represents an error when a reference was not diff --git a/internal/gitaly/service/repository/create.go b/internal/gitaly/service/repository/create.go index 59ff6aabf..198e0710d 100644 --- a/internal/gitaly/service/repository/create.go +++ b/internal/gitaly/service/repository/create.go @@ -27,6 +27,7 @@ func (s *server) CreateRepository(ctx context.Context, req *gitalypb.CreateRepos Flags: []git.Option{ git.Flag{Name: "--bare"}, git.Flag{Name: "--quiet"}, + git.ValueFlag{"--initial-branch", git.DefaultBranch}, }, Args: []string{diskPath}, }, diff --git a/internal/gitaly/service/repository/create_test.go b/internal/gitaly/service/repository/create_test.go index c710d36b8..c7aac2747 100644 --- a/internal/gitaly/service/repository/create_test.go +++ b/internal/gitaly/service/repository/create_test.go @@ -2,13 +2,16 @@ package repository import ( "fmt" + "io/ioutil" "os" + "path" "path/filepath" "strings" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" @@ -48,6 +51,11 @@ func TestCreateRepositorySuccess(t *testing.T) { require.NoError(t, err) require.True(t, fi.IsDir(), "%q must be a directory", fi.Name()) } + + symRef, err := ioutil.ReadFile(path.Join(repoDir, "HEAD")) + require.NoError(t, err) + + require.Equal(t, symRef, []byte(fmt.Sprintf("ref: %s\n", git.DefaultRef))) } func TestCreateRepositoryFailure(t *testing.T) { |