Skip to content

Commit 2f50404

Browse files
unhappychoiceclaude
andcommitted
fix: address CodeRabbit review findings on rename detection and ignore handling
- Propagate errors from `Diff::find_similar` instead of dropping them with `let _`. Without this, rename detection could silently fail and downstream animation logic would emit add/delete instead of `mv` because `old_path` never gets populated. - Make `collect_ignore_patterns` return `Result` so a missing or unreadable `--ignore-file` surfaces as an error rather than being silently downgraded to "no extra patterns" — users explicitly opted into that filtering. - Initialize ignore patterns before computing the working-tree diff inside `prepare_diff_playback` so `should_exclude_file` filters out user-ignored paths during the first metadata extraction, not just on subsequent loop iterations. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent d49df10 commit 2f50404

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

‎src/git.rs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,14 @@ fn matches_date_filter(
173173
Ok(true)
174174
}
175175

176-
fn detect_file_moves(diff: &mut git2::Diff, for_untracked: bool) {
176+
fn detect_file_moves(diff: &mut git2::Diff, for_untracked: bool) -> Result<()> {
177177
let mut options = DiffFindOptions::new();
178178
options.renames(true);
179179
if for_untracked {
180180
options.for_untracked(true);
181181
}
182-
let _ = diff.find_similar(Some(&mut options));
182+
diff.find_similar(Some(&mut options))
183+
.context("Failed to detect file renames in diff")
183184
}
184185

185186
pub struct GitRepository {
@@ -620,7 +621,7 @@ impl GitRepository {
620621
Ok(d) => d,
621622
Err(_) => return Ok(Vec::new()), // Skip if diff fails
622623
};
623-
detect_file_moves(&mut diff, false);
624+
detect_file_moves(&mut diff, false)?;
624625

625626
let mut changes = Vec::new();
626627

@@ -830,7 +831,7 @@ impl GitRepository {
830831
.repo
831832
.diff_tree_to_index(head_tree.as_ref(), Some(&index), Some(&mut diff_opts))
832833
.context("Failed to diff tree to index")?;
833-
detect_file_moves(&mut diff, false);
834+
detect_file_moves(&mut diff, false)?;
834835

835836
self.extract_changes_from_diff(&diff, head_tree.as_ref(), None)
836837
}
@@ -850,7 +851,7 @@ impl GitRepository {
850851
.repo
851852
.diff_index_to_workdir(Some(&index), Some(&mut diff_opts))
852853
.context("Failed to diff index to workdir")?;
853-
detect_file_moves(&mut diff, true);
854+
detect_file_moves(&mut diff, true)?;
854855

855856
// For unstaged, "old" content comes from index, "new" from workdir
856857
self.extract_changes_from_diff_workdir(&diff, &index)

‎src/main.rs‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,12 @@ fn collect_ignore_patterns(
269269
config_patterns: &[String],
270270
ignore_file: Option<&Path>,
271271
cli_patterns: &[String],
272-
) -> Vec<String> {
272+
) -> Result<Vec<String>> {
273273
let mut patterns = config_patterns.to_vec();
274274

275-
if let Some(content) = ignore_file.and_then(|path| std::fs::read_to_string(path).ok()) {
275+
if let Some(path) = ignore_file {
276+
let content = std::fs::read_to_string(path)
277+
.with_context(|| format!("Failed to read ignore file: {}", path.display()))?;
276278
patterns.extend(
277279
content
278280
.lines()
@@ -282,7 +284,7 @@ fn collect_ignore_patterns(
282284
}
283285

284286
patterns.extend(cli_patterns.iter().cloned());
285-
patterns
287+
Ok(patterns)
286288
}
287289

288290
fn parse_speed_rules(cli_rules: &[String], config_rules: &[String]) -> Vec<SpeedRule> {
@@ -424,7 +426,7 @@ fn prepare_commit_playback(
424426
&config.ignore_patterns,
425427
args.ignore_file.as_deref(),
426428
&args.ignore,
427-
);
429+
)?;
428430
git::init_ignore_patterns(&patterns).ok();
429431
let order = resolve_order(args.order, &config.order, is_range_mode, is_filtered);
430432
let runtime = resolve_runtime_options(
@@ -463,12 +465,12 @@ fn prepare_diff_playback(
463465
} else {
464466
DiffMode::Staged
465467
};
468+
let patterns = collect_ignore_patterns(&config.ignore_patterns, None, options.ignore)?;
469+
git::init_ignore_patterns(&patterns).ok();
466470
let metadata = repo.get_working_tree_diff(mode)?;
467471
if metadata.changes.is_empty() {
468472
return Ok(None);
469473
}
470-
let patterns = collect_ignore_patterns(&config.ignore_patterns, None, options.ignore);
471-
git::init_ignore_patterns(&patterns).ok();
472474
let runtime = resolve_runtime_options(
473475
options.speed,
474476
options.theme,
@@ -877,7 +879,8 @@ mod tests {
877879
&["dist/**".to_string()],
878880
Some(ignore_file.as_path()),
879881
&["*.png".to_string()],
880-
);
882+
)
883+
.unwrap();
881884

882885
assert_eq!(
883886
patterns,

0 commit comments

Comments
 (0)