diff options
author | Pavlo Strokov <pstrokov@gitlab.com> | 2021-02-17 19:55:30 +0300 |
---|---|---|
committer | Pavlo Strokov <pstrokov@gitlab.com> | 2021-02-17 19:55:30 +0300 |
commit | aa713f60d41ccfddb75870cfa9e2a0a540662fa2 (patch) | |
tree | 613c508b7fbae668ace22796c0393faf456c54e5 | |
parent | f2a7ab844377c6434db626584ad9b4480432abf7 (diff) |
Make CreateCommitInAlternateObjectDirectory independent from global
CreateCommitInAlternateObjectDirectory is not dependent on the global
config.Config variable anymore.
Part of: https://gitlab.com/gitlab-org/gitaly/-/issues/2699
-rw-r--r-- | internal/gitaly/service/blob/lfs_pointers_test.go | 2 | ||||
-rw-r--r-- | internal/gitaly/service/commit/find_commits_test.go | 2 | ||||
-rw-r--r-- | internal/gitaly/service/commit/isancestor_test.go | 2 | ||||
-rw-r--r-- | internal/gitaly/service/repository/repack_test.go | 2 | ||||
-rw-r--r-- | internal/gitaly/service/repository/snapshot_test.go | 6 | ||||
-rw-r--r-- | internal/testhelper/git_commit.go | 5 |
6 files changed, 9 insertions, 10 deletions
diff --git a/internal/gitaly/service/blob/lfs_pointers_test.go b/internal/gitaly/service/blob/lfs_pointers_test.go index 587903f8d..8845454df 100644 --- a/internal/gitaly/service/blob/lfs_pointers_test.go +++ b/internal/gitaly/service/blob/lfs_pointers_test.go @@ -142,7 +142,7 @@ func TestSuccessfulGetNewLFSPointersRequest(t *testing.T) { // Skip smudge since it doesn't work with file:// remotes and we don't need it cmd.Env = append(cmd.Env, "GIT_LFS_SKIP_SMUDGE=1") altDirs := "./alt-objects" - altDirsCommit := testhelper.CreateCommitInAlternateObjectDirectory(t, testRepoPath, altDirs, cmd) + altDirsCommit := testhelper.CreateCommitInAlternateObjectDirectory(t, config.Config.Git.BinPath, testRepoPath, altDirs, cmd) // Create a commit not pointed at by any ref to emulate being in the // pre-receive hook so that `--not --all` returns some objects diff --git a/internal/gitaly/service/commit/find_commits_test.go b/internal/gitaly/service/commit/find_commits_test.go index a8d20c8eb..6c48c2c75 100644 --- a/internal/gitaly/service/commit/find_commits_test.go +++ b/internal/gitaly/service/commit/find_commits_test.go @@ -465,7 +465,7 @@ func TestSuccessfulFindCommitsRequestWithAltGitObjectDirs(t *testing.T) { "-c", fmt.Sprintf("user.email=%s", committerEmail), "commit", "--allow-empty", "-m", "An empty commit") altObjectsDir := "./alt-objects" - currentHead := testhelper.CreateCommitInAlternateObjectDirectory(t, testRepoCopyPath, altObjectsDir, cmd) + currentHead := testhelper.CreateCommitInAlternateObjectDirectory(t, config.Config.Git.BinPath, testRepoCopyPath, altObjectsDir, cmd) testCases := []struct { desc string diff --git a/internal/gitaly/service/commit/isancestor_test.go b/internal/gitaly/service/commit/isancestor_test.go index 2ef08e60a..70a079e5f 100644 --- a/internal/gitaly/service/commit/isancestor_test.go +++ b/internal/gitaly/service/commit/isancestor_test.go @@ -196,7 +196,7 @@ func TestSuccessfulIsAncestorRequestWithAltGitObjectDirs(t *testing.T) { "-c", fmt.Sprintf("user.email=%s", committerEmail), "commit", "--allow-empty", "-m", "An empty commit") altObjectsDir := "./alt-objects" - currentHead := testhelper.CreateCommitInAlternateObjectDirectory(t, testRepoCopyPath, altObjectsDir, cmd) + currentHead := testhelper.CreateCommitInAlternateObjectDirectory(t, config.Config.Git.BinPath, testRepoCopyPath, altObjectsDir, cmd) testCases := []struct { desc string diff --git a/internal/gitaly/service/repository/repack_test.go b/internal/gitaly/service/repository/repack_test.go index c3b585533..e256b5c41 100644 --- a/internal/gitaly/service/repository/repack_test.go +++ b/internal/gitaly/service/repository/repack_test.go @@ -94,7 +94,7 @@ func TestRepackLocal(t *testing.T) { cmdArgs := append(commiterArgs, "-C", repoPath, "commit", "--allow-empty", "-m", "An empty commit") cmd := exec.Command(config.Config.Git.BinPath, cmdArgs...) altObjectsDir := "./alt-objects" - altDirsCommit := testhelper.CreateCommitInAlternateObjectDirectory(t, repoPath, altObjectsDir, cmd) + altDirsCommit := testhelper.CreateCommitInAlternateObjectDirectory(t, config.Config.Git.BinPath, repoPath, altObjectsDir, cmd) repoCommit := testhelper.CreateCommit(t, repoPath, t.Name(), &testhelper.CreateCommitOpts{Message: t.Name()}) diff --git a/internal/gitaly/service/repository/snapshot_test.go b/internal/gitaly/service/repository/snapshot_test.go index 6425292d0..3572192cb 100644 --- a/internal/gitaly/service/repository/snapshot_test.go +++ b/internal/gitaly/service/repository/snapshot_test.go @@ -132,7 +132,7 @@ func TestGetSnapshotWithDedupe(t *testing.T) { "-c", fmt.Sprintf("user.email=%s", committerEmail), "commit", "--allow-empty", "-m", "An empty commit") alternateObjDir := tc.alternatePathFunc(t, filepath.Join(repoPath, "objects")) - commitSha := testhelper.CreateCommitInAlternateObjectDirectory(t, repoPath, alternateObjDir, cmd) + commitSha := testhelper.CreateCommitInAlternateObjectDirectory(t, config.Config.Git.BinPath, repoPath, alternateObjDir, cmd) originalAlternatesCommit := string(commitSha) locator := config.NewLocator(config.Config) @@ -154,7 +154,7 @@ func TestGetSnapshotWithDedupe(t *testing.T) { "-c", fmt.Sprintf("user.name=%s", committerName), "-c", fmt.Sprintf("user.email=%s", committerEmail), "commit", "--allow-empty", "-m", "Another empty commit") - commitSha = testhelper.CreateCommitInAlternateObjectDirectory(t, repoPath, alternateObjDir, cmd) + commitSha = testhelper.CreateCommitInAlternateObjectDirectory(t, config.Config.Git.BinPath, repoPath, alternateObjDir, cmd) c, err = catfile.New(ctx, gitCmdFactory, testRepo) require.NoError(t, err) @@ -213,7 +213,7 @@ func TestGetSnapshotWithDedupeSoftFailures(t *testing.T) { "-c", fmt.Sprintf("user.email=%s", committerEmail), "commit", "--allow-empty", "-m", "An empty commit") - commitSha := testhelper.CreateCommitInAlternateObjectDirectory(t, repoPath, alternateObjDir, cmd) + commitSha := testhelper.CreateCommitInAlternateObjectDirectory(t, config.Config.Git.BinPath, repoPath, alternateObjDir, cmd) originalAlternatesCommit := string(commitSha) require.NoError(t, ioutil.WriteFile(alternatesPath, []byte(alternateObjPath), 0644)) diff --git a/internal/testhelper/git_commit.go b/internal/testhelper/git_commit.go index ee6320f07..bb50aa20d 100644 --- a/internal/testhelper/git_commit.go +++ b/internal/testhelper/git_commit.go @@ -10,7 +10,6 @@ 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/proto/go/gitalypb" ) @@ -64,7 +63,7 @@ func CreateCommit(t testing.TB, repoPath, branchName string, opts *CreateCommitO // CreateCommitInAlternateObjectDirectory runs a command such that its created // objects will live in an alternate objects directory. It returns the current // head after the command is run and the alternate objects directory path -func CreateCommitInAlternateObjectDirectory(t testing.TB, repoPath, altObjectsDir string, cmd *exec.Cmd) (currentHead []byte) { +func CreateCommitInAlternateObjectDirectory(t testing.TB, gitBin, repoPath, altObjectsDir string, cmd *exec.Cmd) (currentHead []byte) { gitPath := filepath.Join(repoPath, ".git") altObjectsPath := filepath.Join(gitPath, altObjectsDir) @@ -82,7 +81,7 @@ func CreateCommitInAlternateObjectDirectory(t testing.TB, repoPath, altObjectsDi t.Fatalf("stdout: %s, stderr: %s", output, stderr) } - cmd = exec.Command(config.Config.Git.BinPath, "-C", repoPath, "rev-parse", "HEAD") + cmd = exec.Command(gitBin, "-C", repoPath, "rev-parse", "HEAD") cmd.Env = gitObjectEnv currentHead, err := cmd.Output() require.NoError(t, err) |