Skip to content

Commit

Permalink
a test to assure non-existing worktree directories don't hinder disco…
Browse files Browse the repository at this point in the history
…very (#301)
  • Loading branch information
Byron committed May 18, 2022
1 parent bd281b8 commit 131481c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions git-discover/tests/fixtures/make_basic_repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ git clone --bare --shared . bare.git
git worktree add worktrees/a
git worktree add worktrees/b-private-dir-deleted
rm -R .git/worktrees/b-private-dir-deleted
git worktree add worktrees/c-worktree-deleted
rm -R worktrees/c-worktree-deleted

cd bare.git
git worktree add ../worktrees/from-bare/c
Expand Down
13 changes: 13 additions & 0 deletions git-discover/tests/upwards/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@ fn from_existing_worktree_inside_dot_git() {
);
}

#[test]
fn from_non_existing_worktree_inside_dot_git() {
let top_level_repo = repo_path().unwrap();
let (path, _trust) = git_discover::upwards(top_level_repo.join(".git/worktrees/c-worktree-deleted")).unwrap();
let suffix = std::path::Path::new(top_level_repo.file_name().unwrap())
.join("worktrees")
.join("c-worktree-deleted");
assert!(
matches!(path, git_discover::repository::Path::LinkedWorkTree { work_dir, .. } if work_dir.ends_with(suffix)),
"it's no problem if work-dirs don't exist - this can be discovered later and a lot of operations are possible anyway."
);
}

#[test]
fn from_existing_worktree() -> crate::Result {
let top_level_repo = repo_path()?;
Expand Down

0 comments on commit 131481c

Please sign in to comment.