Skip to content

Commit

Permalink
fix: worktrees of submodules now know their correct worktree
Browse files Browse the repository at this point in the history
Previously they would use a very incorrect worktree which would cause
the status to be calculated very wrongly.
  • Loading branch information
Byron committed Jan 12, 2025
1 parent 851a7c4 commit 62df370
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions gix/tests/fixtures/generated-archives/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/make_core_worktree_repo.tar
/make_signatures_repo.tar
/make_diff_repos.tar
/make_submodule_with_worktree.tar
16 changes: 16 additions & 0 deletions gix/tests/fixtures/make_submodule_with_worktree.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -eu -o pipefail

git init -q module1
(cd module1
touch this
git add . && git commit -q -m c1
)

git init submodule-with-extra-worktree-host
(cd submodule-with-extra-worktree-host
git submodule add ../module1 m1
(cd m1
git worktree add ../../worktree-of-submodule
)
)
19 changes: 19 additions & 0 deletions gix/tests/gix/submodule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod open {
use gix::submodule;

use crate::submodule::repo;
use crate::util::named_subrepo_opts;

#[test]
fn various() -> crate::Result {
Expand Down Expand Up @@ -341,6 +342,24 @@ mod open {
Ok(())
}

#[test]
fn submodule_worktrees() -> crate::Result {
let sm_repo = named_subrepo_opts(
"make_submodule_with_worktree.sh",
"worktree-of-submodule",
gix::open::Options::isolated(),
)?;
let wd = sm_repo.work_dir().expect("workdir is present");
assert!(sm_repo.rev_parse_single(":this").is_ok(), "the file is in the submodule");
assert!(
wd.join("this").is_file(),
"The submodule itself has the file, so it should be in the worktree"
);

assert_eq!(sm_repo.worktrees()?.len(), 2, "The main worktree and the extra one");
Ok(())
}

#[test]
fn old_form() -> crate::Result {
for name in ["old-form-invalid-worktree-path", "old-form"] {
Expand Down

0 comments on commit 62df370

Please sign in to comment.