Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2020-08-18 16:58:52 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2020-08-20 08:49:51 +0300
commitabb1fcd6457b02dd4bffd697ebf92c76fac9bbdf (patch)
tree0cc2ada043bdaec79d15b895362ecdfc1a6756e5
parent56251315578cd17c0ceebcb911e8d3ddb159afca (diff)
tests: Fix calls to `exec.Command` using wrong Git executable
While production code uses the Git DSL to execute Git commands in most places which always respects the configured Git binary, many of our tests don't. This commit fixes them by modifying `MustRunCommand()` to automatically adjust invocations of `"git"` and fixing up any other locations which used `exec.Cmd` directly.
-rw-r--r--cmd/gitaly-debug/simulatehttp.go5
-rw-r--r--cmd/gitaly-ssh/auth_test.go3
-rw-r--r--internal/git/gittest/http_server.go4
-rw-r--r--internal/service/blob/lfs_pointers_test.go3
-rw-r--r--internal/service/commit/find_commits_test.go3
-rw-r--r--internal/service/commit/isancestor_test.go3
-rw-r--r--internal/service/operations/branches_test.go13
-rw-r--r--internal/service/operations/merge_test.go13
-rw-r--r--internal/service/operations/tags_test.go11
-rw-r--r--internal/service/ref/refs_test.go5
-rw-r--r--internal/service/repository/calculate_checksum_test.go3
-rw-r--r--internal/service/repository/cleanup_test.go3
-rw-r--r--internal/service/repository/redirecting_test_server_test.go2
-rw-r--r--internal/service/repository/repack_test.go3
-rw-r--r--internal/service/repository/search_files_test.go3
-rw-r--r--internal/service/repository/snapshot_test.go7
-rw-r--r--internal/service/ssh/receive_pack_test.go3
-rw-r--r--internal/service/ssh/upload_archive_test.go3
-rw-r--r--internal/service/ssh/upload_pack_test.go15
-rw-r--r--internal/testhelper/commit.go3
-rw-r--r--internal/testhelper/testhelper.go8
21 files changed, 68 insertions, 48 deletions
diff --git a/cmd/gitaly-debug/simulatehttp.go b/cmd/gitaly-debug/simulatehttp.go
index c87b4f5ee..ac9a63fe3 100644
--- a/cmd/gitaly-debug/simulatehttp.go
+++ b/cmd/gitaly-debug/simulatehttp.go
@@ -9,12 +9,13 @@ import (
"regexp"
"time"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/git/pktline"
)
func simulateHTTPClone(gitDir string) {
msg("Generating server response for HTTP clone. Data goes to /dev/null.")
- infoRefs := exec.Command("git", "upload-pack", "--stateless-rpc", "--advertise-refs", gitDir)
+ infoRefs := exec.Command(command.GitPath(), "upload-pack", "--stateless-rpc", "--advertise-refs", gitDir)
infoRefs.Stderr = os.Stderr
out, err := infoRefs.StdoutPipe()
noError(err)
@@ -57,7 +58,7 @@ func simulateHTTPClone(gitDir string) {
}
fmt.Fprint(request, "00000009done\n")
- uploadPack := exec.Command("git", "upload-pack", "--stateless-rpc", gitDir)
+ uploadPack := exec.Command(command.GitPath(), "upload-pack", "--stateless-rpc", gitDir)
uploadPack.Stdin = request
uploadPack.Stderr = os.Stderr
out, err = uploadPack.StdoutPipe()
diff --git a/cmd/gitaly-ssh/auth_test.go b/cmd/gitaly-ssh/auth_test.go
index 6206aede4..bc6d55438 100644
--- a/cmd/gitaly-ssh/auth_test.go
+++ b/cmd/gitaly-ssh/auth_test.go
@@ -12,6 +12,7 @@ import (
"github.com/golang/protobuf/jsonpb"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/config"
"gitlab.com/gitlab-org/gitaly/internal/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/server"
@@ -91,7 +92,7 @@ func TestConnectivity(t *testing.T) {
require.NoError(t, err)
for _, testcase := range testCases {
t.Run(testcase.name, func(t *testing.T) {
- cmd := exec.Command("git", "ls-remote", "git@localhost:test/test.git", "refs/heads/master")
+ cmd := exec.Command(command.GitPath(), "ls-remote", "git@localhost:test/test.git", "refs/heads/master")
cmd.Stderr = os.Stderr
cmd.Env = []string{
fmt.Sprintf("GITALY_PAYLOAD=%s", payload),
diff --git a/internal/git/gittest/http_server.go b/internal/git/gittest/http_server.go
index 4e5d1916a..25ff78f08 100644
--- a/internal/git/gittest/http_server.go
+++ b/internal/git/gittest/http_server.go
@@ -30,7 +30,7 @@ func RemoteUploadPackServer(ctx context.Context, t *testing.T, repoName, httpTok
}
defer r.Body.Close()
- cmd, err := command.New(ctx, exec.Command("git", "-C", repoPath, "upload-pack", "--stateless-rpc", "."), reader, w, nil)
+ cmd, err := command.New(ctx, exec.Command(command.GitPath(), "-C", repoPath, "upload-pack", "--stateless-rpc", "."), reader, w, nil)
require.NoError(t, err)
require.NoError(t, cmd.Wait())
case fmt.Sprintf("/%s.git/info/refs?service=git-upload-pack", repoName):
@@ -44,7 +44,7 @@ func RemoteUploadPackServer(ctx context.Context, t *testing.T, repoName, httpTok
w.Write([]byte("001e# service=git-upload-pack\n"))
w.Write([]byte("0000"))
- cmd, err := command.New(ctx, exec.Command("git", "-C", repoPath, "upload-pack", "--advertise-refs", "."), nil, w, nil)
+ cmd, err := command.New(ctx, exec.Command(command.GitPath(), "-C", repoPath, "upload-pack", "--advertise-refs", "."), nil, w, nil)
require.NoError(t, err)
require.NoError(t, cmd.Wait())
default:
diff --git a/internal/service/blob/lfs_pointers_test.go b/internal/service/blob/lfs_pointers_test.go
index 7126b35f8..9f2c8de4f 100644
--- a/internal/service/blob/lfs_pointers_test.go
+++ b/internal/service/blob/lfs_pointers_test.go
@@ -7,6 +7,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -137,7 +138,7 @@ func TestSuccessfulGetNewLFSPointersRequest(t *testing.T) {
revision := []byte("46abbb087fcc0fd02c340f0f2f052bd2c7708da3")
commiterArgs := []string{"-c", "user.name=Scrooge McDuck", "-c", "user.email=scrooge@mcduck.com"}
cmdArgs := append(commiterArgs, "-C", testRepoPath, "cherry-pick", string(revision))
- cmd := exec.Command("git", cmdArgs...)
+ cmd := exec.Command(command.GitPath(), cmdArgs...)
// 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"
diff --git a/internal/service/commit/find_commits_test.go b/internal/service/commit/find_commits_test.go
index 8e906a3c9..c94b80173 100644
--- a/internal/service/commit/find_commits_test.go
+++ b/internal/service/commit/find_commits_test.go
@@ -11,6 +11,7 @@ import (
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -455,7 +456,7 @@ func TestSuccessfulFindCommitsRequestWithAltGitObjectDirs(t *testing.T) {
testRepoCopy, testRepoCopyPath, cleanupFn := testhelper.NewTestRepoWithWorktree(t)
defer cleanupFn()
- cmd := exec.Command("git", "-C", testRepoCopyPath,
+ cmd := exec.Command(command.GitPath(), "-C", testRepoCopyPath,
"-c", fmt.Sprintf("user.name=%s", committerName),
"-c", fmt.Sprintf("user.email=%s", committerEmail),
"commit", "--allow-empty", "-m", "An empty commit")
diff --git a/internal/service/commit/isancestor_test.go b/internal/service/commit/isancestor_test.go
index 48998d09a..f63b422a8 100644
--- a/internal/service/commit/isancestor_test.go
+++ b/internal/service/commit/isancestor_test.go
@@ -6,6 +6,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/helper"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -190,7 +191,7 @@ func TestSuccessfulIsAncestorRequestWithAltGitObjectDirs(t *testing.T) {
previousHead := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoCopyPath, "show", "--format=format:%H", "--no-patch", "HEAD")
- cmd := exec.Command("git", "-C", testRepoCopyPath,
+ cmd := exec.Command(command.GitPath(), "-C", testRepoCopyPath,
"-c", fmt.Sprintf("user.name=%s", committerName),
"-c", fmt.Sprintf("user.email=%s", committerEmail),
"commit", "--allow-empty", "-m", "An empty commit")
diff --git a/internal/service/operations/branches_test.go b/internal/service/operations/branches_test.go
index bd235e572..e6879d9f1 100644
--- a/internal/service/operations/branches_test.go
+++ b/internal/service/operations/branches_test.go
@@ -8,6 +8,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/config"
"gitlab.com/gitlab-org/gitaly/internal/git/log"
"gitlab.com/gitlab-org/gitaly/internal/helper"
@@ -79,7 +80,7 @@ func TestSuccessfulCreateBranchRequest(t *testing.T) {
response, err := client.UserCreateBranch(ctx, request)
if testCase.expectedBranch != nil {
- defer exec.Command("git", "-C", testRepoPath, "branch", "-D", branchName).Run()
+ defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-D", branchName).Run()
}
require.NoError(t, err)
@@ -162,7 +163,7 @@ func TestUserCreateBranchWithTransaction(t *testing.T) {
for _, tc := range testcases {
t.Run(tc.desc, func(t *testing.T) {
- defer exec.Command("git", "-C", testRepoPath, "branch", "-D", "new-branch").Run()
+ defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-D", "new-branch").Run()
client, conn := newOperationClient(t, tc.address)
defer conn.Close()
@@ -211,7 +212,7 @@ func testSuccessfulGitHooksForUserCreateBranchRequest(t *testing.T, ctx context.
for _, hookName := range GitlabHooks {
t.Run(hookName, func(t *testing.T) {
- defer exec.Command("git", "-C", testRepoPath, "branch", "-D", branchName).Run()
+ defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-D", branchName).Run()
hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName)
defer cleanup()
@@ -348,7 +349,7 @@ func TestSuccessfulUserDeleteBranchRequest(t *testing.T) {
branchNameInput := "to-be-deleted-soon-branch"
- defer exec.Command("git", "-C", testRepoPath, "branch", "-d", branchNameInput).Run()
+ defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-d", branchNameInput).Run()
testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", branchNameInput)
@@ -378,7 +379,7 @@ func TestSuccessfulGitHooksForUserDeleteBranchRequest(t *testing.T) {
defer conn.Close()
branchNameInput := "to-be-deleted-soon-branch"
- defer exec.Command("git", "-C", testRepoPath, "branch", "-d", branchNameInput).Run()
+ defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-d", branchNameInput).Run()
request := &gitalypb.UserDeleteBranchRequest{
Repository: testRepo,
@@ -470,7 +471,7 @@ func TestFailedUserDeleteBranchDueToHooks(t *testing.T) {
branchNameInput := "to-be-deleted-soon-branch"
testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", branchNameInput)
- defer exec.Command("git", "-C", testRepoPath, "branch", "-d", branchNameInput).Run()
+ defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-d", branchNameInput).Run()
request := &gitalypb.UserDeleteBranchRequest{
Repository: testRepo,
diff --git a/internal/service/operations/merge_test.go b/internal/service/operations/merge_test.go
index 2c60c3718..5a9ad356e 100644
--- a/internal/service/operations/merge_test.go
+++ b/internal/service/operations/merge_test.go
@@ -10,6 +10,7 @@ import (
"time"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
gitlog "gitlab.com/gitlab-org/gitaly/internal/git/log"
"gitlab.com/gitlab-org/gitaly/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
@@ -307,7 +308,7 @@ func TestSuccessfulUserFFBranchRequest(t *testing.T) {
}
testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", "-f", branchName, "6d394385cf567f80a8fd85055db1ab4c5295806f")
- defer exec.Command("git", "-C", testRepoPath, "branch", "-d", branchName).Run()
+ defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-d", branchName).Run()
resp, err := client.UserFFBranch(ctx, request)
require.NoError(t, err)
@@ -330,7 +331,7 @@ func TestFailedUserFFBranchRequest(t *testing.T) {
branchName := "test-ff-target-branch"
testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", "-f", branchName, "6d394385cf567f80a8fd85055db1ab4c5295806f")
- defer exec.Command("git", "-C", testRepoPath, "branch", "-d", branchName).Run()
+ defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-d", branchName).Run()
testCases := []struct {
desc string
@@ -431,7 +432,7 @@ func TestFailedUserFFBranchDueToHooks(t *testing.T) {
}
testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", "-f", branchName, "6d394385cf567f80a8fd85055db1ab4c5295806f")
- defer exec.Command("git", "-C", testRepoPath, "branch", "-d", branchName).Run()
+ defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-d", branchName).Run()
hookContent := []byte("#!/bin/sh\necho 'failure'\nexit 1")
@@ -469,7 +470,7 @@ func TestSuccessfulUserMergeToRefRequest(t *testing.T) {
// Writes in existingTargetRef
beforeRefreshCommitSha := "a5391128b0ef5d21df5dd23d98557f4ef12fae20"
- out, err := exec.Command("git", "-C", testRepoPath, "update-ref", string(existingTargetRef), beforeRefreshCommitSha).CombinedOutput()
+ out, err := exec.Command(command.GitPath(), "-C", testRepoPath, "update-ref", string(existingTargetRef), beforeRefreshCommitSha).CombinedOutput()
require.NoError(t, err, "give an existing state to the target ref: %s", out)
testCases := []struct {
@@ -706,12 +707,12 @@ func TestUserMergeToRefIgnoreHooksRequest(t *testing.T) {
func prepareMergeBranch(t *testing.T, testRepoPath string) {
deleteBranch(testRepoPath, mergeBranchName)
- out, err := exec.Command("git", "-C", testRepoPath, "branch", mergeBranchName, mergeBranchHeadBefore).CombinedOutput()
+ out, err := exec.Command(command.GitPath(), "-C", testRepoPath, "branch", mergeBranchName, mergeBranchHeadBefore).CombinedOutput()
require.NoError(t, err, "set up branch to merge into: %s", out)
}
func deleteBranch(testRepoPath, branchName string) {
- exec.Command("git", "-C", testRepoPath, "branch", "-D", branchName).Run()
+ exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-D", branchName).Run()
}
// This error is used as a sentinel value
diff --git a/internal/service/operations/tags_test.go b/internal/service/operations/tags_test.go
index 549efdad3..42479cd2c 100644
--- a/internal/service/operations/tags_test.go
+++ b/internal/service/operations/tags_test.go
@@ -9,6 +9,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/git/log"
"gitlab.com/gitlab-org/gitaly/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag"
@@ -39,7 +40,7 @@ func TestSuccessfulUserDeleteTagRequest(t *testing.T) {
tagNameInput := "to-be-deleted-soon-tag"
- defer exec.Command("git", "-C", testRepoPath, "tag", "-d", tagNameInput).Run()
+ defer exec.Command(command.GitPath(), "-C", testRepoPath, "tag", "-d", tagNameInput).Run()
testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "tag", tagNameInput)
@@ -84,7 +85,7 @@ func testSuccessfulGitHooksForUserDeleteTagRequest(t *testing.T, ctx context.Con
defer cleanupFn()
tagNameInput := "to-be-déleted-soon-tag"
- defer exec.Command("git", "-C", testRepoPath, "tag", "-d", tagNameInput).Run()
+ defer exec.Command(command.GitPath(), "-C", testRepoPath, "tag", "-d", tagNameInput).Run()
request := &gitalypb.UserDeleteTagRequest{
Repository: testRepo,
@@ -195,7 +196,7 @@ func TestSuccessfulUserCreateTagRequest(t *testing.T) {
require.NoError(t, err, "error from calling RPC")
require.Empty(t, response.PreReceiveError, "PreReceiveError must be empty, signalling the push was accepted")
- defer exec.Command("git", "-C", testRepoPath, "tag", "-d", inputTagName).Run()
+ defer exec.Command(command.GitPath(), "-C", testRepoPath, "tag", "-d", inputTagName).Run()
id := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "rev-parse", inputTagName)
testCase.expectedTag.Id = text.ChompBytes(id)
@@ -241,7 +242,7 @@ func testSuccessfulGitHooksForUserCreateTagRequest(t *testing.T, ctx context.Con
for _, hookName := range GitlabHooks {
t.Run(hookName, func(t *testing.T) {
- defer exec.Command("git", "-C", testRepoPath, "tag", "-d", tagName).Run()
+ defer exec.Command(command.GitPath(), "-C", testRepoPath, "tag", "-d", tagName).Run()
hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName)
defer cleanup()
@@ -329,7 +330,7 @@ func testFailedUserDeleteTagDueToHooks(t *testing.T, ctx context.Context) {
tagNameInput := "to-be-deleted-soon-tag"
testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "tag", tagNameInput)
- defer exec.Command("git", "-C", testRepoPath, "tag", "-d", tagNameInput).Run()
+ defer exec.Command(command.GitPath(), "-C", testRepoPath, "tag", "-d", tagNameInput).Run()
request := &gitalypb.UserDeleteTagRequest{
Repository: testRepo,
diff --git a/internal/service/ref/refs_test.go b/internal/service/ref/refs_test.go
index cb98c6205..72c5070b2 100644
--- a/internal/service/ref/refs_test.go
+++ b/internal/service/ref/refs_test.go
@@ -13,6 +13,7 @@ import (
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/internal/git/log"
"gitlab.com/gitlab-org/gitaly/internal/git/updateref"
@@ -770,7 +771,7 @@ func TestFindAllTagNestedTags(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
tags := bytes.NewReader(testhelper.MustRunCommand(t, nil, "git", "-C", testRepoCopyPath, "tag"))
- testhelper.MustRunCommand(t, tags, "xargs", "git", "-C", testRepoCopyPath, "tag", "-d")
+ testhelper.MustRunCommand(t, tags, "xargs", command.GitPath(), "-C", testRepoCopyPath, "tag", "-d")
batch, err := catfile.New(ctx, testRepoCopy)
require.NoError(t, err)
@@ -1756,7 +1757,7 @@ func TestFindTagNestedTag(t *testing.T) {
t.Run(tc.description, func(t *testing.T) {
tags := bytes.NewReader(testhelper.MustRunCommand(t, nil, "git", "-C", testRepoCopyPath, "tag"))
- testhelper.MustRunCommand(t, tags, "xargs", "git", "-C", testRepoCopyPath, "tag", "-d")
+ testhelper.MustRunCommand(t, tags, "xargs", command.GitPath(), "-C", testRepoCopyPath, "tag", "-d")
batch, err := catfile.New(ctx, testRepoCopy)
require.NoError(t, err)
diff --git a/internal/service/repository/calculate_checksum_test.go b/internal/service/repository/calculate_checksum_test.go
index 450127165..949c403b3 100644
--- a/internal/service/repository/calculate_checksum_test.go
+++ b/internal/service/repository/calculate_checksum_test.go
@@ -7,6 +7,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -28,7 +29,7 @@ func TestSuccessfulCalculateChecksum(t *testing.T) {
require.NoError(t, os.MkdirAll(path.Join(testRepoPath, d), 0755))
}
require.NoError(t, exec.Command("cp", "testdata/checksum-test-packed-refs", path.Join(testRepoPath, "packed-refs")).Run())
- require.NoError(t, exec.Command("git", "-C", testRepoPath, "symbolic-ref", "HEAD", "refs/heads/feature").Run())
+ require.NoError(t, exec.Command(command.GitPath(), "-C", testRepoPath, "symbolic-ref", "HEAD", "refs/heads/feature").Run())
request := &gitalypb.CalculateChecksumRequest{Repository: testRepo}
testCtx, cancelCtx := testhelper.Context()
diff --git a/internal/service/repository/cleanup_test.go b/internal/service/repository/cleanup_test.go
index 7b8256c17..d29aeb73a 100644
--- a/internal/service/repository/cleanup_test.go
+++ b/internal/service/repository/cleanup_test.go
@@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -239,7 +240,7 @@ func TestCleanupDisconnectedWorktrees(t *testing.T) {
if !pre2_20_0 {
err := exec.Command(
- "git",
+ command.GitPath(),
testhelper.AddWorktreeArgs(testRepoPath, worktreePath)...,
).Run()
require.Error(t, err,
diff --git a/internal/service/repository/redirecting_test_server_test.go b/internal/service/repository/redirecting_test_server_test.go
index f5a200488..3ae1e37d4 100644
--- a/internal/service/repository/redirecting_test_server_test.go
+++ b/internal/service/repository/redirecting_test_server_test.go
@@ -44,7 +44,7 @@ func TestRedirectingServerRedirects(t *testing.T) {
httpServerState, redirectingServer := StartRedirectingTestServer()
// we only test for redirection, this command can fail after that
- cmd := exec.Command("git", "-c", "http.followRedirects=true", "clone", "--bare", redirectingServer.URL, dir)
+ cmd := exec.Command(command.GitPath(), "-c", "http.followRedirects=true", "clone", "--bare", redirectingServer.URL, dir)
cmd.Env = append(command.GitEnv, cmd.Env...)
cmd.Run()
diff --git a/internal/service/repository/repack_test.go b/internal/service/repository/repack_test.go
index bd2ec0635..39d89d384 100644
--- a/internal/service/repository/repack_test.go
+++ b/internal/service/repository/repack_test.go
@@ -14,6 +14,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -89,7 +90,7 @@ func TestRepackLocal(t *testing.T) {
commiterArgs := []string{"-c", "user.name=Scrooge McDuck", "-c", "user.email=scrooge@mcduck.com"}
cmdArgs := append(commiterArgs, "-C", repoPath, "commit", "--allow-empty", "-m", "An empty commit")
- cmd := exec.Command("git", cmdArgs...)
+ cmd := exec.Command(command.GitPath(), cmdArgs...)
altObjectsDir := "./alt-objects"
altDirsCommit := testhelper.CreateCommitInAlternateObjectDirectory(t, repoPath, altObjectsDir, cmd)
diff --git a/internal/service/repository/search_files_test.go b/internal/service/repository/search_files_test.go
index ffb596196..e3738d0d4 100644
--- a/internal/service/repository/search_files_test.go
+++ b/internal/service/repository/search_files_test.go
@@ -11,6 +11,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -128,7 +129,7 @@ func TestSearchFilesByContentSuccessful(t *testing.T) {
ref: "many_files",
output: contentOutputLines,
skip: func(t *testing.T) {
- cmd := exec.Command("git", "-C", testRepoPath, "grep", "--perl-regexp", "(*LIMIT_MATCH=1)foobar", "many_files")
+ cmd := exec.Command(command.GitPath(), "-C", testRepoPath, "grep", "--perl-regexp", "(*LIMIT_MATCH=1)foobar", "many_files")
err := cmd.Run()
if exitError, ok := err.(*exec.ExitError); ok && exitError.ExitCode() == 128 {
t.Skip("Git does not seem to be compiled with support for PCRE2")
diff --git a/internal/service/repository/snapshot_test.go b/internal/service/repository/snapshot_test.go
index 8659b00b0..4802100fc 100644
--- a/internal/service/repository/snapshot_test.go
+++ b/internal/service/repository/snapshot_test.go
@@ -16,6 +16,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/archive"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/internal/helper"
@@ -127,7 +128,7 @@ func TestGetSnapshotWithDedupe(t *testing.T) {
const committerName = "Scrooge McDuck"
const committerEmail = "scrooge@mcduck.com"
- cmd := exec.Command("git", "-C", repoPath,
+ cmd := exec.Command(command.GitPath(), "-C", repoPath,
"-c", fmt.Sprintf("user.name=%s", committerName),
"-c", fmt.Sprintf("user.email=%s", committerEmail),
"commit", "--allow-empty", "-m", "An empty commit")
@@ -147,7 +148,7 @@ func TestGetSnapshotWithDedupe(t *testing.T) {
require.NoError(t, ioutil.WriteFile(alternatesPath, []byte(path.Join(repoPath, ".git", fmt.Sprintf("%s\n", alternateObjDir))), 0644))
// write another commit and ensure we can find it
- cmd = exec.Command("git", "-C", repoPath,
+ cmd = exec.Command(command.GitPath(), "-C", repoPath,
"-c", fmt.Sprintf("user.name=%s", committerName),
"-c", fmt.Sprintf("user.email=%s", committerEmail),
"commit", "--allow-empty", "-m", "Another empty commit")
@@ -203,7 +204,7 @@ func TestGetSnapshotWithDedupeSoftFailures(t *testing.T) {
committerName := "Scrooge McDuck"
committerEmail := "scrooge@mcduck.com"
- cmd := exec.Command("git", "-C", repoPath,
+ cmd := exec.Command(command.GitPath(), "-C", repoPath,
"-c", fmt.Sprintf("user.name=%s", committerName),
"-c", fmt.Sprintf("user.email=%s", committerEmail),
"commit", "--allow-empty", "-m", "An empty commit")
diff --git a/internal/service/ssh/receive_pack_test.go b/internal/service/ssh/receive_pack_test.go
index 059ed950b..ff48d20e3 100644
--- a/internal/service/ssh/receive_pack_test.go
+++ b/internal/service/ssh/receive_pack_test.go
@@ -15,6 +15,7 @@ import (
"github.com/golang/protobuf/jsonpb"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/config"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/hooks"
@@ -317,7 +318,7 @@ func sshPush(t *testing.T, cloneDetails SSHCloneDetails, serverSocketPath string
})
require.NoError(t, err)
- cmd := exec.Command("git", "-C", cloneDetails.LocalRepoPath, "push", "-v", "git@localhost:test/test.git", "master")
+ cmd := exec.Command(command.GitPath(), "-C", cloneDetails.LocalRepoPath, "push", "-v", "git@localhost:test/test.git", "master")
cmd.Env = []string{
fmt.Sprintf("GITALY_PAYLOAD=%s", payload),
fmt.Sprintf("GITALY_ADDRESS=%s", serverSocketPath),
diff --git a/internal/service/ssh/upload_archive_test.go b/internal/service/ssh/upload_archive_test.go
index 334e11864..d39f636f2 100644
--- a/internal/service/ssh/upload_archive_test.go
+++ b/internal/service/ssh/upload_archive_test.go
@@ -9,6 +9,7 @@ import (
"github.com/golang/protobuf/jsonpb"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -101,7 +102,7 @@ func TestUploadArchiveSuccess(t *testing.T) {
serverSocketPath, stop := runSSHServer(t)
defer stop()
- cmd := exec.Command("git", "archive", "master", "--remote=git@localhost:test/test.git")
+ cmd := exec.Command(command.GitPath(), "archive", "master", "--remote=git@localhost:test/test.git")
err := testArchive(t, serverSocketPath, testRepo, cmd)
require.NoError(t, err)
diff --git a/internal/service/ssh/upload_pack_test.go b/internal/service/ssh/upload_pack_test.go
index 351364418..5b147eedf 100644
--- a/internal/service/ssh/upload_pack_test.go
+++ b/internal/service/ssh/upload_pack_test.go
@@ -14,6 +14,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
promtest "github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
@@ -205,12 +206,12 @@ func TestUploadPackCloneSuccess(t *testing.T) {
deepen float64
}{
{
- cmd: exec.Command("git", "clone", "git@localhost:test/test.git", localRepoPath),
+ cmd: exec.Command(command.GitPath(), "clone", "git@localhost:test/test.git", localRepoPath),
desc: "full clone",
deepen: 0,
},
{
- cmd: exec.Command("git", "clone", "--depth", "1", "git@localhost:test/test.git", localRepoPath),
+ cmd: exec.Command(command.GitPath(), "clone", "--depth", "1", "git@localhost:test/test.git", localRepoPath),
desc: "shallow clone",
deepen: 1,
},
@@ -271,7 +272,7 @@ func TestUploadPackCloneWithPartialCloneFilter(t *testing.T) {
localPath := path.Join(testRepoRoot, fmt.Sprintf("gitlab-test-upload-pack-local-%s", tc.desc))
cmd := cloneCommand{
repository: testRepo,
- command: exec.Command("git", append(tc.cloneArgs, localPath)...),
+ command: exec.Command(command.GitPath(), append(tc.cloneArgs, localPath)...),
server: serverSocketPath,
}
err := cmd.execute(t)
@@ -298,11 +299,11 @@ func TestUploadPackCloneSuccessWithGitProtocol(t *testing.T) {
desc string
}{
{
- cmd: exec.Command("git", "clone", "git@localhost:test/test.git", localRepoPath),
+ cmd: exec.Command(command.GitPath(), "clone", "git@localhost:test/test.git", localRepoPath),
desc: "full clone",
},
{
- cmd: exec.Command("git", "clone", "--depth", "1", "git@localhost:test/test.git", localRepoPath),
+ cmd: exec.Command(command.GitPath(), "clone", "--depth", "1", "git@localhost:test/test.git", localRepoPath),
desc: "shallow clone",
},
}
@@ -335,7 +336,7 @@ func TestUploadPackCloneHideTags(t *testing.T) {
cmd := cloneCommand{
repository: testRepo,
- command: exec.Command("git", "clone", "--mirror", "git@localhost:test/test.git", localRepoPath),
+ command: exec.Command(command.GitPath(), "clone", "--mirror", "git@localhost:test/test.git", localRepoPath),
server: serverSocketPath,
gitConfig: "transfer.hideRefs=refs/tags",
}
@@ -360,7 +361,7 @@ func TestUploadPackCloneFailure(t *testing.T) {
StorageName: "foobar",
RelativePath: testRepo.GetRelativePath(),
},
- command: exec.Command("git", "clone", "git@localhost:test/test.git", localRepoPath),
+ command: exec.Command(command.GitPath(), "clone", "git@localhost:test/test.git", localRepoPath),
server: serverSocketPath,
}
err := cmd.execute(t)
diff --git a/internal/testhelper/commit.go b/internal/testhelper/commit.go
index d8199882b..3769f0b66 100644
--- a/internal/testhelper/commit.go
+++ b/internal/testhelper/commit.go
@@ -10,6 +10,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/helper/text"
)
@@ -80,7 +81,7 @@ func CreateCommitInAlternateObjectDirectory(t testing.TB, repoPath, altObjectsDi
t.Fatalf("stdout: %s, stderr: %s", output, stderr)
}
- cmd = exec.Command("git", "-C", repoPath, "rev-parse", "HEAD")
+ cmd = exec.Command(command.GitPath(), "-C", repoPath, "rev-parse", "HEAD")
cmd.Env = gitObjectEnv
currentHead, err := cmd.Output()
require.NoError(t, err)
diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go
index 16084860d..80db0ddf1 100644
--- a/internal/testhelper/testhelper.go
+++ b/internal/testhelper/testhelper.go
@@ -216,15 +216,17 @@ func MustRunCommand(t testing.TB, stdin io.Reader, name string, args ...string)
t.Helper()
}
- cmd := exec.Command(name, args...)
-
+ var cmd *exec.Cmd
if name == "git" {
+ cmd = exec.Command(command.GitPath(), 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",
)
+ } else {
+ cmd = exec.Command(name, args...)
}
if stdin != nil {
@@ -678,7 +680,7 @@ func GitObjectMustNotExist(t testing.TB, repoPath, sha string) {
}
func gitObjectExists(t testing.TB, repoPath, sha string, exists bool) {
- cmd := exec.Command("git", "-C", repoPath, "cat-file", "-e", sha)
+ cmd := exec.Command(command.GitPath(), "-C", repoPath, "cat-file", "-e", sha)
cmd.Env = []string{
"GIT_ALLOW_PROTOCOL=", // To prevent partial clone reaching remote repo over SSH
}