Skip to content

Commit bc02284

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 bc02284

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

gix/src/open/repository.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,21 @@ impl ThreadSafeRepository {
263263
.resolved
264264
.path_filter(Core::WORKTREE, {
265265
|section| {
266-
let res = filter_config_section(section);
267-
if res {
268-
key_source = Some(section.source);
266+
if !filter_config_section(section) {
267+
return false;
269268
}
270-
res
269+
// ignore worktree settings that aren't from our repository. This can happen
270+
// with worktrees of submodules for instance.
271+
let is_config_in_our_repo = section
272+
.path
273+
.as_deref()
274+
.and_then(|p| gix_path::normalize(p.into(), current_dir))
275+
.is_some_and(|config_path| config_path.starts_with(&git_dir));
276+
if !is_config_in_our_repo {
277+
return false;
278+
}
279+
key_source = Some(section.source);
280+
true
271281
}
272282
})
273283
.zip(key_source);

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

+1
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
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

+20
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,25 @@ 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!(
354+
sm_repo.rev_parse_single(":this").is_ok(),
355+
"the file is in the submodule"
356+
);
357+
assert!(
358+
wd.join("this").is_file(),
359+
"The submodule itself has the file, so it should be in the worktree"
360+
);
361+
Ok(())
362+
}
363+
344364
#[test]
345365
fn old_form() -> crate::Result {
346366
for name in ["old-form-invalid-worktree-path", "old-form"] {

0 commit comments

Comments
 (0)