gastownhall/beads · error

failed to untrack files: %w %s

Error message

failed to untrack files: %w
%s

What it means

FixTrackedRuntimeFiles removes runtime files from git tracking with 'git rm --cached --' while keeping local copies. If that git command fails, the combined error and git output are wrapped with this message so the user can see git's own complaint.

Source

Thrown at cmd/bd/doctor/tracked_runtime.go:253

		if err != nil {
			continue
		}

		if shouldFlagTrackedFile(rel) {
			toUntrack = append(toUntrack, line)
		}
	}

	if len(toUntrack) == 0 {
		return nil
	}

	// Untrack files (keeps local copies)
	args := append([]string{"rm", "--cached", "--"}, toUntrack...)
	cmd = exec.Command("git", args...) // #nosec G204 - args are constructed from known parts
	cmd.Dir = repoRoot
	if out, err := cmd.CombinedOutput(); err != nil {
		return fmt.Errorf("failed to untrack files: %w\n%s", err, string(out))
	}

	return nil
}

View on GitHub (pinned to 71377f2769)

Solutions

  1. Read the appended git output for the exact git error
  2. Run 'git rm --cached -- <file>' manually for the listed files to see the failure directly
  3. Ensure you are inside a git repository and no stale .git/index.lock exists (remove it if no git process is running)

Example fix

// before
out, err := cmd.CombinedOutput() // fatal: pathspec 'runtime.db' did not match
// after
if isTracked(repoRoot, f) { untrack(f) } // skip files git does not track
Defensive patterns

Strategy: validation

Validate before calling

func isTracked(repo, f string) bool {
    out, err := exec.Command("git", "-C", repo, "ls-files", "--error-unmatch", f).CombinedOutput()
    return err == nil && len(out) > 0
}
// only pass tracked files to FixTrackedRuntimeFiles

Try / catch

if err != nil && strings.Contains(err.Error(), "failed to untrack files") {
    log.Printf("git rm --cached failed: %s", gitOutput) // appended after \\n
}

Prevention

When it happens

Trigger: exec.Command("git", ["rm","--cached","--",files...]).CombinedOutput() returns an error: not a git repo, files not actually tracked, pathspec mismatches, or index.lock contention.

Common situations: Running the fix outside a git worktree (repoRoot wrong); runtime files already untracked; another git process holding index.lock; case-sensitivity pathspec mismatch on macOS/Windows.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/fbdfd162e9c85703. Report an issue: GitHub.