diff --git a/git/git.go b/git/git.go index 817e5bd1..00f0196a 100644 --- a/git/git.go +++ b/git/git.go @@ -12,6 +12,7 @@ import ( "io/ioutil" "net/url" "os" + "os/exec" "path/filepath" "regexp" "strconv" @@ -604,6 +605,13 @@ func GitAndRootDirs() (string, string, error) { out, err := cmd.Output() output := string(out) if err != nil { + // If we got a fatal error, it's possible we're on a newer + // (2.24+) Git and we're not in a worktree, so fall back to just + // looking up the repo directory. + if e, ok := err.(*exec.ExitError); ok && e.ProcessState.ExitCode() == 128 { + absGitDir, err := GitDir() + return absGitDir, "", err + } return "", "", fmt.Errorf("failed to call git rev-parse --git-dir --show-toplevel: %q", buf.String()) }