Skip to content

Commit

Permalink
fix: status-iterator won't swallow legitimate modification during 'ra…
Browse files Browse the repository at this point in the history
…cy-git'.

When a modification is marked as being racy, then previously the iterator would have
kept the whole modification even though it should just have tracked the single change.

This made the legitimate modification disappear.
  • Loading branch information
Byron committed Jan 4, 2025
1 parent 9c8d9e4 commit 2ff0b25
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
17 changes: 10 additions & 7 deletions gix/src/status/iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,15 @@ impl Iter {

impl Iter {
fn maybe_keep_index_change(&mut self, item: Item) -> Option<Item> {
let change = match item {
match item {
Item::IndexWorktree(index_worktree::Item::Modification {
status: EntryStatus::NeedsUpdate(stat),
entry_index,
..
}) => (entry_index, ApplyChange::NewStat(stat)),
}) => {
self.index_changes.push((entry_index, ApplyChange::NewStat(stat)));
return None;
}
Item::IndexWorktree(index_worktree::Item::Modification {
status:
EntryStatus::Change(Change::Modification {
Expand All @@ -288,12 +291,12 @@ impl Iter {
}),
entry_index,
..
}) if set_entry_stat_size_zero => (entry_index, ApplyChange::SetSizeToZero),
_ => return Some(item),
}) if set_entry_stat_size_zero => {
self.index_changes.push((entry_index, ApplyChange::SetSizeToZero));
}
_ => {}
};

self.index_changes.push(change);
None
Some(item)
}
}

Expand Down
Binary file modified gix/tests/fixtures/generated-archives/make_status_repos.tar
Binary file not shown.
9 changes: 9 additions & 0 deletions gix/tests/fixtures/make_status_repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ git init git-mv

git mv file renamed
)

git init racy-git
(cd racy-git
echo hi >file
git add file && git commit -m "init"

echo ho >file && git add file
echo ha >file
)
10 changes: 10 additions & 0 deletions gix/tests/gix/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ mod into_iter {
Ok(())
}

#[test]
fn tree_index_modification_worktree_modification_racy_git() -> crate::Result {
let repo = repo("racy-git")?;
let mut status = repo.status(gix::progress::Discard)?.into_iter(None)?;
let mut items: Vec<_> = status.by_ref().filter_map(Result::ok).collect();
items.sort_by(|a, b| a.location().cmp(b.location()));
assert_eq!(items.len(), 2, "1 modified in index, the same in worktree");
Ok(())
}

#[test]
fn error_during_tree_traversal_causes_failure() -> crate::Result {
let repo = repo("untracked-only")?;
Expand Down

0 comments on commit 2ff0b25

Please sign in to comment.