diff options
Diffstat (limited to 'internal/linguist/linguist.go')
-rw-r--r-- | internal/linguist/linguist.go | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/internal/linguist/linguist.go b/internal/linguist/linguist.go index 0a0359626..64598373f 100644 --- a/internal/linguist/linguist.go +++ b/internal/linguist/linguist.go @@ -9,7 +9,6 @@ import ( "os" "os/exec" "path" - "strings" "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/config" @@ -54,17 +53,31 @@ func Color(language string) string { // LoadColors loads the name->color map from the Linguist gem. func LoadColors() error { - cmd := exec.Command("bundle", "show", "linguist") - cmd.Dir = config.Config.Ruby.Dir - linguistPath, err := cmd.Output() + tempFile, err := ioutil.TempFile("", "gitaly-linguist") if err != nil { + return err + } + defer os.Remove(tempFile.Name()) + + if err := tempFile.Close(); err != nil { + return err + } + + // Replace the tempfile with a symlink to the directory where + // github-linguist is installed. We don't write the path to stdout + // because Bundler sometimes writes garbage to stdout. + rubyScript := `FileUtils.ln_sf(Bundler.rubygems.find_name('github-linguist').first.full_gem_path, ARGV.first)` + cmd := exec.Command("bundle", "exec", "ruby", "-r", "fileutils", "-e", rubyScript, tempFile.Name()) + cmd.Dir = config.Config.Ruby.Dir + + if err := cmd.Run(); err != nil { if exitError, ok := err.(*exec.ExitError); ok { err = fmt.Errorf("%v; stderr: %q", exitError, exitError.Stderr) } return err } - languageJSON, err := ioutil.ReadFile(path.Join(strings.TrimSpace(string(linguistPath)), "lib/linguist/languages.json")) + languageJSON, err := ioutil.ReadFile(path.Join(tempFile.Name(), "lib/linguist/languages.json")) if err != nil { return err } |