Skip to content

fix(core): respect .gitignore for tracked files in isGitIgnored (#703)#821

Merged
glittercowboy merged 1 commit intogsd-build:mainfrom
Tibsfox:fix/config-and-path-corrections
Mar 2, 2026
Merged

fix(core): respect .gitignore for tracked files in isGitIgnored (#703)#821
glittercowboy merged 1 commit intogsd-build:mainfrom
Tibsfox:fix/config-and-path-corrections

Conversation

@Tibsfox
Copy link
Contributor

@Tibsfox Tibsfox commented Feb 28, 2026

What This Fixes

When .planning/ files have been committed to a repo and .planning/ is later added to .gitignore, the isGitIgnored() function in core.cjs incorrectly reports them as "not ignored." This means the automatic commit_docs: false safety net — designed to prevent unwanted .planning/ commits — silently fails.

This is a subtle interaction between git's index and .gitignore that can catch people off guard. Once files enter git's tracked index, git check-ignore considers them "not ignored" regardless of what .gitignore says. It's standard git behavior, but it breaks the assumption that .gitignore entries are always respected.

The Fix

A one-word addition: --no-index on the git check-ignore call.

- execSync('git check-ignore -q -- ' + targetPath...
+ execSync('git check-ignore -q --no-index -- ' + targetPath...

The --no-index flag tells git to evaluate .gitignore rules without consulting the index, which matches what users expect: if .planning/ is in .gitignore, treat it as ignored regardless of tracking history.

Why It Matters

This is especially relevant for projects that started with commit_docs: true (the default) and later decided to stop committing planning docs. Without this fix, the transition is silent — .planning/ files keep getting committed even after adding them to .gitignore, and the auto-detection safety net that's supposed to catch this never triggers.

The issue reporter also noted this compounds with the auto-advance nesting behavior (#668/#686), where agents doing raw git add bypass the commit_docs config entirely. This fix addresses the isGitIgnored() detection half of that problem.

Test Plan

  • Project with .planning/ tracked + .planning/ in .gitignore: isGitIgnored should return true
  • Project with .planning/ untracked + .planning/ in .gitignore: isGitIgnored should return true (unchanged behavior)
  • Project with .planning/ tracked + .planning/ NOT in .gitignore: isGitIgnored should return false (unchanged behavior)

Recovery Note for Affected Users

If .planning/ files are already committed and you want to stop tracking them:

git rm -r --cached .planning/
git commit -m "chore: stop tracking .planning/ (now gitignored)"

Closes #703

🤖 Generated with Claude Code

…sd-build#703)

Without --no-index, git check-ignore only reports files as ignored if
they are untracked. Once .planning/ files enter git's index (e.g., from
an initial commit before .gitignore was set up), check-ignore returns
"not ignored" even when .gitignore explicitly lists .planning/.

This means the documented safety net — "if .planning/ is gitignored,
commit_docs is automatically false" — silently fails for any repo where
.planning/ was ever committed. The --no-index flag checks .gitignore
rules regardless of tracking state, matching user expectations.

Closes gsd-build#703

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

isGitIgnored() fails for tracked files — missing --no-index flag

2 participants