()
| 857 | } |
| 858 | |
| 859 | func GitDir() (string, error) { |
| 860 | cmd, err := gitNoLFS("rev-parse", "--git-dir") |
| 861 | if err != nil { |
| 862 | // The %w format specifier is unique to fmt.Errorf(), so we |
| 863 | // do not pass it to tr.Tr.Get(). |
| 864 | return "", fmt.Errorf("%s: %w", tr.Tr.Get("failed to find `git rev-parse --git-dir`"), err) |
| 865 | } |
| 866 | buf := &bytes.Buffer{} |
| 867 | cmd.Stderr = buf |
| 868 | out, err := cmd.Output() |
| 869 | |
| 870 | if err != nil { |
| 871 | // The %w format specifier is unique to fmt.Errorf(), so we |
| 872 | // do not pass it to tr.Tr.Get(). |
| 873 | return "", fmt.Errorf("%s: %w %v: %v", tr.Tr.Get("failed to call `git rev-parse --git-dir`"), err, string(out), buf.String()) |
| 874 | } |
| 875 | path := strings.TrimSpace(string(out)) |
| 876 | return tools.CanonicalizePath(path, false) |
| 877 | } |
| 878 | |
| 879 | func GitCommonDir() (string, error) { |
| 880 | // Versions before 2.5.0 don't have the --git-common-dir option, since |
no test coverage detected