diff options
Diffstat (limited to 'internal/linguist/linguist.go')
-rw-r--r-- | internal/linguist/linguist.go | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/internal/linguist/linguist.go b/internal/linguist/linguist.go index 42f8f0e4f..f2158a566 100644 --- a/internal/linguist/linguist.go +++ b/internal/linguist/linguist.go @@ -53,21 +53,30 @@ func Color(language string) string { // LoadColors loads the name->color map from the Linguist gem. func LoadColors() error { - // We can't use 'bundle show' because that sometimes prints garbage on - // its stdout. - rubyScript := `print Bundler.rubygems.find_name('github-linguist').first.full_gem_path` - cmd := exec.Command("bundle", "exec", "ruby", "-e", rubyScript) + linguistPathSymlink, err := ioutil.TempFile("", "gitaly-linguist-path") + if err != nil { + return err + } + defer os.Remove(linguistPathSymlink.Name()) + + if err := linguistPathSymlink.Close(); err != nil { + return err + } + + // We use a symlink because we cannot trust Bundler to not print garbage + // on its stdout. + rubyScript := `FileUtils.ln_sf(Bundler.rubygems.find_name('github-linguist').first.full_gem_path, ARGV.first)` + cmd := exec.Command("bundle", "exec", "ruby", "-rfileutils", "-e", rubyScript, linguistPathSymlink.Name()) cmd.Dir = config.Config.Ruby.Dir - linguistPath, err := cmd.Output() - if err != nil { + 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(string(linguistPath), "lib/linguist/languages.json")) + languageJSON, err := ioutil.ReadFile(path.Join(linguistPathSymlink.Name(), "lib/linguist/languages.json")) if err != nil { return err } |