fix(commit): skip staging deletions for missing files when --files is explicit (#2014) (#2025)

When gsd-tools commit is invoked with --files and one of the listed files
does not exist on disk, the previous code called git rm --cached which
staged and committed a deletion. This silently removed tracked planning
files (STATE.md, ROADMAP.md) from the repository whenever they were
temporarily absent on disk.

Fix: when explicit --files are provided, skip files that do not exist
rather than staging their deletion. Only the default (.planning/ staging
path) retains the git rm --cached behavior so genuinely removed planning
files are not left dangling in the index.

Adds regression tests verifying that missing files in an explicit --files
list are never staged as deletions.
This commit is contained in:
Tom Boucher
2026-04-10 10:56:09 -04:00
committed by GitHub
parent 21d2bd039d
commit 0f77681df4
2 changed files with 111 additions and 2 deletions

View File

@@ -313,11 +313,19 @@ function cmdCommit(cwd, message, files, raw, amend, noVerify) {
}
// Stage files
const filesToStage = files && files.length > 0 ? files : ['.planning/'];
const explicitFiles = files && files.length > 0;
const filesToStage = explicitFiles ? files : ['.planning/'];
for (const file of filesToStage) {
const fullPath = path.join(cwd, file);
if (!fs.existsSync(fullPath)) {
// File was deleted/moved — stage the deletion
if (explicitFiles) {
// Caller passed an explicit --files list: missing files are skipped.
// Staging a deletion here would silently remove tracked planning files
// (e.g. STATE.md, ROADMAP.md) when they are temporarily absent (#2014).
continue;
}
// Default mode (staging all of .planning/): stage the deletion so
// removed planning files are not left dangling in the index.
execGit(cwd, ['rm', '--cached', '--ignore-unmatch', file]);
} else {
execGit(cwd, ['add', file]);