diff options
author | James Fargher <jfargher@gitlab.com> | 2023-03-08 23:19:47 +0300 |
---|---|---|
committer | James Fargher <jfargher@gitlab.com> | 2023-03-08 23:43:20 +0300 |
commit | 806e9b7cdb943d3f6397244659d737c8a2d4f760 (patch) | |
tree | 731e7a409bec166cc8536b3ab4a2d4e7bd1fa1e3 | |
parent | 659bff3b53d7b9a6894ac9404edbc45d02b49497 (diff) |
gittest: Use the actual gitaly default branch when creating repositoriesalways_set_default_branch
GetDefaultBranch prefers returing main over master. So setting the
default branch to master in tests leads to discrepancies.
-rw-r--r-- | internal/git/gittest/command.go | 2 | ||||
-rw-r--r-- | internal/git/gittest/repo.go | 1 | ||||
-rw-r--r-- | internal/git/housekeeping/worktrees_test.go | 4 | ||||
-rw-r--r-- | internal/git/objectpool/create_test.go | 8 | ||||
-rw-r--r-- | internal/git/quarantine/quarantine_test.go | 3 | ||||
-rw-r--r-- | internal/git/stats/http_push_test.go | 6 |
6 files changed, 13 insertions, 11 deletions
diff --git a/internal/git/gittest/command.go b/internal/git/gittest/command.go index f39e1c1c1..e26878ee4 100644 --- a/internal/git/gittest/command.go +++ b/internal/git/gittest/command.go @@ -80,7 +80,7 @@ func createCommand(tb testing.TB, cfg config.Cfg, execCfg ExecConfig, args ...st gitConfig, err := factory.GlobalConfiguration(ctx) require.NoError(tb, err) gitConfig = append(gitConfig, - git.ConfigPair{Key: "init.defaultBranch", Value: "master"}, + git.ConfigPair{Key: "init.defaultBranch", Value: git.DefaultBranch}, git.ConfigPair{Key: "init.templateDir", Value: ""}, git.ConfigPair{Key: "user.name", Value: "Your Name"}, git.ConfigPair{Key: "user.email", Value: "you@example.com"}, diff --git a/internal/git/gittest/repo.go b/internal/git/gittest/repo.go index 208d189f8..ae2c609e3 100644 --- a/internal/git/gittest/repo.go +++ b/internal/git/gittest/repo.go @@ -324,6 +324,7 @@ func AddWorktreeArgs(repoPath, worktreeName string) []string { // AddWorktree creates a worktree in the repository path for tests func AddWorktree(tb testing.TB, cfg config.Cfg, repoPath string, worktreeName string) { + tb.Helper() Exec(tb, cfg, AddWorktreeArgs(repoPath, worktreeName)...) } diff --git a/internal/git/housekeeping/worktrees_test.go b/internal/git/housekeeping/worktrees_test.go index b6374fd54..eccc3cd1c 100644 --- a/internal/git/housekeeping/worktrees_test.go +++ b/internal/git/housekeeping/worktrees_test.go @@ -24,7 +24,7 @@ func TestCleanupDisconnectedWorktrees_doesNothingWithoutWorktrees(t *testing.T) repoProto, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{ SkipCreationViaService: true, }) - gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("master")) + gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch(git.DefaultBranch)) worktreePath := filepath.Join(testhelper.TempDir(t), "worktree") failingGitCmdFactory := gittest.NewInterceptingCommandFactory(t, ctx, cfg, func(git.ExecutionEnvironment) string { @@ -56,7 +56,7 @@ func TestRemoveWorktree(t *testing.T) { repoProto, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{ SkipCreationViaService: true, }) - gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("master")) + gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch(git.DefaultBranch)) repo := localrepo.NewTestRepo(t, cfg, repoProto) existingWorktreePath := filepath.Join(repoPath, worktreePrefix, "existing") diff --git a/internal/git/objectpool/create_test.go b/internal/git/objectpool/create_test.go index 4cb3e2031..db749e25b 100644 --- a/internal/git/objectpool/create_test.go +++ b/internal/git/objectpool/create_test.go @@ -33,7 +33,7 @@ func TestCreate(t *testing.T) { SkipCreationViaService: true, }) repo := localrepo.NewTestRepo(t, cfg, repoProto) - commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("master")) + commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch(git.DefaultBranch)) createPool := func(t *testing.T, poolProto *gitalypb.ObjectPool) (*ObjectPool, string, error) { catfileCache := catfile.NewCache(cfg) @@ -70,8 +70,8 @@ func TestCreate(t *testing.T) { require.NoDirExists(t, filepath.Join(poolPath, "hooks")) // The repository has no remote. require.Empty(t, gittest.Exec(t, cfg, "-C", poolPath, "remote")) - // The "master" branch points to the same commit as in the pool member. - require.Equal(t, commitID, gittest.ResolveRevision(t, cfg, poolPath, "refs/heads/master")) + // The default branch points to the same commit as in the pool member. + require.Equal(t, commitID, gittest.ResolveRevision(t, cfg, poolPath, string(git.DefaultRef))) // Objects exist in the pool repository. gittest.RequireObjectExists(t, cfg, poolPath, commitID) }) @@ -101,7 +101,7 @@ func TestCreate(t *testing.T) { }) gittest.WriteCommit(t, cfg, repoPath, gittest.WithParents(), - gittest.WithBranch("master"), + gittest.WithBranch(git.DefaultBranch), gittest.WithTree(treeID), ) diff --git a/internal/git/quarantine/quarantine_test.go b/internal/git/quarantine/quarantine_test.go index 0de0b6d32..e5ab0a2f3 100644 --- a/internal/git/quarantine/quarantine_test.go +++ b/internal/git/quarantine/quarantine_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/v15/internal/git" "gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo" "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/config" @@ -142,7 +143,7 @@ func TestQuarantine_localrepo(t *testing.T) { repoProto, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{ SkipCreationViaService: true, }) - gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("master")) + gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch(git.DefaultBranch)) repo := localrepo.NewTestRepo(t, cfg, repoProto) locator := config.NewLocator(cfg) diff --git a/internal/git/stats/http_push_test.go b/internal/git/stats/http_push_test.go index e6a74b95a..6c9a2a390 100644 --- a/internal/git/stats/http_push_test.go +++ b/internal/git/stats/http_push_test.go @@ -150,16 +150,16 @@ func TestPerformHTTPPush(t *testing.T) { { desc: "failing delete", preparePush: func(t *testing.T, cfg config.Cfg) ([]PushCommand, io.Reader) { - gittest.WriteCommit(t, cfg, targetRepoPath, gittest.WithBranch("master")) + gittest.WriteCommit(t, cfg, targetRepoPath, gittest.WithBranch(git.DefaultBranch)) oldOID := git.ObjectID(strings.Repeat("1", gittest.DefaultObjectHash.EncodedLen())) return []PushCommand{ - {OldOID: oldOID, NewOID: gittest.DefaultObjectHash.ZeroOID, Reference: "refs/heads/master"}, + {OldOID: oldOID, NewOID: gittest.DefaultObjectHash.ZeroOID, Reference: git.DefaultRef}, }, nil }, expectedErr: fmt.Errorf("parsing packfile response: %w", - errors.New("reference update failed: \"ng refs/heads/master deletion of the current branch prohibited\\n\"")), + errors.New("reference update failed: \"ng "+string(git.DefaultRef)+" deletion of the current branch prohibited\\n\"")), }, } { t.Run(tc.desc, func(t *testing.T) { |