Skip to content

Commit 131481c

Browse files
committed
a test to assure non-existing worktree directories don't hinder discovery (#301)
1 parent bd281b8 commit 131481c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

git-discover/tests/fixtures/make_basic_repo.sh

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ git clone --bare --shared . bare.git
1717
git worktree add worktrees/a
1818
git worktree add worktrees/b-private-dir-deleted
1919
rm -R .git/worktrees/b-private-dir-deleted
20+
git worktree add worktrees/c-worktree-deleted
21+
rm -R worktrees/c-worktree-deleted
2022

2123
cd bare.git
2224
git worktree add ../worktrees/from-bare/c

git-discover/tests/upwards/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,19 @@ fn from_existing_worktree_inside_dot_git() {
142142
);
143143
}
144144

145+
#[test]
146+
fn from_non_existing_worktree_inside_dot_git() {
147+
let top_level_repo = repo_path().unwrap();
148+
let (path, _trust) = git_discover::upwards(top_level_repo.join(".git/worktrees/c-worktree-deleted")).unwrap();
149+
let suffix = std::path::Path::new(top_level_repo.file_name().unwrap())
150+
.join("worktrees")
151+
.join("c-worktree-deleted");
152+
assert!(
153+
matches!(path, git_discover::repository::Path::LinkedWorkTree { work_dir, .. } if work_dir.ends_with(suffix)),
154+
"it's no problem if work-dirs don't exist - this can be discovered later and a lot of operations are possible anyway."
155+
);
156+
}
157+
145158
#[test]
146159
fn from_existing_worktree() -> crate::Result {
147160
let top_level_repo = repo_path()?;

0 commit comments

Comments
 (0)