| 793 | } |
| 794 | |
| 795 | func GitAndRootDirs() (string, string, error) { |
| 796 | cmd, err := gitNoLFS("rev-parse", "--git-dir", "--show-toplevel") |
| 797 | if err != nil { |
| 798 | return "", "", errors.New(tr.Tr.Get("failed to find `git rev-parse --git-dir --show-toplevel`: %v", err)) |
| 799 | } |
| 800 | buf := &bytes.Buffer{} |
| 801 | cmd.Stderr = buf |
| 802 | |
| 803 | out, err := cmd.Output() |
| 804 | output := string(out) |
| 805 | if err != nil { |
| 806 | // If we got a fatal error, it's possible we're on a newer |
| 807 | // (2.24+) Git and we're not in a worktree, so fall back to just |
| 808 | // looking up the repo directory. |
| 809 | if lfserrors.ExitStatus(err) == 128 { |
| 810 | absGitDir, err := GitDir() |
| 811 | return absGitDir, "", err |
| 812 | } |
| 813 | return "", "", errors.New(tr.Tr.Get("failed to call `git rev-parse --git-dir --show-toplevel`: %q", buf.String())) |
| 814 | } |
| 815 | |
| 816 | paths := strings.Split(output, "\n") |
| 817 | pathLen := len(paths) |
| 818 | |
| 819 | if pathLen == 0 { |
| 820 | return "", "", errors.New(tr.Tr.Get("bad `git rev-parse` output: %q", output)) |
| 821 | } |
| 822 | |
| 823 | absGitDir, err := tools.CanonicalizePath(paths[0], false) |
| 824 | if err != nil { |
| 825 | return "", "", errors.New(tr.Tr.Get("error converting %q to absolute: %s", paths[0], err)) |
| 826 | } |
| 827 | |
| 828 | if pathLen == 1 || len(paths[1]) == 0 { |
| 829 | return absGitDir, "", nil |
| 830 | } |
| 831 | |
| 832 | absRootDir, err := tools.CanonicalizePath(paths[1], false) |
| 833 | return absGitDir, absRootDir, err |
| 834 | } |
| 835 | |
| 836 | func RootDir() (string, error) { |
| 837 | cmd, err := gitNoLFS("rev-parse", "--show-toplevel") |