plandex-ai/plandex · error

error checking for uncommitted changes for file %s | err: %v

Error message

error checking for uncommitted changes for file %s | err: %v, output: %s

What it means

GitFileHasUncommittedChanges runs `git status --porcelain <path>` and reports true if the output is non-empty. This error is returned only when the git command itself fails (non-zero exit), with the command output embedded. An empty or dirty file is a normal result, not an error.

Source

Thrown at app/cli/lib/git.go:197

		return fmt.Errorf("error resetting staged changes | err: %v, output: %s", err, string(res))
	}

	// Clean untracked files
	res, err = exec.Command("git", "clean", "-d", "-f").CombinedOutput()
	if err != nil {
		return fmt.Errorf("error cleaning untracked files | err: %v, output: %s", err, string(res))
	}

	return nil
}

func GitFileHasUncommittedChanges(path string) (bool, error) {
	gitMutex.Lock()
	defer gitMutex.Unlock()

	res, err := exec.Command("git", "status", "--porcelain", path).CombinedOutput()
	if err != nil {
		return false, fmt.Errorf("error checking for uncommitted changes for file %s | err: %v, output: %s", path, err, string(res))
	}

	return strings.TrimSpace(string(res)) != "", nil
}

func GitCheckoutFile(path string) error {
	gitMutex.Lock()
	defer gitMutex.Unlock()

	res, err := exec.Command("git", "checkout", path).CombinedOutput()
	if err != nil {
		log.Println("Error checking out file:", string(res))

		return fmt.Errorf("error checking out file %s | err: %v, output: %s", path, err, string(res))
	}

	return nil
}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Run `git rev-parse --show-toplevel` in the same cwd to confirm you are inside a repository.
  2. Check `which git` and install the git binary if it is missing.
  3. Inspect the `output:` field in the error for git's specific complaint (bad path, not a repo, etc.).
  4. Ensure the path passed is relative to the repo root or absolute but inside the repo.

Example fix

// before
ok, err := GitFileHasUncommittedChanges(path)
// after
if _, err := os.Stat(filepath.Join(dir, ".git")); err != nil {
    return fmt.Errorf("%s is not inside a git repository", dir)
}
ok, err := GitFileHasUncommittedChanges(path)
Defensive patterns

Strategy: validation

Validate before calling

func inGitRepo(dir string) bool {
    out, err := exec.Command("git", "-C", dir, "rev-parse", "--is-inside-work-tree").Output()
    return err == nil && strings.TrimSpace(string(out)) == "true"
}

Try / catch

dirty, err := GitFileHasUncommittedChanges(path)
if err != nil {
    if strings.Contains(err.Error(), "not a git repository") {
        return false, nil // treat as no changes outside a repo
    }
    return err
}

Prevention

When it happens

Trigger: Calling GitFileHasUncommittedChanges(path) when `git status --porcelain path` fails: git not installed/on PATH, path is outside any git repository, or git cannot resolve the pathspec.

Common situations: Invoking the check in a directory that is not a git checkout, checking a file that was never tracked inside a repo without a .git dir, missing git binary in a minimal container image.

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/c7e2638afa89e0ec. Report an issue: GitHub.