Skip to content

Commit 3406b1d

Browse files
codexByron
andcommitted
Add another test to learn what is_dirty() does when there are modifications.
Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
1 parent 1f82a9f commit 3406b1d

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

49.5 KB
Binary file not shown.

gix/tests/fixtures/make_status_repos.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ git init untracked-unborn
3636
touch untracked
3737
)
3838

39+
git init added-unborn
40+
(cd added-unborn
41+
echo content >added
42+
mkdir dir
43+
echo content >dir/nested
44+
git add added dir/nested
45+
)
46+
3947
git init untracked-added
4048
(cd untracked-added
4149
echo content >added

gix/tests/gix/status.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,40 @@ mod into_iter {
241241
Ok(())
242242
}
243243

244+
#[test]
245+
fn added_unborn() -> crate::Result {
246+
let repo = repo("added-unborn")?;
247+
let mut status = repo.status(gix::progress::Discard)?.into_iter(None)?;
248+
let mut items: Vec<_> = status.by_ref().filter_map(Result::ok).collect();
249+
items.sort_by(|a, b| a.location().cmp(b.location()));
250+
let snapshot = gix_testtools::normalize_debug_snapshot(&items).0;
251+
insta::assert_snapshot!(snapshot, @r#"
252+
[
253+
TreeIndex(
254+
Addition {
255+
location: "added",
256+
index: 0,
257+
entry_mode: Mode(
258+
FILE,
259+
),
260+
id: Oid(1),
261+
},
262+
),
263+
TreeIndex(
264+
Addition {
265+
location: "dir/nested",
266+
index: 1,
267+
entry_mode: Mode(
268+
FILE,
269+
),
270+
id: Oid(1),
271+
},
272+
),
273+
]
274+
"#);
275+
Ok(())
276+
}
277+
244278
#[test]
245279
fn untracked_added() -> crate::Result {
246280
let repo = repo("untracked-added")?;
@@ -529,6 +563,17 @@ mod is_dirty {
529563
Ok(())
530564
}
531565

566+
#[test]
567+
fn added_files_in_unborn_head_are_dirty() -> crate::Result {
568+
let repo = repo("added-unborn")?;
569+
570+
assert!(
571+
repo.is_dirty()?,
572+
"files added to the index make an unborn repository dirty"
573+
);
574+
Ok(())
575+
}
576+
532577
#[test]
533578
fn index_changed() -> crate::Result {
534579
let repo = repo("git-mv")?;

0 commit comments

Comments
 (0)