Skip to content

Commit b517b45

Browse files
wwwillchen-botwwwillchenclaudegithub-actions[bot]
authored
Fix gitAdd to skip staging files ignored by .gitignore (#2707)
## Summary - Add a pre-flight check in `gitAdd` to detect if a file is ignored by `.gitignore` before attempting to stage it - Skip staging ignored files gracefully with a debug log instead of throwing an error - This prevents errors when the AI attempts to stage files like `.env.local` that should remain untracked ## Test plan - [ ] Verify that staging a normal file still works correctly - [ ] Create a `.gitignore` file that ignores a test file (e.g., `test.ignored`) - [ ] Create the ignored file and attempt to stage it - [ ] Confirm the file is skipped without error and a debug message is logged 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/dyad-sh/dyad/pull/2707" target="_blank"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1"> <img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin"> </picture> </a> <!-- devin-review-badge-end --> --------- Co-authored-by: Will Chen <willchen90@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
1 parent ef4ec84 commit b517b45

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/ipc/utils/git_utils.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,29 @@ export async function gitAddAll({ path }: GitBaseParams): Promise<void> {
419419
export async function gitAdd({ path, filepath }: GitFileParams): Promise<void> {
420420
const normalizedFilepath = normalizePath(filepath);
421421
const settings = readSettings();
422+
423+
// Check if the file is ignored by .gitignore before attempting to stage.
424+
// This prevents errors when trying to stage files like .env.local.
425+
// Skip the check when filepath is "." (stage-all), as "." is not a meaningful
426+
// argument to git check-ignore and could incorrectly skip staging all files.
427+
if (normalizedFilepath !== ".") {
428+
let isIgnored = false;
429+
try {
430+
isIgnored = await gitIsIgnored({ path, filepath: normalizedFilepath });
431+
} catch (e) {
432+
logger.warn(
433+
`Failed to check if file '${normalizedFilepath}' is ignored, proceeding with staging`,
434+
e,
435+
);
436+
}
437+
if (isIgnored) {
438+
logger.debug(
439+
`Skipping staging of ignored file '${normalizedFilepath}' (file is in .gitignore)`,
440+
);
441+
return;
442+
}
443+
}
444+
422445
if (settings.enableNativeGit) {
423446
await execOrThrow(
424447
["add", "--", normalizedFilepath],

0 commit comments

Comments
 (0)