diff options
-rw-r--r-- | internal/command/command.go | 2 | ||||
-rw-r--r-- | internal/command/option.go | 8 | ||||
-rw-r--r-- | internal/git/command_factory.go | 2 | ||||
-rw-r--r-- | internal/gitaly/hook/custom.go | 2 | ||||
-rw-r--r-- | internal/gitaly/linguist/linguist.go | 2 |
5 files changed, 13 insertions, 3 deletions
diff --git a/internal/command/command.go b/internal/command/command.go index f7c1936c6..834360a75 100644 --- a/internal/command/command.go +++ b/internal/command/command.go @@ -204,6 +204,8 @@ func New(ctx context.Context, cmd *exec.Cmd, opts ...Option) (*Command, error) { cmdGitVersion: cfg.gitVersion, } + cmd.Dir = cfg.dir + // Export allowed environment variables as set in the Gitaly process. cmd.Env = AllowedEnvironment(os.Environ()) // Append environment variables explicitly requested by the caller. diff --git a/internal/command/option.go b/internal/command/option.go index d5ec59635..cca8e62f1 100644 --- a/internal/command/option.go +++ b/internal/command/option.go @@ -10,6 +10,7 @@ type config struct { stdin io.Reader stdout io.Writer stderr io.Writer + dir string environment []string finalizer func(*Command) @@ -56,6 +57,13 @@ func WithStderr(stderr io.Writer) Option { } } +// WithDir will set up the command to be ran in the specific directory. +func WithDir(dir string) Option { + return func(cfg *config) { + cfg.dir = dir + } +} + // WithEnvironment sets up environment variables that shall be set for the command. func WithEnvironment(environment []string) Option { return func(cfg *config) { diff --git a/internal/git/command_factory.go b/internal/git/command_factory.go index de4ee857e..5c1af29f7 100644 --- a/internal/git/command_factory.go +++ b/internal/git/command_factory.go @@ -392,7 +392,6 @@ func (cf *ExecCommandFactory) newCommand(ctx context.Context, repo repository.Gi env = append(env, execEnv.EnvironmentVariables...) execCommand := exec.Command(execEnv.BinaryPath, args...) - execCommand.Dir = dir cmdGitVersion, err := cf.GitVersion(ctx) if err != nil { @@ -401,6 +400,7 @@ func (cf *ExecCommandFactory) newCommand(ctx context.Context, repo repository.Gi command, err := command.New(ctx, execCommand, append( config.commandOpts, + command.WithDir(dir), command.WithEnvironment(env), command.WithCommandName("git", sc.Subcommand()), command.WithCgroup(cf.cgroupsManager, repo), diff --git a/internal/gitaly/hook/custom.go b/internal/gitaly/hook/custom.go index 2c819dd3e..525544bc0 100644 --- a/internal/gitaly/hook/custom.go +++ b/internal/gitaly/hook/custom.go @@ -67,8 +67,8 @@ func (m *GitLabHookManager) newCustomHooksExecutor(repo *gitalypb.Repository, ho for _, hookFile := range hookFiles { cmd := exec.Command(hookFile, args...) - cmd.Dir = repoPath c, err := command.New(ctx, cmd, + command.WithDir(repoPath), command.WithStdin(bytes.NewReader(stdinBytes)), command.WithStdout(stdout), command.WithStderr(stderr), diff --git a/internal/gitaly/linguist/linguist.go b/internal/gitaly/linguist/linguist.go index 2a1a92c60..226972fed 100644 --- a/internal/gitaly/linguist/linguist.go +++ b/internal/gitaly/linguist/linguist.go @@ -108,9 +108,9 @@ func (inst *Instance) startGitLinguist(ctx context.Context, repoPath string, com } cmd := exec.Command(bundle, "exec", "bin/gitaly-linguist", "--repository="+repoPath, "--commit="+commitID) - cmd.Dir = inst.cfg.Ruby.Dir internalCmd, err := command.New(ctx, cmd, + command.WithDir(inst.cfg.Ruby.Dir), command.WithEnvironment(env.AllowedRubyEnvironment(os.Environ())), command.WithCommandName("git-linguist", "stats"), ) |