diff options
author | Pavlo Strokov <pstrokov@gitlab.com> | 2020-11-26 18:44:37 +0300 |
---|---|---|
committer | Pavlo Strokov <pstrokov@gitlab.com> | 2020-11-29 19:32:54 +0300 |
commit | 6cda774b5e8d89a37039924cce31d20736770836 (patch) | |
tree | e68e3d67bbe610f37d44ba191571212d4a80a4e5 /internal | |
parent | bbff75dd8e27ef30c9a179ec41bb3cd5a7f46dfd (diff) |
Removal of command.GitPath()
Function 'command.GitPath()' depends on the global 'config.Config' variable
and uses internal call to change the state of it in case it is not
yet initialized properly. To break this dependency we remove the function
and replaces it with direct access to the configured value.
It could be set from the config.toml file or from env using GITALY_TESTING_GIT_BINARY.
If none used the value will be resolved from the system.
In the tests the value is set on the configuration stage and point to the temporary
directory.
Part of: https://gitlab.com/gitlab-org/gitaly/-/issues/2699
Diffstat (limited to 'internal')
33 files changed, 79 insertions, 102 deletions
diff --git a/internal/command/command.go b/internal/command/command.go index 5373853b7..7ba78459c 100644 --- a/internal/command/command.go +++ b/internal/command/command.go @@ -17,7 +17,6 @@ import ( "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "github.com/opentracing/opentracing-go" "github.com/sirupsen/logrus" - "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" "gitlab.com/gitlab-org/labkit/tracing" ) @@ -127,20 +126,6 @@ func (c *Command) Wait() error { return c.waitError } -// GitPath returns the path to the `git` binary. See `SetGitPath` for details -// on how this is set -func GitPath() string { - if config.Config.Git.BinPath == "" { - // This shouldn't happen outside of testing, SetGitPath should be called by - // main.go to ensure correctness of the configuration on start-up. - if err := config.Config.SetGitPath(); err != nil { - logrus.Fatal(err) // Bail out. - } - } - - return config.Config.Git.BinPath -} - var wg = &sync.WaitGroup{} // WaitAllDone waits for all commands started by the command package to diff --git a/internal/git/gittest/http_server.go b/internal/git/gittest/http_server.go index 25ff78f08..c578ad5ca 100644 --- a/internal/git/gittest/http_server.go +++ b/internal/git/gittest/http_server.go @@ -11,6 +11,7 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/command" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" ) // RemoteUploadPackServer implements two HTTP routes for git-upload-pack by copying stdin and stdout into and out of the git upload-pack command @@ -30,7 +31,7 @@ func RemoteUploadPackServer(ctx context.Context, t *testing.T, repoName, httpTok } defer r.Body.Close() - cmd, err := command.New(ctx, exec.Command(command.GitPath(), "-C", repoPath, "upload-pack", "--stateless-rpc", "."), reader, w, nil) + cmd, err := command.New(ctx, exec.Command(config.Config.Git.BinPath, "-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 +45,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(command.GitPath(), "-C", repoPath, "upload-pack", "--advertise-refs", "."), nil, w, nil) + cmd, err := command.New(ctx, exec.Command(config.Config.Git.BinPath, "-C", repoPath, "upload-pack", "--advertise-refs", "."), nil, w, nil) require.NoError(t, err) require.NoError(t, cmd.Wait()) default: diff --git a/internal/git/repository_test.go b/internal/git/repository_test.go index 84d802ef3..0720c0af9 100644 --- a/internal/git/repository_test.go +++ b/internal/git/repository_test.go @@ -14,7 +14,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -482,7 +481,7 @@ func TestLocalRepository_FetchRemote(t *testing.T) { testRepo, testRepoPath, cleanup := testhelper.InitBareRepo(t) - cmd := exec.Command(command.GitPath(), "-C", testRepoPath, "remote", "add", remote, remoteRepoPath) + cmd := exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "remote", "add", remote, remoteRepoPath) err := cmd.Run() if err != nil { cleanup() diff --git a/internal/git2go/apply_test.go b/internal/git2go/apply_test.go index 1744432b6..fe12d603d 100644 --- a/internal/git2go/apply_test.go +++ b/internal/git2go/apply_test.go @@ -8,7 +8,6 @@ import ( "time" "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/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" @@ -19,7 +18,7 @@ func TestExecutor_Apply(t *testing.T) { defer clean() repo := git.NewRepository(pbRepo) - executor := New(filepath.Join(config.Config.BinDir, "gitaly-git2go"), command.GitPath()) + executor := New(filepath.Join(config.Config.BinDir, "gitaly-git2go"), config.Config.Git.BinPath) ctx, cancel := testhelper.Context() defer cancel() diff --git a/internal/git2go/commit_test.go b/internal/git2go/commit_test.go index 0fbe24bd7..215cc59da 100644 --- a/internal/git2go/commit_test.go +++ b/internal/git2go/commit_test.go @@ -13,7 +13,6 @@ import ( "time" "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/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" @@ -64,7 +63,7 @@ func TestExecutor_Commit(t *testing.T) { updatedFile, err := repo.WriteBlob(ctx, "file", bytes.NewBufferString("updated")) require.NoError(t, err) - executor := New(filepath.Join(config.Config.BinDir, "gitaly-git2go"), command.GitPath()) + executor := New(filepath.Join(config.Config.BinDir, "gitaly-git2go"), config.Config.Git.BinPath) for _, tc := range []struct { desc string diff --git a/internal/gitaly/linguist/linguist.go b/internal/gitaly/linguist/linguist.go index 9d92e05b7..25cc3f840 100644 --- a/internal/gitaly/linguist/linguist.go +++ b/internal/gitaly/linguist/linguist.go @@ -33,8 +33,8 @@ type Language struct { type ByteCountPerLanguage map[string]uint64 // Stats returns the repository's language stats as reported by 'git-linguist'. -func Stats(ctx context.Context, repoPath string, commitID string) (ByteCountPerLanguage, error) { - cmd, err := startGitLinguist(ctx, repoPath, commitID, "stats") +func Stats(ctx context.Context, cfg config.Cfg, repoPath string, commitID string) (ByteCountPerLanguage, error) { + cmd, err := startGitLinguist(ctx, cfg, repoPath, commitID, "stats") if err != nil { return nil, err } @@ -73,7 +73,7 @@ func LoadColors(cfg *config.Cfg) error { return json.NewDecoder(jsonReader).Decode(&colorMap) } -func startGitLinguist(ctx context.Context, repoPath string, commitID string, linguistCommand string) (*command.Command, error) { +func startGitLinguist(ctx context.Context, cfg config.Cfg, repoPath string, commitID string, linguistCommand string) (*command.Command, error) { bundle, err := exec.LookPath("bundle") if err != nil { return nil, err @@ -97,7 +97,7 @@ func startGitLinguist(ctx context.Context, repoPath string, commitID string, lin // Git's directory to PATH. But as our internal command interface will // overwrite PATH even if we pass it in here, we need to work around it // and instead execute the command with `env PATH=$GITDIR:$PATH`. - gitDir := filepath.Dir(command.GitPath()) + gitDir := filepath.Dir(cfg.Git.BinPath) if path, ok := os.LookupEnv("PATH"); ok && gitDir != "." { args = append([]string{ "env", fmt.Sprintf("PATH=%s:%s", gitDir, path), diff --git a/internal/gitaly/linguist/linguist_test.go b/internal/gitaly/linguist/linguist_test.go index 72037bd75..dfb253ff5 100644 --- a/internal/gitaly/linguist/linguist_test.go +++ b/internal/gitaly/linguist/linguist_test.go @@ -28,7 +28,7 @@ func TestStatsUnmarshalJSONError(t *testing.T) { // When an error occurs, this used to trigger JSON marshelling of a plain string // the new behaviour shouldn't do that, and return an command error - _, err := Stats(ctx, "/var/empty", "deadbeef") + _, err := Stats(ctx, config.Config, "/var/empty", "deadbeef") require.Error(t, err) _, ok := err.(*json.SyntaxError) diff --git a/internal/gitaly/rubyserver/rubyserver.go b/internal/gitaly/rubyserver/rubyserver.go index c796a408a..a56179161 100644 --- a/internal/gitaly/rubyserver/rubyserver.go +++ b/internal/gitaly/rubyserver/rubyserver.go @@ -85,7 +85,7 @@ func (s *Server) start() error { env := append( os.Environ(), - "GITALY_RUBY_GIT_BIN_PATH="+command.GitPath(), + "GITALY_RUBY_GIT_BIN_PATH="+cfg.Git.BinPath, fmt.Sprintf("GITALY_RUBY_WRITE_BUFFER_SIZE=%d", streamio.WriteBufferSize), fmt.Sprintf("GITALY_RUBY_MAX_COMMIT_OR_TAG_MESSAGE_SIZE=%d", helper.MaxCommitOrTagMessageSize), "GITALY_RUBY_GITALY_BIN_DIR="+cfg.BinDir, diff --git a/internal/gitaly/service/blob/lfs_pointers_test.go b/internal/gitaly/service/blob/lfs_pointers_test.go index 7d1580b13..587903f8d 100644 --- a/internal/gitaly/service/blob/lfs_pointers_test.go +++ b/internal/gitaly/service/blob/lfs_pointers_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/internal/command" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -138,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(command.GitPath(), cmdArgs...) + cmd := exec.Command(config.Config.Git.BinPath, 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/gitaly/service/commit/find_commits_test.go b/internal/gitaly/service/commit/find_commits_test.go index 39e76abfb..a0d777a2c 100644 --- a/internal/gitaly/service/commit/find_commits_test.go +++ b/internal/gitaly/service/commit/find_commits_test.go @@ -11,7 +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/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -379,7 +379,7 @@ func TestSuccessfulFindCommitsRequestWithAltGitObjectDirs(t *testing.T) { testRepoCopy, testRepoCopyPath, cleanupFn := testhelper.NewTestRepoWithWorktree(t) defer cleanupFn() - cmd := exec.Command(command.GitPath(), "-C", testRepoCopyPath, + cmd := exec.Command(config.Config.Git.BinPath, "-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/gitaly/service/commit/isancestor_test.go b/internal/gitaly/service/commit/isancestor_test.go index f63b422a8..2ef08e60a 100644 --- a/internal/gitaly/service/commit/isancestor_test.go +++ b/internal/gitaly/service/commit/isancestor_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/internal/command" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -191,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(command.GitPath(), "-C", testRepoCopyPath, + cmd := exec.Command(config.Config.Git.BinPath, "-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/gitaly/service/commit/languages.go b/internal/gitaly/service/commit/languages.go index ce08b0534..5fd9fa743 100644 --- a/internal/gitaly/service/commit/languages.go +++ b/internal/gitaly/service/commit/languages.go @@ -47,7 +47,7 @@ func (s *server) CommitLanguages(ctx context.Context, req *gitalypb.CommitLangua if err != nil { return nil, err } - stats, err := linguist.Stats(ctx, repoPath, commitID) + stats, err := linguist.Stats(ctx, s.cfg, repoPath, commitID) if err != nil { return nil, err } diff --git a/internal/gitaly/service/commit/server.go b/internal/gitaly/service/commit/server.go index d36c6c3e6..3a923fc73 100644 --- a/internal/gitaly/service/commit/server.go +++ b/internal/gitaly/service/commit/server.go @@ -1,6 +1,7 @@ package commit import ( + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/gitaly/service/ref" "gitlab.com/gitlab-org/gitaly/internal/storage" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -8,6 +9,7 @@ import ( type server struct { locator storage.Locator + cfg config.Cfg } var ( @@ -15,6 +17,6 @@ var ( ) // NewServer creates a new instance of a grpc CommitServiceServer -func NewServer(locator storage.Locator) gitalypb.CommitServiceServer { - return &server{locator: locator} +func NewServer(cfg config.Cfg, locator storage.Locator) gitalypb.CommitServiceServer { + return &server{cfg: cfg, locator: locator} } diff --git a/internal/gitaly/service/commit/testhelper_test.go b/internal/gitaly/service/commit/testhelper_test.go index 37120b132..b2e8f6b16 100644 --- a/internal/gitaly/service/commit/testhelper_test.go +++ b/internal/gitaly/service/commit/testhelper_test.go @@ -33,7 +33,7 @@ func startTestServices(t testing.TB) (*grpc.Server, string) { t.Fatal("failed to start server") } - gitalypb.RegisterCommitServiceServer(server, NewServer(config.NewLocator(config.Config))) + gitalypb.RegisterCommitServiceServer(server, NewServer(config.Config, config.NewLocator(config.Config))) reflection.Register(server) go server.Serve(listener) diff --git a/internal/gitaly/service/operations/branches_test.go b/internal/gitaly/service/operations/branches_test.go index bff46b79a..8bc2bdbba 100644 --- a/internal/gitaly/service/operations/branches_test.go +++ b/internal/gitaly/service/operations/branches_test.go @@ -10,7 +10,6 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/client" - "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/git/log" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" gitalyhook "gitlab.com/gitlab-org/gitaly/internal/gitaly/hook" @@ -85,7 +84,7 @@ func testSuccessfulCreateBranchRequest(t *testing.T, ctx context.Context) { response, err := client.UserCreateBranch(ctx, request) if testCase.expectedBranch != nil { - defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-D", branchName).Run() + defer exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "branch", "-D", branchName).Run() } require.NoError(t, err) @@ -171,7 +170,7 @@ func testUserCreateBranchWithTransaction(t *testing.T, withRefTxHook bool) { for _, tc := range testcases { t.Run(tc.desc, func(t *testing.T) { - defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-D", "new-branch").Run() + defer exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "branch", "-D", "new-branch").Run() client, conn := newOperationClient(t, tc.address) defer conn.Close() @@ -235,7 +234,7 @@ func testSuccessfulGitHooksForUserCreateBranchRequest(t *testing.T, ctx context. for _, hookName := range GitlabHooks { t.Run(hookName, func(t *testing.T) { - defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-D", branchName).Run() + defer exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "branch", "-D", branchName).Run() hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName) defer cleanup() @@ -368,7 +367,7 @@ func testSuccessfulUserDeleteBranchRequest(t *testing.T, ctx context.Context) { branchNameInput := "to-be-deleted-soon-branch" - defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-d", branchNameInput).Run() + defer exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "branch", "-d", branchNameInput).Run() testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", branchNameInput) @@ -396,7 +395,7 @@ func TestSuccessfulGitHooksForUserDeleteBranchRequest(t *testing.T) { defer conn.Close() branchNameInput := "to-be-deleted-soon-branch" - defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-d", branchNameInput).Run() + defer exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "branch", "-d", branchNameInput).Run() request := &gitalypb.UserDeleteBranchRequest{ Repository: testRepo, @@ -493,7 +492,7 @@ func testFailedUserDeleteBranchDueToHooks(t *testing.T, ctx context.Context) { branchNameInput := "to-be-deleted-soon-branch" testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", branchNameInput) - defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-d", branchNameInput).Run() + defer exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "branch", "-d", branchNameInput).Run() request := &gitalypb.UserDeleteBranchRequest{ Repository: testRepo, @@ -595,7 +594,7 @@ func testBranchHookOutput(t *testing.T, ctx context.Context) { require.Equal(t, testCase.output, createResponse.PreReceiveError) testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", branchNameInput) - defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-d", branchNameInput).Run() + defer exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "branch", "-d", branchNameInput).Run() deleteResponse, err := client.UserDeleteBranch(ctx, deleteRequest) require.NoError(t, err) diff --git a/internal/gitaly/service/operations/merge_test.go b/internal/gitaly/service/operations/merge_test.go index 42df4b6de..e1e0a7759 100644 --- a/internal/gitaly/service/operations/merge_test.go +++ b/internal/gitaly/service/operations/merge_test.go @@ -12,8 +12,8 @@ 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/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/helper/text" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/internal/testhelper" @@ -338,7 +338,7 @@ func TestSuccessfulUserFFBranchRequest(t *testing.T) { } testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", "-f", branchName, "6d394385cf567f80a8fd85055db1ab4c5295806f") - defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-d", branchName).Run() + defer exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "branch", "-d", branchName).Run() resp, err := client.UserFFBranch(ctx, request) require.NoError(t, err) @@ -362,7 +362,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(command.GitPath(), "-C", testRepoPath, "branch", "-d", branchName).Run() + defer exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "branch", "-d", branchName).Run() testCases := []struct { desc string @@ -464,7 +464,7 @@ func TestFailedUserFFBranchDueToHooks(t *testing.T) { } testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", "-f", branchName, "6d394385cf567f80a8fd85055db1ab4c5295806f") - defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-d", branchName).Run() + defer exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "branch", "-d", branchName).Run() hookContent := []byte("#!/bin/sh\necho 'failure'\nexit 1") @@ -516,7 +516,7 @@ func testSuccessfulUserMergeToRefRequest(t *testing.T, ctx context.Context) { // Writes in existingTargetRef beforeRefreshCommitSha := "a5391128b0ef5d21df5dd23d98557f4ef12fae20" - out, err := exec.Command(command.GitPath(), "-C", testRepoPath, "update-ref", string(existingTargetRef), beforeRefreshCommitSha).CombinedOutput() + out, err := exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "update-ref", string(existingTargetRef), beforeRefreshCommitSha).CombinedOutput() require.NoError(t, err, "give an existing state to the target ref: %s", out) testCases := []struct { @@ -636,7 +636,7 @@ func testConflictsOnUserMergeToRefRequest(t *testing.T, ctx context.Context) { require.NoError(t, err) var buf bytes.Buffer - cmd := exec.Command(command.GitPath(), "-C", testRepoPath, "show", resp.CommitId) + cmd := exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "show", resp.CommitId) cmd.Stdout = &buf require.NoError(t, cmd.Run()) @@ -807,12 +807,12 @@ func prepareMergeBranch(t *testing.T, testRepoPath string) { func prepareMergeBranchWithHead(t *testing.T, testRepoPath, mergeBranchHead string) { deleteBranch(testRepoPath, mergeBranchName) - out, err := exec.Command(command.GitPath(), "-C", testRepoPath, "branch", mergeBranchName, mergeBranchHead).CombinedOutput() + out, err := exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "branch", mergeBranchName, mergeBranchHead).CombinedOutput() require.NoError(t, err, "set up branch to merge into: %s", out) } func deleteBranch(testRepoPath, branchName string) { - exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-D", branchName).Run() + exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "branch", "-D", branchName).Run() } // This error is used as a sentinel value diff --git a/internal/gitaly/service/operations/server.go b/internal/gitaly/service/operations/server.go index 3a5cd9d88..c366ba321 100644 --- a/internal/gitaly/service/operations/server.go +++ b/internal/gitaly/service/operations/server.go @@ -4,7 +4,6 @@ import ( "path/filepath" "gitlab.com/gitlab-org/gitaly/client" - "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/git2go" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/gitaly/hook" @@ -30,6 +29,6 @@ func NewServer(cfg config.Cfg, rs *rubyserver.Server, hookManager hook.Manager, hookManager: hookManager, locator: locator, conns: conns, - git2go: git2go.New(filepath.Join(cfg.BinDir, "gitaly-git2go"), command.GitPath()), + git2go: git2go.New(filepath.Join(cfg.BinDir, "gitaly-git2go"), cfg.Git.BinPath), } } diff --git a/internal/gitaly/service/operations/tags_test.go b/internal/gitaly/service/operations/tags_test.go index 5fe772e17..fc82a4189 100644 --- a/internal/gitaly/service/operations/tags_test.go +++ b/internal/gitaly/service/operations/tags_test.go @@ -9,8 +9,8 @@ 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/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" @@ -32,7 +32,7 @@ func TestSuccessfulUserDeleteTagRequest(t *testing.T) { tagNameInput := "to-be-deleted-soon-tag" - defer exec.Command(command.GitPath(), "-C", testRepoPath, "tag", "-d", tagNameInput).Run() + defer exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "tag", "-d", tagNameInput).Run() testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "tag", tagNameInput) @@ -60,7 +60,7 @@ func TestSuccessfulGitHooksForUserDeleteTagRequest(t *testing.T) { defer cleanupFn() tagNameInput := "to-be-déleted-soon-tag" - defer exec.Command(command.GitPath(), "-C", testRepoPath, "tag", "-d", tagNameInput).Run() + defer exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "tag", "-d", tagNameInput).Run() ctx, cancel := testhelper.Context() defer cancel() @@ -105,7 +105,7 @@ abort 'cat-file failed' unless $?.success? unless out.chomp == ARGV[0] abort "error: expected #{ARGV[0]} object, got #{out}" -end`, command.GitPath()) +end`, config.Config.Git.BinPath) dir, cleanup := testhelper.TempDir(t) hookPath := filepath.Join(dir, "pre-receive") @@ -130,7 +130,7 @@ abort 'cat-file failed' unless $?.success? unless out.chomp == expected_object_type abort "error: expected #{expected_object_type} object, got #{out}" -end`, command.GitPath()) +end`, config.Config.Git.BinPath) dir, cleanup := testhelper.TempDir(t) hookPath := filepath.Join(dir, "pre-receive") @@ -221,7 +221,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(command.GitPath(), "-C", testRepoPath, "tag", "-d", inputTagName).Run() + defer exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "tag", "-d", inputTagName).Run() id := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "rev-parse", inputTagName) testCase.expectedTag.Id = text.ChompBytes(id) @@ -265,7 +265,7 @@ func testSuccessfulGitHooksForUserCreateTagRequest(t *testing.T, ctx context.Con for _, hookName := range GitlabHooks { t.Run(hookName, func(t *testing.T) { - defer exec.Command(command.GitPath(), "-C", testRepoPath, "tag", "-d", tagName).Run() + defer exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "tag", "-d", tagName).Run() hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName) defer cleanup() @@ -353,7 +353,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(command.GitPath(), "-C", testRepoPath, "tag", "-d", tagNameInput).Run() + defer exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "tag", "-d", tagNameInput).Run() request := &gitalypb.UserDeleteTagRequest{ Repository: testRepo, @@ -580,7 +580,7 @@ func TestTagHookOutput(t *testing.T) { require.False(t, createResponse.Exists) require.Equal(t, testCase.output, createResponse.PreReceiveError) - defer exec.Command(command.GitPath(), "-C", testRepoPath, "tag", "-d", tagNameInput).Run() + defer exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "tag", "-d", tagNameInput).Run() testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "tag", tagNameInput) deleteResponse, err := client.UserDeleteTag(ctx, deleteRequest) diff --git a/internal/gitaly/service/operations/testhelper_test.go b/internal/gitaly/service/operations/testhelper_test.go index 3327d70cc..53b5b2406 100644 --- a/internal/gitaly/service/operations/testhelper_test.go +++ b/internal/gitaly/service/operations/testhelper_test.go @@ -93,7 +93,7 @@ func runOperationServiceServerWithRubyServer(t *testing.T, ruby *rubyserver.Serv gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hook.NewServer(config.Config, hookManager)) gitalypb.RegisterRepositoryServiceServer(srv.GrpcServer(), repository.NewServer(config.Config, ruby, locator, config.Config.GitalyInternalSocketPath())) gitalypb.RegisterRefServiceServer(srv.GrpcServer(), ref.NewServer(locator)) - gitalypb.RegisterCommitServiceServer(srv.GrpcServer(), commit.NewServer(locator)) + gitalypb.RegisterCommitServiceServer(srv.GrpcServer(), commit.NewServer(config.Config, locator)) gitalypb.RegisterSSHServiceServer(srv.GrpcServer(), ssh.NewServer(locator)) reflection.Register(srv.GrpcServer()) diff --git a/internal/gitaly/service/ref/refs_test.go b/internal/gitaly/service/ref/refs_test.go index 1c2f66431..f9e960dc3 100644 --- a/internal/gitaly/service/ref/refs_test.go +++ b/internal/gitaly/service/ref/refs_test.go @@ -13,7 +13,6 @@ 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" @@ -715,7 +714,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", command.GitPath(), "-C", testRepoCopyPath, "tag", "-d") + testhelper.MustRunCommand(t, tags, "xargs", config.Config.Git.BinPath, "-C", testRepoCopyPath, "tag", "-d") batch, err := catfile.New(ctx, testRepoCopy) require.NoError(t, err) @@ -1646,7 +1645,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", command.GitPath(), "-C", testRepoCopyPath, "tag", "-d") + testhelper.MustRunCommand(t, tags, "xargs", config.Config.Git.BinPath, "-C", testRepoCopyPath, "tag", "-d") batch, err := catfile.New(ctx, testRepoCopy) require.NoError(t, err) diff --git a/internal/gitaly/service/register.go b/internal/gitaly/service/register.go index 761752e1e..37698f2e9 100644 --- a/internal/gitaly/service/register.go +++ b/internal/gitaly/service/register.go @@ -71,7 +71,7 @@ func RegisterAll(grpcServer *grpc.Server, cfg config.Cfg, rubyServer *rubyserver gitalypb.RegisterBlobServiceServer(grpcServer, blob.NewServer(rubyServer, locator)) gitalypb.RegisterCleanupServiceServer(grpcServer, cleanup.NewServer()) - gitalypb.RegisterCommitServiceServer(grpcServer, commit.NewServer(locator)) + gitalypb.RegisterCommitServiceServer(grpcServer, commit.NewServer(cfg, locator)) gitalypb.RegisterDiffServiceServer(grpcServer, diff.NewServer(locator)) gitalypb.RegisterNamespaceServiceServer(grpcServer, namespace.NewServer(locator)) gitalypb.RegisterOperationServiceServer(grpcServer, operations.NewServer(cfg, rubyServer, hookManager, locator, conns)) diff --git a/internal/gitaly/service/repository/calculate_checksum_test.go b/internal/gitaly/service/repository/calculate_checksum_test.go index 3e27c036a..7e9919a00 100644 --- a/internal/gitaly/service/repository/calculate_checksum_test.go +++ b/internal/gitaly/service/repository/calculate_checksum_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -31,7 +30,7 @@ func TestSuccessfulCalculateChecksum(t *testing.T) { require.NoError(t, os.MkdirAll(filepath.Join(testRepoPath, d), 0755)) } require.NoError(t, exec.Command("cp", "testdata/checksum-test-packed-refs", filepath.Join(testRepoPath, "packed-refs")).Run()) - require.NoError(t, exec.Command(command.GitPath(), "-C", testRepoPath, "symbolic-ref", "HEAD", "refs/heads/feature").Run()) + require.NoError(t, exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "symbolic-ref", "HEAD", "refs/heads/feature").Run()) request := &gitalypb.CalculateChecksumRequest{Repository: testRepo} testCtx, cancelCtx := testhelper.Context() diff --git a/internal/gitaly/service/repository/cleanup_test.go b/internal/gitaly/service/repository/cleanup_test.go index 434c269dc..1a7e11487 100644 --- a/internal/gitaly/service/repository/cleanup_test.go +++ b/internal/gitaly/service/repository/cleanup_test.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -233,7 +232,7 @@ func TestCleanupDisconnectedWorktrees(t *testing.T) { "disconnecting worktree by removing work tree at %s should succeed", worktreePath, ) - err = exec.Command(command.GitPath(), testhelper.AddWorktreeArgs(testRepoPath, worktreePath)...).Run() + err = exec.Command(config.Config.Git.BinPath, testhelper.AddWorktreeArgs(testRepoPath, worktreePath)...).Run() require.Error(t, err, "creating a new work tree at the same path as a disconnected work tree should fail") // cleanup should prune the disconnected worktree administrative files diff --git a/internal/gitaly/service/repository/redirecting_test_server_test.go b/internal/gitaly/service/repository/redirecting_test_server_test.go index 3ae1e37d4..8ade1d72e 100644 --- a/internal/gitaly/service/repository/redirecting_test_server_test.go +++ b/internal/gitaly/service/repository/redirecting_test_server_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/command" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" ) @@ -44,7 +45,7 @@ func TestRedirectingServerRedirects(t *testing.T) { httpServerState, redirectingServer := StartRedirectingTestServer() // we only test for redirection, this command can fail after that - cmd := exec.Command(command.GitPath(), "-c", "http.followRedirects=true", "clone", "--bare", redirectingServer.URL, dir) + cmd := exec.Command(config.Config.Git.BinPath, "-c", "http.followRedirects=true", "clone", "--bare", redirectingServer.URL, dir) cmd.Env = append(command.GitEnv, cmd.Env...) cmd.Run() diff --git a/internal/gitaly/service/repository/repack_test.go b/internal/gitaly/service/repository/repack_test.go index 39360ab92..7ee400bc7 100644 --- a/internal/gitaly/service/repository/repack_test.go +++ b/internal/gitaly/service/repository/repack_test.go @@ -13,7 +13,6 @@ 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/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" @@ -93,7 +92,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(command.GitPath(), cmdArgs...) + cmd := exec.Command(config.Config.Git.BinPath, cmdArgs...) altObjectsDir := "./alt-objects" altDirsCommit := testhelper.CreateCommitInAlternateObjectDirectory(t, repoPath, altObjectsDir, cmd) diff --git a/internal/gitaly/service/repository/snapshot_test.go b/internal/gitaly/service/repository/snapshot_test.go index 2866e68cf..4e185e5a9 100644 --- a/internal/gitaly/service/repository/snapshot_test.go +++ b/internal/gitaly/service/repository/snapshot_test.go @@ -14,7 +14,6 @@ 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/catfile" "gitlab.com/gitlab-org/gitaly/internal/gitaly/archive" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" @@ -127,7 +126,7 @@ func TestGetSnapshotWithDedupe(t *testing.T) { const committerName = "Scrooge McDuck" const committerEmail = "scrooge@mcduck.com" - cmd := exec.Command(command.GitPath(), "-C", repoPath, + cmd := exec.Command(config.Config.Git.BinPath, "-C", repoPath, "-c", fmt.Sprintf("user.name=%s", committerName), "-c", fmt.Sprintf("user.email=%s", committerEmail), "commit", "--allow-empty", "-m", "An empty commit") @@ -149,7 +148,7 @@ func TestGetSnapshotWithDedupe(t *testing.T) { require.NoError(t, ioutil.WriteFile(alternatesPath, []byte(filepath.Join(repoPath, ".git", fmt.Sprintf("%s\n", alternateObjDir))), 0644)) // write another commit and ensure we can find it - cmd = exec.Command(command.GitPath(), "-C", repoPath, + cmd = exec.Command(config.Config.Git.BinPath, "-C", repoPath, "-c", fmt.Sprintf("user.name=%s", committerName), "-c", fmt.Sprintf("user.email=%s", committerEmail), "commit", "--allow-empty", "-m", "Another empty commit") @@ -207,7 +206,7 @@ func TestGetSnapshotWithDedupeSoftFailures(t *testing.T) { committerName := "Scrooge McDuck" committerEmail := "scrooge@mcduck.com" - cmd := exec.Command(command.GitPath(), "-C", repoPath, + cmd := exec.Command(config.Config.Git.BinPath, "-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/gitaly/service/ssh/receive_pack_test.go b/internal/gitaly/service/ssh/receive_pack_test.go index 52b61a394..1e41502c6 100644 --- a/internal/gitaly/service/ssh/receive_pack_test.go +++ b/internal/gitaly/service/ssh/receive_pack_test.go @@ -14,7 +14,6 @@ import ( "github.com/golang/protobuf/jsonpb" "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/git/hooks" "gitlab.com/gitlab-org/gitaly/internal/git/objectpool" @@ -326,7 +325,7 @@ func sshPush(t *testing.T, cloneDetails SSHCloneDetails, serverSocketPath string }) require.NoError(t, err) - cmd := exec.Command(command.GitPath(), "-C", cloneDetails.LocalRepoPath, "push", "-v", "git@localhost:test/test.git", "master") + cmd := exec.Command(config.Config.Git.BinPath, "-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/gitaly/service/ssh/upload_archive_test.go b/internal/gitaly/service/ssh/upload_archive_test.go index 21a601e38..e57076524 100644 --- a/internal/gitaly/service/ssh/upload_archive_test.go +++ b/internal/gitaly/service/ssh/upload_archive_test.go @@ -9,7 +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/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -105,7 +105,7 @@ func TestUploadArchiveSuccess(t *testing.T) { serverSocketPath, stop := runSSHServer(t) defer stop() - cmd := exec.Command(command.GitPath(), "archive", "master", "--remote=git@localhost:test/test.git") + cmd := exec.Command(config.Config.Git.BinPath, "archive", "master", "--remote=git@localhost:test/test.git") testRepo, _, cleanup := testhelper.NewTestRepo(t) defer cleanup() diff --git a/internal/gitaly/service/ssh/upload_pack_test.go b/internal/gitaly/service/ssh/upload_pack_test.go index b544f278d..f47efa50c 100644 --- a/internal/gitaly/service/ssh/upload_pack_test.go +++ b/internal/gitaly/service/ssh/upload_pack_test.go @@ -15,9 +15,9 @@ 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/git/pktline" + "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" @@ -215,12 +215,12 @@ func TestUploadPackCloneSuccess(t *testing.T) { deepen float64 }{ { - cmd: exec.Command(command.GitPath(), "clone", "git@localhost:test/test.git", localRepoPath), + cmd: exec.Command(config.Config.Git.BinPath, "clone", "git@localhost:test/test.git", localRepoPath), desc: "full clone", deepen: 0, }, { - cmd: exec.Command(command.GitPath(), "clone", "--depth", "1", "git@localhost:test/test.git", localRepoPath), + cmd: exec.Command(config.Config.Git.BinPath, "clone", "--depth", "1", "git@localhost:test/test.git", localRepoPath), desc: "shallow clone", deepen: 1, }, @@ -332,7 +332,7 @@ func TestUploadPackCloneWithPartialCloneFilter(t *testing.T) { cmd := cloneCommand{ repository: testRepo, - command: exec.Command(command.GitPath(), append(tc.cloneArgs, localPath)...), + command: exec.Command(config.Config.Git.BinPath, append(tc.cloneArgs, localPath)...), server: serverSocketPath, } err := cmd.execute(t) @@ -354,11 +354,11 @@ func TestUploadPackCloneSuccessWithGitProtocol(t *testing.T) { desc string }{ { - cmd: exec.Command(command.GitPath(), "clone", "git@localhost:test/test.git", localRepoPath), + cmd: exec.Command(config.Config.Git.BinPath, "clone", "git@localhost:test/test.git", localRepoPath), desc: "full clone", }, { - cmd: exec.Command(command.GitPath(), "clone", "--depth", "1", "git@localhost:test/test.git", localRepoPath), + cmd: exec.Command(config.Config.Git.BinPath, "clone", "--depth", "1", "git@localhost:test/test.git", localRepoPath), desc: "shallow clone", }, } @@ -404,7 +404,7 @@ func TestUploadPackCloneHideTags(t *testing.T) { cmd := cloneCommand{ repository: testRepo, - command: exec.Command(command.GitPath(), "clone", "--mirror", "git@localhost:test/test.git", localRepoPath), + command: exec.Command(config.Config.Git.BinPath, "clone", "--mirror", "git@localhost:test/test.git", localRepoPath), server: serverSocketPath, gitConfig: "transfer.hideRefs=refs/tags", } @@ -433,7 +433,7 @@ func TestUploadPackCloneFailure(t *testing.T) { StorageName: "foobar", RelativePath: testRepo.GetRelativePath(), }, - command: exec.Command(command.GitPath(), "clone", "git@localhost:test/test.git", localRepoPath), + command: exec.Command(config.Config.Git.BinPath, "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 12cdbf0ee..d213b0d6d 100644 --- a/internal/testhelper/commit.go +++ b/internal/testhelper/commit.go @@ -10,7 +10,7 @@ import ( "testing" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/internal/command" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/helper/text" ) @@ -81,7 +81,7 @@ func CreateCommitInAlternateObjectDirectory(t testing.TB, repoPath, altObjectsDi t.Fatalf("stdout: %s, stderr: %s", output, stderr) } - cmd = exec.Command(command.GitPath(), "-C", repoPath, "rev-parse", "HEAD") + cmd = exec.Command(config.Config.Git.BinPath, "-C", repoPath, "rev-parse", "HEAD") cmd.Env = gitObjectEnv currentHead, err := cmd.Output() require.NoError(t, err) diff --git a/internal/testhelper/git_protocol.go b/internal/testhelper/git_protocol.go index ab9e74c6f..a5ab0952f 100644 --- a/internal/testhelper/git_protocol.go +++ b/internal/testhelper/git_protocol.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" ) @@ -22,7 +21,7 @@ func EnableGitProtocolV2Support(t *testing.T) func() { mkdir -p testdata env | grep ^GIT_PROTOCOL= >>"%s" exec "%s" "$@" -`, envPath, command.GitPath()) +`, envPath, config.Config.Git.BinPath) dir, cleanupDir := TempDir(t) diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go index e3da558a8..5f602e910 100644 --- a/internal/testhelper/testhelper.go +++ b/internal/testhelper/testhelper.go @@ -216,7 +216,7 @@ func MustRunCommand(t testing.TB, stdin io.Reader, name string, args ...string) var cmd *exec.Cmd if name == "git" { - cmd = exec.Command(command.GitPath(), args...) + cmd = exec.Command(config.Config.Git.BinPath, args...) cmd.Env = os.Environ() cmd.Env = append(command.GitEnv, cmd.Env...) cmd.Env = append(cmd.Env, @@ -809,7 +809,7 @@ func GitObjectMustNotExist(t testing.TB, repoPath, sha string) { } func gitObjectExists(t testing.TB, repoPath, sha string, exists bool) { - cmd := exec.Command(command.GitPath(), "-C", repoPath, "cat-file", "-e", sha) + cmd := exec.Command(config.Config.Git.BinPath, "-C", repoPath, "cat-file", "-e", sha) cmd.Env = []string{ "GIT_ALLOW_PROTOCOL=", // To prevent partial clone reaching remote repo over SSH } @@ -904,7 +904,7 @@ STDIN.each_line do |line| exit 1 unless new_object exit 1 unless system(*%%W[%s cat-file -e #{new_object}]) end -`, command.GitPath()) +`, config.Config.Git.BinPath) cleanup, err := WriteCustomHook(repoPath, "pre-receive", []byte(hook)) require.NoError(t, err) diff --git a/internal/testhelper/testserver/gitaly.go b/internal/testhelper/testserver/gitaly.go index 3e64e0bc3..143ad3c26 100644 --- a/internal/testhelper/testserver/gitaly.go +++ b/internal/testhelper/testserver/gitaly.go @@ -53,7 +53,7 @@ func RealGitaly(storages []config.Storage, authToken, internalSocketPath string) gitalyserver.NewServer(storages), repository.NewServer(config.Config, RubyServer, config.NewLocator(config.Config), internalSocketPath), internalgitaly.NewServer(config.Config.Storages), - commit.NewServer(config.NewLocator(config.Config)), + commit.NewServer(config.Config, config.NewLocator(config.Config)), health.NewServer(), } } |