diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2021-04-22 17:00:42 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2021-04-22 17:00:42 +0300 |
commit | 385d4bd0d9242bef94bfee14b5eef635238a2bba (patch) | |
tree | c7e35c2979ce5be28f6127235f4856b69bed3807 | |
parent | ffbce774bce90b5a65f5b235afe492a7266aa82f (diff) | |
parent | 3ff8154b9555e501556f1e0668cb304932008154 (diff) |
Merge branch 'ps-git-command' into 'master'
Introduce gittest.Exec|ExecStream to execute git commands
See merge request gitlab-org/gitaly!3389
35 files changed, 112 insertions, 56 deletions
diff --git a/internal/git/gittest/branch.go b/internal/git/gittest/branch.go index 35c844d68..af668bb06 100644 --- a/internal/git/gittest/branch.go +++ b/internal/git/gittest/branch.go @@ -3,11 +3,10 @@ package gittest import ( "testing" - "gitlab.com/gitlab-org/gitaly/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" ) // CreateRemoteBranch creates a new remote branch -func CreateRemoteBranch(t testing.TB, repoPath, remoteName, branchName, ref string) { - testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "update-ref", - "refs/remotes/"+remoteName+"/"+branchName, ref) +func CreateRemoteBranch(t testing.TB, cfg config.Cfg, repoPath, remoteName, branchName, ref string) { + Exec(t, cfg, "-C", repoPath, "update-ref", "refs/remotes/"+remoteName+"/"+branchName, ref) } diff --git a/internal/git/gittest/command.go b/internal/git/gittest/command.go new file mode 100644 index 000000000..7a5d1bb54 --- /dev/null +++ b/internal/git/gittest/command.go @@ -0,0 +1,47 @@ +package gittest + +import ( + "io" + "os" + "os/exec" + "testing" + + "gitlab.com/gitlab-org/gitaly/internal/command" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" +) + +// Exec runs a git command and returns the standard output, or fails. +func Exec(t testing.TB, cfg config.Cfg, args ...string) []byte { + return run(t, nil, cfg, args...) +} + +// ExecStream runs a git command with an input stream and returns the standard output, or fails. +func ExecStream(t testing.TB, cfg config.Cfg, stream io.Reader, args ...string) []byte { + return run(t, stream, cfg, args...) +} + +func run(t testing.TB, stdin io.Reader, cfg config.Cfg, args ...string) []byte { + t.Helper() + + cmd := exec.Command(cfg.Git.BinPath, args...) + cmd.Env = os.Environ() + cmd.Env = append(command.GitEnv, cmd.Env...) + cmd.Env = append(cmd.Env, + "GIT_AUTHOR_DATE=1572776879 +0100", + "GIT_COMMITTER_DATE=1572776879 +0100", + ) + + if stdin != nil { + cmd.Stdin = stdin + } + + output, err := cmd.Output() + if err != nil { + stderr := err.(*exec.ExitError).Stderr + t.Log(cfg.Git.BinPath, args) + t.Logf("%s: %s\n", stderr, output) + t.Fatal(err) + } + + return output +} diff --git a/internal/git/gittest/commit.go b/internal/git/gittest/commit.go index 29a3ea6e5..0fb23da2e 100644 --- a/internal/git/gittest/commit.go +++ b/internal/git/gittest/commit.go @@ -10,8 +10,8 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/helper/text" - "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) @@ -27,7 +27,7 @@ const ( ) // CreateCommit makes a new empty commit and updates the named branch to point to it. -func CreateCommit(t testing.TB, repoPath, branchName string, opts *CreateCommitOpts) string { +func CreateCommit(t testing.TB, cfg config.Cfg, repoPath, branchName string, opts *CreateCommitOpts) string { message := "message" // The ID of an arbitrary commit known to exist in the test repository. parentID := "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863" @@ -54,10 +54,10 @@ func CreateCommit(t testing.TB, repoPath, branchName string, opts *CreateCommitO "-C", repoPath, "commit-tree", "-F", "-", "-p", parentID, parentID + "^{tree}", } - newCommit := testhelper.MustRunCommand(t, stdin, "git", commitArgs...) + newCommit := ExecStream(t, cfg, stdin, commitArgs...) newCommitID := text.ChompBytes(newCommit) - testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "update-ref", "refs/heads/"+branchName, newCommitID) + Exec(t, cfg, "-C", repoPath, "update-ref", "refs/heads/"+branchName, newCommitID) return newCommitID } @@ -94,12 +94,12 @@ func CreateCommitInAlternateObjectDirectory(t testing.TB, gitBin, repoPath, altO // specified name. This enables testing situations where the filepath is not // possible due to filesystem constraints (e.g. non-UTF characters). The commit // ID is returned. -func CommitBlobWithName(t testing.TB, testRepoPath, blobID, fileName, commitMessage string) string { +func CommitBlobWithName(t testing.TB, cfg config.Cfg, testRepoPath, blobID, fileName, commitMessage string) string { mktreeIn := strings.NewReader(fmt.Sprintf("100644 blob %s\t%s", blobID, fileName)) - treeID := text.ChompBytes(testhelper.MustRunCommand(t, mktreeIn, "git", "-C", testRepoPath, "mktree")) + treeID := text.ChompBytes(ExecStream(t, cfg, mktreeIn, "-C", testRepoPath, "mktree")) return text.ChompBytes( - testhelper.MustRunCommand(t, nil, "git", + Exec(t, cfg, "-c", fmt.Sprintf("user.name=%s", committerName), "-c", fmt.Sprintf("user.email=%s", committerEmail), "-C", testRepoPath, "commit-tree", treeID, "-m", commitMessage), @@ -107,12 +107,12 @@ func CommitBlobWithName(t testing.TB, testRepoPath, blobID, fileName, commitMess } // CreateCommitOnNewBranch creates a branch and a commit, returning the commit sha and the branch name respectivelyi -func CreateCommitOnNewBranch(t testing.TB, repoPath string) (string, string) { +func CreateCommitOnNewBranch(t testing.TB, cfg config.Cfg, repoPath string) (string, string) { nonce, err := text.RandomHex(4) require.NoError(t, err) newBranch := "branch-" + nonce - sha := CreateCommit(t, repoPath, newBranch, &CreateCommitOpts{ + sha := CreateCommit(t, cfg, repoPath, newBranch, &CreateCommitOpts{ Message: "a new branch and commit " + nonce, }) diff --git a/internal/git/localrepo/remote_test.go b/internal/git/localrepo/remote_test.go index adceefe2b..79c93a6a8 100644 --- a/internal/git/localrepo/remote_test.go +++ b/internal/git/localrepo/remote_test.go @@ -498,7 +498,7 @@ if [ -z ${GIT_SSH_COMMAND+x} ];then rm -f %q ;else echo -n "$GIT_SSH_COMMAND" > require.NoError(t, err) require.NoError(t, sourceRepo.Push(ctx, pushRepoPath, []string{"refs/*"}, PushOptions{})) - divergedMaster := gittest.CreateCommit(t, pushRepoPath, "master", &gittest.CreateCommitOpts{ + divergedMaster := gittest.CreateCommit(t, cfg, pushRepoPath, "master", &gittest.CreateCommitOpts{ ParentID: sourceMaster.Target, }) diff --git a/internal/git/stats/profile_test.go b/internal/git/stats/profile_test.go index 25d6102ec..4d8080f3f 100644 --- a/internal/git/stats/profile_test.go +++ b/internal/git/stats/profile_test.go @@ -48,7 +48,7 @@ func TestRepositoryProfile(t *testing.T) { require.Equal(t, int64(blobs), looseObjects) for _, blobID := range blobIDs { - commitID := gittest.CommitBlobWithName(t, testRepoPath, blobID, blobID, "adding another blob....") + commitID := gittest.CommitBlobWithName(t, cfg, testRepoPath, blobID, blobID, "adding another blob....") testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "update-ref", "refs/heads/"+blobID, commitID) } diff --git a/internal/gitaly/service/commit/commit_messages_test.go b/internal/gitaly/service/commit/commit_messages_test.go index 4b41a4e5a..fbb4ca916 100644 --- a/internal/gitaly/service/commit/commit_messages_test.go +++ b/internal/gitaly/service/commit/commit_messages_test.go @@ -14,7 +14,7 @@ import ( ) func TestSuccessfulGetCommitMessagesRequest(t *testing.T) { - _, repo, repoPath, client := setupCommitServiceWithRepo(t, true) + cfg, repo, repoPath, client := setupCommitServiceWithRepo(t, true) ctx, cancel := testhelper.Context() defer cancel() @@ -22,8 +22,8 @@ func TestSuccessfulGetCommitMessagesRequest(t *testing.T) { message1 := strings.Repeat("a\n", helper.MaxCommitOrTagMessageSize*2) message2 := strings.Repeat("b\n", helper.MaxCommitOrTagMessageSize*2) - commit1ID := gittest.CreateCommit(t, repoPath, "local-big-commits", &gittest.CreateCommitOpts{Message: message1}) - commit2ID := gittest.CreateCommit(t, repoPath, "local-big-commits", &gittest.CreateCommitOpts{Message: message2, ParentID: commit1ID}) + commit1ID := gittest.CreateCommit(t, cfg, repoPath, "local-big-commits", &gittest.CreateCommitOpts{Message: message1}) + commit2ID := gittest.CreateCommit(t, cfg, repoPath, "local-big-commits", &gittest.CreateCommitOpts{Message: message2, ParentID: commit1ID}) request := &gitalypb.GetCommitMessagesRequest{ Repository: repo, diff --git a/internal/gitaly/service/commit/find_commit_test.go b/internal/gitaly/service/commit/find_commit_test.go index 50bf988b2..7f5182566 100644 --- a/internal/gitaly/service/commit/find_commit_test.go +++ b/internal/gitaly/service/commit/find_commit_test.go @@ -32,7 +32,7 @@ func TestSuccessfulFindCommitRequest(t *testing.T) { defer cancel() bigMessage := "An empty commit with REALLY BIG message\n\n" + strings.Repeat("MOAR!\n", 20*1024) - bigCommitID := gittest.CreateCommit(t, repoPath, "local-big-commits", &gittest.CreateCommitOpts{ + bigCommitID := gittest.CreateCommit(t, cfg, repoPath, "local-big-commits", &gittest.CreateCommitOpts{ Message: bigMessage, ParentID: "60ecb67744cb56576c30214ff52294f8ce2def98", }) diff --git a/internal/gitaly/service/commit/last_commit_for_path_test.go b/internal/gitaly/service/commit/last_commit_for_path_test.go index e5ef030a6..4c60c7766 100644 --- a/internal/gitaly/service/commit/last_commit_for_path_test.go +++ b/internal/gitaly/service/commit/last_commit_for_path_test.go @@ -115,13 +115,15 @@ func TestFailedLastCommitForPathRequest(t *testing.T) { } func TestSuccessfulLastCommitWithGlobCharacters(t *testing.T) { - _, repo, repoPath, client := setupCommitServiceWithRepo(t, true) + cfg, repo, repoPath, client := setupCommitServiceWithRepo(t, true) // This is an arbitrary blob known to exist in the test repository const blobID = "c60514b6d3d6bf4bec1030f70026e34dfbd69ad5" path := ":wq" - commitID := gittest.CommitBlobWithName(t, + commitID := gittest.CommitBlobWithName( + t, + cfg, repoPath, blobID, path, diff --git a/internal/gitaly/service/commit/list_last_commits_for_tree_test.go b/internal/gitaly/service/commit/list_last_commits_for_tree_test.go index c1797be9b..88eef4f15 100644 --- a/internal/gitaly/service/commit/list_last_commits_for_tree_test.go +++ b/internal/gitaly/service/commit/list_last_commits_for_tree_test.go @@ -320,7 +320,7 @@ func TestFailedListLastCommitsForTreeRequest(t *testing.T) { } func TestNonUtf8ListLastCommitsForTreeRequest(t *testing.T) { - _, repo, repoPath, client := setupCommitServiceWithRepo(t, true) + cfg, repo, repoPath, client := setupCommitServiceWithRepo(t, true) ctx, cancel := testhelper.Context() defer cancel() @@ -331,7 +331,9 @@ func TestNonUtf8ListLastCommitsForTreeRequest(t *testing.T) { nonUTF8Filename := "hello\x80world" require.False(t, utf8.ValidString(nonUTF8Filename)) - commitID := gittest.CommitBlobWithName(t, + commitID := gittest.CommitBlobWithName( + t, + cfg, repoPath, blobID, nonUTF8Filename, diff --git a/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go b/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go index 9dc3d9695..8e601a3ce 100644 --- a/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go +++ b/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go @@ -33,7 +33,7 @@ func TestFetchIntoObjectPool_Success(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - repoCommit := gittest.CreateCommit(t, repoPath, t.Name(), &gittest.CreateCommitOpts{Message: t.Name()}) + repoCommit := gittest.CreateCommit(t, cfg, repoPath, t.Name(), &gittest.CreateCommitOpts{Message: t.Name()}) pool, err := objectpool.NewObjectPool(cfg, locator, git.NewExecCommandFactory(cfg), repo.GetStorageName(), gittest.NewObjectPoolName(t)) require.NoError(t, err) diff --git a/internal/gitaly/service/objectpool/link_test.go b/internal/gitaly/service/objectpool/link_test.go index aa2f1d175..2ca1dfd36 100644 --- a/internal/gitaly/service/objectpool/link_test.go +++ b/internal/gitaly/service/objectpool/link_test.go @@ -33,7 +33,7 @@ func TestLink(t *testing.T) { // Mock object in the pool, which should be available to the pool members // after linking - poolCommitID := gittest.CreateCommit(t, pool.FullPath(), "pool-test-branch", nil) + poolCommitID := gittest.CreateCommit(t, cfg, pool.FullPath(), "pool-test-branch", nil) testCases := []struct { desc string diff --git a/internal/gitaly/service/operations/merge_test.go b/internal/gitaly/service/operations/merge_test.go index b70e79892..1ef299929 100644 --- a/internal/gitaly/service/operations/merge_test.go +++ b/internal/gitaly/service/operations/merge_test.go @@ -281,7 +281,7 @@ func TestFailedMergeConcurrentUpdate(t *testing.T) { require.NoError(t, err, "receive first response") // This concurrent update of the branch we are merging into should make the merge fail. - concurrentCommitID := gittest.CreateCommit(t, repoPath, mergeBranchName, nil) + concurrentCommitID := gittest.CreateCommit(t, cfg, repoPath, mergeBranchName, nil) require.NotEqual(t, firstResponse.CommitId, concurrentCommitID) require.NoError(t, mergeBidi.Send(&gitalypb.UserMergeBranchRequest{Apply: true}), "apply merge") diff --git a/internal/gitaly/service/ref/refs_test.go b/internal/gitaly/service/ref/refs_test.go index ef25594fc..cb2d9df0a 100644 --- a/internal/gitaly/service/ref/refs_test.go +++ b/internal/gitaly/service/ref/refs_test.go @@ -426,7 +426,7 @@ func TestSuccessfulFindAllTagsRequest(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - bigCommitID := gittest.CreateCommit(t, repoPath, "local-big-commits", &gittest.CreateCommitOpts{ + bigCommitID := gittest.CreateCommit(t, cfg, repoPath, "local-big-commits", &gittest.CreateCommitOpts{ Message: "An empty commit with REALLY BIG message\n\n" + strings.Repeat("a", helper.MaxCommitOrTagMessageSize+1), ParentID: "60ecb67744cb56576c30214ff52294f8ce2def98", }) @@ -929,7 +929,7 @@ func TestEmptyFindLocalBranchesRequest(t *testing.T) { } func TestSuccessfulFindAllBranchesRequest(t *testing.T) { - _, repo, repoPath, client := setupRefService(t) + cfg, repo, repoPath, client := setupRefService(t) remoteBranch := &gitalypb.FindAllBranchesResponse_Branch{ Name: []byte("refs/remotes/origin/fake-remote-branch"), @@ -956,7 +956,7 @@ func TestSuccessfulFindAllBranchesRequest(t *testing.T) { }, } - gittest.CreateRemoteBranch(t, repoPath, "origin", + gittest.CreateRemoteBranch(t, cfg, repoPath, "origin", "fake-remote-branch", remoteBranch.Target.Id) request := &gitalypb.FindAllBranchesRequest{Repository: repo} @@ -1291,7 +1291,7 @@ func TestSuccessfulFindTagRequest(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - bigCommitID := gittest.CreateCommit(t, repoPath, "local-big-commits", &gittest.CreateCommitOpts{ + bigCommitID := gittest.CreateCommit(t, cfg, repoPath, "local-big-commits", &gittest.CreateCommitOpts{ Message: "An empty commit with REALLY BIG message\n\n" + strings.Repeat("a", helper.MaxCommitOrTagMessageSize+1), ParentID: "60ecb67744cb56576c30214ff52294f8ce2def98", }) diff --git a/internal/gitaly/service/ref/remote_branches_test.go b/internal/gitaly/service/ref/remote_branches_test.go index 9f90d4b12..ac732396c 100644 --- a/internal/gitaly/service/ref/remote_branches_test.go +++ b/internal/gitaly/service/ref/remote_branches_test.go @@ -32,11 +32,11 @@ func TestSuccessfulFindAllRemoteBranchesRequest(t *testing.T) { } for branchName, commitID := range expectedBranches { - gittest.CreateRemoteBranch(t, repoPath, remoteName, branchName, commitID) + gittest.CreateRemoteBranch(t, cfg, repoPath, remoteName, branchName, commitID) } for branchName, commitID := range excludedBranches { - gittest.CreateRemoteBranch(t, repoPath, excludedRemote, branchName, commitID) + gittest.CreateRemoteBranch(t, cfg, repoPath, excludedRemote, branchName, commitID) } request := &gitalypb.FindAllRemoteBranchesRequest{Repository: repoProto, RemoteName: remoteName} diff --git a/internal/gitaly/service/remote/fetch_internal_remote_test.go b/internal/gitaly/service/remote/fetch_internal_remote_test.go index 1f7847914..c7e413ed7 100644 --- a/internal/gitaly/service/remote/fetch_internal_remote_test.go +++ b/internal/gitaly/service/remote/fetch_internal_remote_test.go @@ -157,7 +157,7 @@ func TestSuccessfulFetchInternalRemote(t *testing.T) { gitalypb.RegisterHookServiceServer(srv, hook.NewServer(deps.GetCfg(), deps.GetHookManager(), deps.GetGitCmdFactory())) }, testserver.WithDisablePraefect()) - gittest.CreateCommit(t, remoteRepoPath, "master", nil) + gittest.CreateCommit(t, remoteCfg, remoteRepoPath, "master", nil) localCfgBuilder := testcfg.NewGitalyCfgBuilder(testcfg.WithStorages("gitaly-1")) t.Cleanup(localCfgBuilder.Cleanup) diff --git a/internal/gitaly/service/remote/update_remote_mirror_test.go b/internal/gitaly/service/remote/update_remote_mirror_test.go index 39e87537a..9056e11c3 100644 --- a/internal/gitaly/service/remote/update_remote_mirror_test.go +++ b/internal/gitaly/service/remote/update_remote_mirror_test.go @@ -470,7 +470,7 @@ func testSuccessfulUpdateRemoteMirrorRequestFeatured(t *testing.T, ctx context.C Message: "Overriding tag", Force: true}) // Create a commit that only exists in the mirror - mirrorOnlyCommitOid := gittest.CreateCommit(t, mirrorPath, "master", nil) + mirrorOnlyCommitOid := gittest.CreateCommit(t, cfg, mirrorPath, "master", nil) require.NotEmpty(t, mirrorOnlyCommitOid) setupCommands := [][]string{ diff --git a/internal/gitaly/service/repository/clone_from_pool_internal_test.go b/internal/gitaly/service/repository/clone_from_pool_internal_test.go index 45894ce70..24ebb42b4 100644 --- a/internal/gitaly/service/repository/clone_from_pool_internal_test.go +++ b/internal/gitaly/service/repository/clone_from_pool_internal_test.go @@ -65,7 +65,7 @@ func TestCloneFromPoolInternal(t *testing.T) { fullRepack(t, testRepoPath) - _, newBranch := gittest.CreateCommitOnNewBranch(t, testRepoPath) + _, newBranch := gittest.CreateCommitOnNewBranch(t, config.Config, testRepoPath) forkedRepo, forkRepoPath, forkRepoCleanup := getForkDestination(t) defer forkRepoCleanup() diff --git a/internal/gitaly/service/repository/clone_from_pool_test.go b/internal/gitaly/service/repository/clone_from_pool_test.go index 3791cb576..267a3ee21 100644 --- a/internal/gitaly/service/repository/clone_from_pool_test.go +++ b/internal/gitaly/service/repository/clone_from_pool_test.go @@ -39,7 +39,7 @@ func TestCloneFromPoolHTTP(t *testing.T) { fullRepack(t, testRepoPath) - _, newBranch := gittest.CreateCommitOnNewBranch(t, testRepoPath) + _, newBranch := gittest.CreateCommitOnNewBranch(t, config.Config, testRepoPath) forkedRepo, forkRepoPath, forkRepoCleanup := getForkDestination(t) defer forkRepoCleanup() diff --git a/internal/gitaly/service/repository/commit_graph_test.go b/internal/gitaly/service/repository/commit_graph_test.go index 8dc962f57..cb684dab4 100644 --- a/internal/gitaly/service/repository/commit_graph_test.go +++ b/internal/gitaly/service/repository/commit_graph_test.go @@ -34,6 +34,7 @@ func TestWriteCommitGraph(t *testing.T) { gittest.CreateCommit( t, + config.Config, testRepoPath, t.Name(), &gittest.CreateCommitOpts{Message: t.Name()}, @@ -62,6 +63,7 @@ func TestUpdateCommitGraph(t *testing.T) { gittest.CreateCommit( t, + config.Config, testRepoPath, t.Name(), &gittest.CreateCommitOpts{Message: t.Name()}, @@ -86,6 +88,7 @@ func TestUpdateCommitGraph(t *testing.T) { gittest.CreateCommit( t, + config.Config, testRepoPath, t.Name(), &gittest.CreateCommitOpts{Message: t.Name()}, diff --git a/internal/gitaly/service/repository/create_bundle_test.go b/internal/gitaly/service/repository/create_bundle_test.go index be526d8e2..535bc5284 100644 --- a/internal/gitaly/service/repository/create_bundle_test.go +++ b/internal/gitaly/service/repository/create_bundle_test.go @@ -34,7 +34,7 @@ func TestSuccessfulCreateBundleRequest(t *testing.T) { // create a work tree with a HEAD pointing to a commit that is missing. // CreateBundle should clean this up before creating the bundle - sha, branchName := gittest.CreateCommitOnNewBranch(t, testRepoPath) + sha, branchName := gittest.CreateCommitOnNewBranch(t, config.Config, testRepoPath) require.NoError(t, os.MkdirAll(filepath.Join(testRepoPath, "gitlab-worktree"), 0755)) diff --git a/internal/gitaly/service/repository/fetch_remote_test.go b/internal/gitaly/service/repository/fetch_remote_test.go index 6fa0ca65c..67102e5b8 100644 --- a/internal/gitaly/service/repository/fetch_remote_test.go +++ b/internal/gitaly/service/repository/fetch_remote_test.go @@ -400,8 +400,8 @@ func TestFetchRemote_force(t *testing.T) { tagOID, err := sourceRepo.ResolveRevision(ctx, "refs/tags/v1.0.0") require.NoError(t, err) - divergingBranchOID, _ := gittest.CreateCommitOnNewBranch(t, sourceRepoPath) - divergingTagOID, _ := gittest.CreateCommitOnNewBranch(t, sourceRepoPath) + divergingBranchOID, _ := gittest.CreateCommitOnNewBranch(t, config.Config, sourceRepoPath) + divergingTagOID, _ := gittest.CreateCommitOnNewBranch(t, config.Config, sourceRepoPath) serverSocketPath, stop := runRepoServer(t, locator, testhelper.WithInternalSocket(config.Config)) defer stop() diff --git a/internal/gitaly/service/repository/fetch_test.go b/internal/gitaly/service/repository/fetch_test.go index a7160a0db..2f7e45abf 100644 --- a/internal/gitaly/service/repository/fetch_test.go +++ b/internal/gitaly/service/repository/fetch_test.go @@ -49,7 +49,7 @@ func TestFetchSourceBranchSourceRepositorySuccess(t *testing.T) { defer cleanup() sourceBranch := "fetch-source-branch-test-branch" - newCommitID := gittest.CreateCommit(t, sourcePath, sourceBranch, nil) + newCommitID := gittest.CreateCommit(t, config.Config, sourcePath, sourceBranch, nil) targetRef := "refs/tmp/fetch-source-branch-test" req := &gitalypb.FetchSourceBranchRequest{ @@ -87,7 +87,7 @@ func TestFetchSourceBranchSameRepositorySuccess(t *testing.T) { repo := localrepo.New(git.NewExecCommandFactory(config.Config), repoProto, config.Config) sourceBranch := "fetch-source-branch-test-branch" - newCommitID := gittest.CreateCommit(t, repoPath, sourceBranch, nil) + newCommitID := gittest.CreateCommit(t, config.Config, repoPath, sourceBranch, nil) targetRef := "refs/tmp/fetch-source-branch-test" req := &gitalypb.FetchSourceBranchRequest{ @@ -183,7 +183,7 @@ func TestFetchSourceBranchWrongRef(t *testing.T) { defer cleanup() sourceBranch := "fetch-source-branch-testmas-branch" - gittest.CreateCommit(t, sourceRepoPath, sourceBranch, nil) + gittest.CreateCommit(t, config.Config, sourceRepoPath, sourceBranch, nil) targetRef := "refs/tmp/fetch-source-branch-test" diff --git a/internal/gitaly/service/repository/gc_test.go b/internal/gitaly/service/repository/gc_test.go index 7ef7b432f..dca064b99 100644 --- a/internal/gitaly/service/repository/gc_test.go +++ b/internal/gitaly/service/repository/gc_test.go @@ -143,7 +143,7 @@ func TestGarbageCollectWithPrune(t *testing.T) { oldReferencedObjFile := filepath.Join(repoPath, "objects", blobHashes[2][:2], blobHashes[2][2:]) // create a reference to the blob, so it should not be removed by gc - gittest.CommitBlobWithName(t, repoPath, blobHashes[2], t.Name(), t.Name()) + gittest.CommitBlobWithName(t, config.Config, repoPath, blobHashes[2], t.Name(), t.Name()) // change modification time of the blobs to make them attractive for the gc aBitMoreThan30MinutesAgo := time.Now().Add(-30*time.Minute - time.Second) diff --git a/internal/gitaly/service/repository/midx_test.go b/internal/gitaly/service/repository/midx_test.go index d531e8fda..91e16e9b0 100644 --- a/internal/gitaly/service/repository/midx_test.go +++ b/internal/gitaly/service/repository/midx_test.go @@ -240,7 +240,7 @@ func addPackFiles( // create some pack files with different sizes for i := 0; i < packCount; i++ { for y := packCount + 1 - i; y > 0; y-- { - gittest.CreateCommitOnNewBranch(t, repoPath) + gittest.CreateCommitOnNewBranch(t, config.Config, repoPath) } _, err = client.RepackIncremental(ctx, &gitalypb.RepackIncrementalRequest{Repository: repo}) diff --git a/internal/gitaly/service/repository/optimize_test.go b/internal/gitaly/service/repository/optimize_test.go index 315f12d53..265d6c481 100644 --- a/internal/gitaly/service/repository/optimize_test.go +++ b/internal/gitaly/service/repository/optimize_test.go @@ -55,7 +55,7 @@ func TestOptimizeRepository(t *testing.T) { // get timestamp of latest packfile newestsPackfileTime := getNewestPackfileModtime(t, testRepoPath) - gittest.CreateCommit(t, testRepoPath, "master", nil) + gittest.CreateCommit(t, config.Config, testRepoPath, "master", nil) testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "config", "http.http://localhost:51744/60631c8695bf041a808759a05de53e36a73316aacb502824fabbb0c6055637c1.git.extraHeader", "Authorization: Basic secret-password") testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "config", "http.http://localhost:51744/60631c8695bf041a808759a05de53e36a73316aacb502824fabbb0c6055637c2.git.extraHeader", "Authorization: Basic secret-password") @@ -106,7 +106,7 @@ func TestOptimizeRepository(t *testing.T) { require.NoError(t, err) for _, blobID := range blobIDs { - commitID := gittest.CommitBlobWithName(t, testRepoPath, blobID, blobID, "adding another blob....") + commitID := gittest.CommitBlobWithName(t, config.Config, testRepoPath, blobID, blobID, "adding another blob....") require.NoError(t, updater.Create(git.ReferenceName("refs/heads/"+blobID), commitID)) } diff --git a/internal/gitaly/service/repository/raw_changes_test.go b/internal/gitaly/service/repository/raw_changes_test.go index a51d42b20..59830d6a9 100644 --- a/internal/gitaly/service/repository/raw_changes_test.go +++ b/internal/gitaly/service/repository/raw_changes_test.go @@ -343,6 +343,7 @@ func TestGetRawChangesInvalidUTF8Paths(t *testing.T) { fromCommitID := gittest.CommitBlobWithName( t, + config.Config, testRepoPath, blobID1, nonUTF8Filename, @@ -350,6 +351,7 @@ func TestGetRawChangesInvalidUTF8Paths(t *testing.T) { ) toCommitID := gittest.CommitBlobWithName( t, + config.Config, testRepoPath, blobID2, nonUTF8Filename, diff --git a/internal/gitaly/service/repository/rename_test.go b/internal/gitaly/service/repository/rename_test.go index 1efe13275..f46823866 100644 --- a/internal/gitaly/service/repository/rename_test.go +++ b/internal/gitaly/service/repository/rename_test.go @@ -57,7 +57,7 @@ func TestRenameRepositoryDestinationExists(t *testing.T) { destinationRepo, destinationRepoPath, cleanupDestinationRepo := gittest.CloneRepo(t) defer cleanupDestinationRepo() - _, sha := gittest.CreateCommitOnNewBranch(t, destinationRepoPath) + _, sha := gittest.CreateCommitOnNewBranch(t, config.Config, destinationRepoPath) req := &gitalypb.RenameRepositoryRequest{Repository: testRepo, RelativePath: destinationRepo.GetRelativePath()} diff --git a/internal/gitaly/service/repository/repack_test.go b/internal/gitaly/service/repository/repack_test.go index cf81b4ab5..fe8026a6b 100644 --- a/internal/gitaly/service/repository/repack_test.go +++ b/internal/gitaly/service/repository/repack_test.go @@ -96,7 +96,7 @@ func TestRepackLocal(t *testing.T) { altObjectsDir := "./alt-objects" altDirsCommit := gittest.CreateCommitInAlternateObjectDirectory(t, config.Config.Git.BinPath, repoPath, altObjectsDir, cmd) - repoCommit := gittest.CreateCommit(t, repoPath, t.Name(), &gittest.CreateCommitOpts{Message: t.Name()}) + repoCommit := gittest.CreateCommit(t, config.Config, repoPath, t.Name(), &gittest.CreateCommitOpts{Message: t.Name()}) ctx, cancelFn := testhelper.Context() defer cancelFn() diff --git a/internal/gitaly/service/repository/replicate_test.go b/internal/gitaly/service/repository/replicate_test.go index a4c863999..3d993edaa 100644 --- a/internal/gitaly/service/repository/replicate_test.go +++ b/internal/gitaly/service/repository/replicate_test.go @@ -97,7 +97,7 @@ func TestReplicateRepository(t *testing.T) { require.Equal(t, string(attrData), string(replicatedAttrData), "info/attributes files must match") // create another branch - _, anotherNewBranch := gittest.CreateCommitOnNewBranch(t, testRepoPath) + _, anotherNewBranch := gittest.CreateCommitOnNewBranch(t, config.Config, testRepoPath) _, err = repoClient.ReplicateRepository(injectedCtx, &gitalypb.ReplicateRepositoryRequest{ Repository: &targetRepo, Source: testRepo, diff --git a/internal/gitaly/service/repository/snapshot_test.go b/internal/gitaly/service/repository/snapshot_test.go index 3ce7b4c65..f72f6cab6 100644 --- a/internal/gitaly/service/repository/snapshot_test.go +++ b/internal/gitaly/service/repository/snapshot_test.go @@ -63,7 +63,7 @@ func TestGetSnapshotSuccess(t *testing.T) { // Ensure certain files exist in the test repo. // CreateCommit produces a loose object with the given sha - sha := gittest.CreateCommit(t, repoPath, "master", nil) + sha := gittest.CreateCommit(t, config.Config, repoPath, "master", nil) zeroes := strings.Repeat("0", 40) require.NoError(t, os.MkdirAll(filepath.Join(repoPath, "hooks"), 0755)) require.NoError(t, os.MkdirAll(filepath.Join(repoPath, "objects/pack"), 0755)) diff --git a/internal/gitaly/service/smarthttp/inforefs_test.go b/internal/gitaly/service/smarthttp/inforefs_test.go index 2bdc6cf27..246ddc997 100644 --- a/internal/gitaly/service/smarthttp/inforefs_test.go +++ b/internal/gitaly/service/smarthttp/inforefs_test.go @@ -191,7 +191,7 @@ func TestObjectPoolRefAdvertisementHiding(t *testing.T) { require.NoError(t, pool.Remove(ctx)) }() - commitID := gittest.CreateCommit(t, pool.FullPath(), t.Name(), nil) + commitID := gittest.CreateCommit(t, config.Config, pool.FullPath(), t.Name(), nil) require.NoError(t, pool.Link(ctx, repo)) diff --git a/internal/gitaly/service/smarthttp/upload_pack_test.go b/internal/gitaly/service/smarthttp/upload_pack_test.go index da704408d..4e2e9db37 100644 --- a/internal/gitaly/service/smarthttp/upload_pack_test.go +++ b/internal/gitaly/service/smarthttp/upload_pack_test.go @@ -18,6 +18,7 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/internal/git/pktline" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -440,7 +441,7 @@ func TestUploadPackRequestForPartialCloneSuccess(t *testing.T) { gittest.GitObjectMustNotExist(t, cfg.Git.BinPath, localRepoPath, blobGreaterThanLimit) newBranch := "new-branch" - newHead = []byte(gittest.CreateCommit(t, remoteRepoPath, newBranch, &gittest.CreateCommitOpts{ + newHead = []byte(gittest.CreateCommit(t, config.Config, remoteRepoPath, newBranch, &gittest.CreateCommitOpts{ Message: commitMsg, })) diff --git a/internal/gitaly/service/ssh/receive_pack_test.go b/internal/gitaly/service/ssh/receive_pack_test.go index 389624a42..f35adec0b 100644 --- a/internal/gitaly/service/ssh/receive_pack_test.go +++ b/internal/gitaly/service/ssh/receive_pack_test.go @@ -230,7 +230,7 @@ func TestObjectPoolRefAdvertisementHidingSSH(t *testing.T) { require.NoError(t, pool.Link(ctx, repo)) - commitID := gittest.CreateCommit(t, pool.FullPath(), t.Name(), nil) + commitID := gittest.CreateCommit(t, cfg, pool.FullPath(), t.Name(), nil) // First request require.NoError(t, stream.Send(&gitalypb.SSHReceivePackRequest{ diff --git a/internal/praefect/info_service_test.go b/internal/praefect/info_service_test.go index 48fcdebf9..df9c16b70 100644 --- a/internal/praefect/info_service_test.go +++ b/internal/praefect/info_service_test.go @@ -69,7 +69,7 @@ func TestInfoService_RepositoryReplicas(t *testing.T) { gittest.CloneRepoAtStorageRoot(t, cfg.Storages[2].Path, "repo-1") // create a commit in the second replica so we can check that its checksum is different than the primary - gittest.CreateCommit(t, filepath.Join(cfg.Storages[1].Path, "repo-1"), "master", nil) + gittest.CreateCommit(t, cfg, filepath.Join(cfg.Storages[1].Path, "repo-1"), "master", nil) nodeManager, err := nodes.NewManager(testhelper.DiscardTestEntry(t), conf, nil, nil, promtest.NewMockHistogramVec(), protoregistry.GitalyProtoPreregistered, nil, nil) require.NoError(t, err) diff --git a/internal/praefect/replicator_test.go b/internal/praefect/replicator_test.go index e209efe53..80ec36d48 100644 --- a/internal/praefect/replicator_test.go +++ b/internal/praefect/replicator_test.go @@ -193,7 +193,7 @@ func TestReplMgr_ProcessBacklog(t *testing.T) { } require.Len(t, events, 1) - commitID := gittest.CreateCommit(t, testRepoPath, "master", &gittest.CreateCommitOpts{ + commitID := gittest.CreateCommit(t, gitaly_config.Config, testRepoPath, "master", &gittest.CreateCommitOpts{ Message: "a commit", }) @@ -568,7 +568,7 @@ func TestConfirmReplication(t *testing.T) { require.NoError(t, err) require.True(t, equal) - gittest.CreateCommit(t, testRepoAPath, "master", &gittest.CreateCommitOpts{ + gittest.CreateCommit(t, gitaly_config.Config, testRepoAPath, "master", &gittest.CreateCommitOpts{ Message: "a commit", }) |