Skip to content

Commit 4cfc259

Browse files
committed
fix: Submodule::status() now konws about tree-index changes as well.
This completes the status implementation.
1 parent 38e3c50 commit 4cfc259

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

gix/src/submodule/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ pub mod status {
323323
/// Return the status of the submodule, just like [`status`](Self::status), but allows to adjust options
324324
/// for more control over how the status is performed.
325325
///
326+
/// If `check_dirty` is `true`, the computation will stop once the first in a ladder operations
327+
/// ordered from cheap to expensive shows that the submodule is dirty.
328+
///
326329
/// Use `&mut std::convert::identity` for `adjust_options` if no specific options are desired.
327330
/// A reason to change them might be to enable sorting to enjoy deterministic order of changes.
328331
///
18 KB
Binary file not shown.

gix/tests/fixtures/make_submodules.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ git init submodule-head-changed
2121
cd m1 && git checkout @~1
2222
)
2323

24+
git init submodule-index-changed
25+
(cd submodule-index-changed
26+
git submodule add ../module1 m1
27+
git commit -m "add submodule"
28+
29+
(cd m1
30+
git mv subdir subdir-renamed
31+
git mv this that
32+
)
33+
)
34+
2435
git init submodule-head-changed-no-worktree
2536
(cd submodule-head-changed-no-worktree
2637
git submodule add ../module1 m1

gix/tests/gix/submodule.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,37 @@ mod open {
186186
Ok(())
187187
}
188188

189+
#[test]
190+
fn modified_in_index_only() -> crate::Result {
191+
let repo = repo("submodule-index-changed")?;
192+
let sm = repo.submodules()?.into_iter().flatten().next().expect("one submodule");
193+
194+
for mode in [
195+
gix::submodule::config::Ignore::Untracked,
196+
gix::submodule::config::Ignore::None,
197+
] {
198+
for check_dirty in [false, true] {
199+
let status = sm.status_opts(mode, check_dirty, &mut |platform| platform)?;
200+
assert_eq!(
201+
status.is_dirty(),
202+
Some(true),
203+
"two files were renamed using `git mv` for an HEAD^{tree}-index change"
204+
);
205+
assert_eq!(
206+
status.changes.expect("present").len(),
207+
if check_dirty { 1 } else { 2 },
208+
"in is-dirty mode, we don't collect all changes"
209+
);
210+
}
211+
}
212+
213+
assert!(
214+
repo.is_dirty()?,
215+
"superproject should see submodule changes in the index as well"
216+
);
217+
Ok(())
218+
}
219+
189220
#[test]
190221
fn modified_and_untracked() -> crate::Result {
191222
let repo = repo("modified-and-untracked")?;

0 commit comments

Comments
 (0)