From 8b758eabee40f989a5e0f36cef27a05149bc4df9 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 16 Oct 2023 13:30:31 +0200 Subject: [PATCH] fix: make repositories with `worktree` config work. --- .../tests/fixtures/make_basic_repo.sh | 12 +++++++++ gix-discover/tests/is_git/mod.rs | 26 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/gix-discover/tests/fixtures/make_basic_repo.sh b/gix-discover/tests/fixtures/make_basic_repo.sh index f7beae17d0d..2b36e8abd43 100755 --- a/gix-discover/tests/fixtures/make_basic_repo.sh +++ b/gix-discover/tests/fixtures/make_basic_repo.sh @@ -70,3 +70,15 @@ git init non-bare-without-index git commit -m "init" rm .git/index ) + +git --git-dir=repo-with-worktree-in-config-unborn-no-worktreedir --work-tree=does-not-exist-yet init +worktree=repo-with-worktree-in-config-unborn-worktree +git --git-dir=repo-with-worktree-in-config-unborn --work-tree=$worktree init && mkdir $worktree + +worktree=repo-with-worktree-in-config-worktree +git --git-dir=repo-with-worktree-in-config --work-tree=$worktree init +mkdir $worktree && touch $worktree/file +(cd repo-with-worktree-in-config + git add file + git commit -m "make sure na index exists" +) diff --git a/gix-discover/tests/is_git/mod.rs b/gix-discover/tests/is_git/mod.rs index 370af83fa8f..84621e2dd18 100644 --- a/gix-discover/tests/is_git/mod.rs +++ b/gix-discover/tests/is_git/mod.rs @@ -85,3 +85,29 @@ fn missing_configuration_file_is_not_a_dealbreaker_in_nonbare_repo() -> crate::R } Ok(()) } + +#[test] +fn unborn_with_split_worktree_by_configuration() -> crate::Result { + for name in [ + "repo-with-worktree-in-config-unborn", + "repo-with-worktree-in-config-unborn-no-worktreedir", + ] { + let repo = repo_path()?.join(name); + let kind = gix_discover::is_git(&repo)?; + assert_eq!( + kind, + gix_discover::repository::Kind::Bare, + "{name}: we think these are bare as we don't read the configuration in this case - \ + a shortcoming to favor performance which still comes out correct in `gix`" + ); + } + Ok(()) +} + +#[test] +fn split_worktree_as_seen_from_repo() -> crate::Result { + let repo = repo_path()?.join("repo-with-worktree-in-config"); + let kind = gix_discover::is_git(&repo)?; + assert_eq!(kind, gix_discover::repository::Kind::WorkTree { linked_git_dir: None }); + Ok(()) +}