feat(commit): 添加.gitignore文件过滤功能,自动跳过被忽略的文件

在自动暂存和`--all`模式下,检测并跳过被.gitignore规则匹配的文件,暂存完成后显示被移除的被忽略文件列表
This commit is contained in:
2026-07-20 17:33:57 +08:00
parent 19aff8a6c1
commit 995d263a48
5 changed files with 395 additions and 14 deletions

View File

@@ -121,8 +121,17 @@ impl CommitCommand {
// Auto-add if no files are staged and there are unstaged/untracked changes
if status.staged == 0 && (status.unstaged > 0 || status.untracked > 0) && !self.all {
println!("{}", messages.auto_stage_changes().yellow());
repo.stage_all()?;
let removed = repo.stage_all()?;
println!("{}", messages.staged_all().green());
if !removed.is_empty() {
println!(
"{}",
format!("Removed {} ignored files from staging:", removed.len()).yellow()
);
for file in &removed {
println!("{}", file);
}
}
// Re-check status after staging to ensure changes are detected
let new_status = repo.status_summary()?;
@@ -133,8 +142,17 @@ impl CommitCommand {
// Stage all if requested
if self.all {
repo.stage_all()?;
let removed = repo.stage_all()?;
println!("{}", messages.staged_all().green());
if !removed.is_empty() {
println!(
"{}",
format!("Removed {} ignored files from staging:", removed.len()).yellow()
);
for file in &removed {
println!("{}", file);
}
}
}
// Generate or build commit message