Skip to content

Commit 2ff0b25

Browse files
committed
fix: status-iterator won't swallow legitimate modification during 'racy-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.
1 parent 9c8d9e4 commit 2ff0b25

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

gix/src/status/iter/mod.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,15 @@ impl Iter {
274274

275275
impl Iter {
276276
fn maybe_keep_index_change(&mut self, item: Item) -> Option<Item> {
277-
let change = match item {
277+
match item {
278278
Item::IndexWorktree(index_worktree::Item::Modification {
279279
status: EntryStatus::NeedsUpdate(stat),
280280
entry_index,
281281
..
282-
}) => (entry_index, ApplyChange::NewStat(stat)),
282+
}) => {
283+
self.index_changes.push((entry_index, ApplyChange::NewStat(stat)));
284+
return None;
285+
}
283286
Item::IndexWorktree(index_worktree::Item::Modification {
284287
status:
285288
EntryStatus::Change(Change::Modification {
@@ -288,12 +291,12 @@ impl Iter {
288291
}),
289292
entry_index,
290293
..
291-
}) if set_entry_stat_size_zero => (entry_index, ApplyChange::SetSizeToZero),
292-
_ => return Some(item),
294+
}) if set_entry_stat_size_zero => {
295+
self.index_changes.push((entry_index, ApplyChange::SetSizeToZero));
296+
}
297+
_ => {}
293298
};
294-
295-
self.index_changes.push(change);
296-
None
299+
Some(item)
297300
}
298301
}
299302

Binary file not shown.

gix/tests/fixtures/make_status_repos.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,12 @@ git init git-mv
2121

2222
git mv file renamed
2323
)
24+
25+
git init racy-git
26+
(cd racy-git
27+
echo hi >file
28+
git add file && git commit -m "init"
29+
30+
echo ho >file && git add file
31+
echo ha >file
32+
)

gix/tests/gix/status.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ mod into_iter {
7373
Ok(())
7474
}
7575

76+
#[test]
77+
fn tree_index_modification_worktree_modification_racy_git() -> crate::Result {
78+
let repo = repo("racy-git")?;
79+
let mut status = repo.status(gix::progress::Discard)?.into_iter(None)?;
80+
let mut items: Vec<_> = status.by_ref().filter_map(Result::ok).collect();
81+
items.sort_by(|a, b| a.location().cmp(b.location()));
82+
assert_eq!(items.len(), 2, "1 modified in index, the same in worktree");
83+
Ok(())
84+
}
85+
7686
#[test]
7787
fn error_during_tree_traversal_causes_failure() -> crate::Result {
7888
let repo = repo("untracked-only")?;

0 commit comments

Comments
 (0)