diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-08-19 16:05:58 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-08-20 14:20:19 +0300 |
commit | 489e4eace7fb09c42771e94e7fb2eee52f5de6c2 (patch) | |
tree | fa720cfe059e8b89a2cb685ec892621dc70a5fb9 /internal/linguist/linguist.go | |
parent | 8cf48086d19d1d53f535864c528a6c9888c99077 (diff) |
linguist: Use configured Git executable
When executing git-linguist, one of the first things it'll do is verify
whether it's running in a Git directory by executing `git rev-parse
--git-dir`. git-linguist doesn't allow specifying which Git executable
is executed here, so it'll always use the first one it finds in PATH,
which isn't necessarily the one configured in Gitaly's configuration.
Fix the issue by always prepending the configured Git executable's
directory to PATH previous to executing git-linguist. As our own command
interface will overwrite and PATH environment variables passed to it, we
need to use a hack here and specify the PATH variable by executing
git-linguist with `env PATH=$GITDIR:$PATH`.
Diffstat (limited to 'internal/linguist/linguist.go')
-rw-r--r-- | internal/linguist/linguist.go | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/internal/linguist/linguist.go b/internal/linguist/linguist.go index 252e36047..523fe9e6a 100644 --- a/internal/linguist/linguist.go +++ b/internal/linguist/linguist.go @@ -74,7 +74,32 @@ func LoadColors(cfg config.Cfg) error { } func startGitLinguist(ctx context.Context, repoPath string, commitID string, linguistCommand string) (*command.Command, error) { - cmd := exec.Command("bundle", "exec", "bin/ruby-cd", repoPath, "git-linguist", "--commit="+commitID, linguistCommand) + args := []string{ + "bundle", + "exec", + "bin/ruby-cd", + repoPath, + "git-linguist", + "--commit=" + commitID, + linguistCommand, + } + + // This is a horrible hack. git-linguist will execute `git rev-parse + // --git-dir` to check whether it is in a Git directory or not. We don't + // want to use the one provided by PATH, but instead the one specified + // via the configuration. git-linguist doesn't specify any way to choose + // a different Git implementation, so we need to prepend the configured + // 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 := path.Dir(command.GitPath()) + if path, ok := os.LookupEnv("PATH"); ok && gitDir != "." { + args = append([]string{ + "env", fmt.Sprintf("PATH=%s:%s", gitDir, path), + }, args...) + } + + cmd := exec.Command(args[0], args[1:]...) cmd.Dir = config.Config.Ruby.Dir internalCmd, err := command.New(ctx, cmd, nil, nil, nil, exportEnvironment()...) |