Skip to content

Commit 62df370

Browse files
committed
fix: worktrees of submodules now know their correct worktree
Previously they would use a very incorrect worktree which would cause the status to be calculated very wrongly.
1 parent 851a7c4 commit 62df370

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

gix/tests/fixtures/generated-archives/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/make_core_worktree_repo.tar
88
/make_signatures_repo.tar
99
/make_diff_repos.tar
10+
/make_submodule_with_worktree.tar
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
set -eu -o pipefail
3+
4+
git init -q module1
5+
(cd module1
6+
touch this
7+
git add . && git commit -q -m c1
8+
)
9+
10+
git init submodule-with-extra-worktree-host
11+
(cd submodule-with-extra-worktree-host
12+
git submodule add ../module1 m1
13+
(cd m1
14+
git worktree add ../../worktree-of-submodule
15+
)
16+
)

gix/tests/gix/submodule.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mod open {
1111
use gix::submodule;
1212

1313
use crate::submodule::repo;
14+
use crate::util::named_subrepo_opts;
1415

1516
#[test]
1617
fn various() -> crate::Result {
@@ -341,6 +342,24 @@ mod open {
341342
Ok(())
342343
}
343344

345+
#[test]
346+
fn submodule_worktrees() -> crate::Result {
347+
let sm_repo = named_subrepo_opts(
348+
"make_submodule_with_worktree.sh",
349+
"worktree-of-submodule",
350+
gix::open::Options::isolated(),
351+
)?;
352+
let wd = sm_repo.work_dir().expect("workdir is present");
353+
assert!(sm_repo.rev_parse_single(":this").is_ok(), "the file is in the submodule");
354+
assert!(
355+
wd.join("this").is_file(),
356+
"The submodule itself has the file, so it should be in the worktree"
357+
);
358+
359+
assert_eq!(sm_repo.worktrees()?.len(), 2, "The main worktree and the extra one");
360+
Ok(())
361+
}
362+
344363
#[test]
345364
fn old_form() -> crate::Result {
346365
for name in ["old-form-invalid-worktree-path", "old-form"] {

0 commit comments

Comments
 (0)