diff --git a/git/git.go b/git/git.go index d82f63c9a0f6a8a926c487fd131a49e298ec8282..02735cc5a418fe1dc27f5629ee68a554b9db6bc9 100644 --- a/git/git.go +++ b/git/git.go @@ -37,6 +37,15 @@ func Dir() (string, error) { } func HasFile(segments ...string) bool { + // The blessed way to resolve paths within git dir since Git 2.5.0 + output, err := gitOutput("rev-parse", "-q", "--git-path", filepath.Join(segments...)) + if err == nil && output[0] != "--git-path" { + if _, err := os.Stat(output[0]); err == nil { + return true + } + } + + // Fallback for older git versions dir, err := Dir() if err != nil { return false