plandex-ai/plandex · error

error getting git root: %s

Error message

error getting git root: %s

What it means

GetPaths runs `git rev-parse --show-toplevel` in a background goroutine to locate the repository root so it can resolve deleted-file paths from `git status`. This error is thrown when that git command fails to execute or exits non-zero, meaning the code could not determine the repo root even though IsGitRepo(baseDir) returned true moments earlier. It is sent over errCh and returned from GetPaths, aborting the whole path scan.

Source

Thrown at app/cli/fs/paths.go:55

	gitIgnoredDirs := map[string]bool{}

	isGitRepo := IsGitRepo(baseDir)

	errCh := make(chan error)
	var mu sync.Mutex
	numRoutines := 0

	deletedFiles := map[string]bool{}

	if isGitRepo {

		// Use git status to find deleted files
		numRoutines++
		go func() {
			cmd := exec.Command("git", "rev-parse", "--show-toplevel")
			output, err := cmd.Output()
			if err != nil {
				errCh <- fmt.Errorf("error getting git root: %s", err)
				return
			}
			repoRoot := strings.TrimSpace(string(output))

			cmd = exec.Command("git", "status", "--porcelain")
			cmd.Dir = baseDir
			out, err := cmd.Output()
			if err != nil {
				errCh <- fmt.Errorf("error getting git status: %s", err)
			}

			lines := strings.Split(string(out), "\n")

			for _, line := range lines {
				line = strings.TrimSpace(line)
				if strings.HasPrefix(line, "D ") {
					path := strings.TrimSpace(line[2:])
					absPath := filepath.Join(repoRoot, path)

View on GitHub (pinned to e2d772072e)

Solutions

  1. Verify `git rev-parse --show-toplevel` succeeds manually in baseDir; fix the repo (e.g. run `git config --global --add safe.directory <path>` if git reports dubious ownership).
  2. Ensure git is installed and on PATH in the environment where the CLI runs.
  3. Re-clone or repair a corrupt .git directory (e.g. `git init` again or restore from a clean copy).
  4. If the directory is genuinely not a git repo, run the tool from a valid repository so IsGitRepo and the git commands agree.

Example fix

// before (shell)
$ plandex load
error getting git root: fatal: detected dubious ownership in repository at '/repo'
// after (shell)
$ git config --global --add safe.directory /repo
$ plandex load
Defensive patterns

Strategy: validation

Validate before calling

out, err := exec.Command("git", "-C", baseDir, "rev-parse", "--show-toplevel").Output()
if err != nil {
	return fmt.Errorf("cannot resolve git root for %s: %w", baseDir, err)
}

Try / catch

if err := <-errCh; err != nil {
	if strings.Contains(err.Error(), "error getting git root") {
		// fall back to non-git path scanning or prompt user to fix repo
	}
}

Prevention

When it happens

Trigger: Calling GetPaths/GetProjectPaths on a directory that passed the IsGitRepo check but where `git rev-parse --show-toplevel` fails: e.g. the .git directory is corrupt or was deleted between the check and the call, git is not on PATH, or the git binary itself errors (e.g. dubious ownership detected by newer git versions).

Common situations: Running the CLI in a container or CI image where git is not installed or is a stripped-down binary; a repo owned by another user triggering git's 'detected dubious ownership' safe.directory error; a race where the repo was deleted/re-initialized mid-run; a corrupted .git directory.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/b9dbc689a074bf3c. Report an issue: GitHub.