Unverified 提交 b517b457 authored 作者: wwwillchen-bot's avatar wwwillchen-bot 提交者: GitHub

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: 's avatarWill Chen <willchen90@gmail.com> Co-authored-by: 's avatarClaude Opus 4.5 <noreply@anthropic.com> Co-authored-by: 's avatarclaude[bot] <41898282+claude[bot]@users.noreply.github.com>
上级 ef4ec841
......@@ -419,6 +419,29 @@ export async function gitAddAll({ path }: GitBaseParams): Promise<void> {
export async function gitAdd({ path, filepath }: GitFileParams): Promise<void> {
const normalizedFilepath = normalizePath(filepath);
const settings = readSettings();
// Check if the file is ignored by .gitignore before attempting to stage.
// This prevents errors when trying to stage files like .env.local.
// Skip the check when filepath is "." (stage-all), as "." is not a meaningful
// argument to git check-ignore and could incorrectly skip staging all files.
if (normalizedFilepath !== ".") {
let isIgnored = false;
try {
isIgnored = await gitIsIgnored({ path, filepath: normalizedFilepath });
} catch (e) {
logger.warn(
`Failed to check if file '${normalizedFilepath}' is ignored, proceeding with staging`,
e,
);
}
if (isIgnored) {
logger.debug(
`Skipping staging of ignored file '${normalizedFilepath}' (file is in .gitignore)`,
);
return;
}
}
if (settings.enableNativeGit) {
await execOrThrow(
["add", "--", normalizedFilepath],
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论