From 3f252917972bf7ea6a408ea321d71be270d73a07 Mon Sep 17 00:00:00 2001 From: "Jacob Vosmaer (GitLab)" Date: Tue, 12 Sep 2017 01:17:29 +0000 Subject: Don't use 'bundle show' to find Linguist --- internal/linguist/linguist.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'internal/linguist') 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 } -- cgit v1.2.3