Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion gix/src/repository/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ impl crate::Repository {
pub fn kind(&self) -> crate::repository::Kind {
use gix_discover::path::RepositoryKind::*;
match gix_discover::path::repository_kind(self.git_dir()) {
None | Some(Common) => crate::repository::Kind::Common,
Some(Submodule) => crate::repository::Kind::Submodule,
Some(LinkedWorktree) => crate::repository::Kind::LinkedWorkTree,
None | Some(Common) if self.git_dir() != self.common_dir() => crate::repository::Kind::LinkedWorkTree,
None | Some(Common) => crate::repository::Kind::Common,
}
}

Expand Down
5 changes: 5 additions & 0 deletions gix/tests/fixtures/make_worktree_repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ git init non-bare-turned-bare

git worktree add ../worktree-of-bare-repo
)

git clone --bare --shared repo natively-bare-repo
(cd natively-bare-repo
git worktree add ../worktree-of-natively-bare-repo
)
45 changes: 45 additions & 0 deletions gix/tests/gix/repository/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,51 @@ fn worktree_of_bare_repo() -> crate::Result {
Ok(())
}

#[test]
fn worktree_of_natively_bare_repo() -> crate::Result {
let repo = named_subrepo_opts(
"make_worktree_repo.sh",
"worktree-of-natively-bare-repo",
gix::open::Options::isolated(),
)?;
assert_ne!(
repo.workdir(),
None,
"we have opened the repo through a worktree, which is never bare"
);
assert!(
!repo
.worktree()
.expect("the worktree is available, it's linked")
.is_main(),
"linked worktrees can exist for any repository, even bare"
);
assert!(
repo.is_bare(),
"the shared config has core.bare=true, which a linked worktree inherits even though it has a workdir"
);
assert_eq!(repo.kind(), gix::repository::Kind::LinkedWorkTree);
Ok(())
}

#[test]
fn natively_bare_repo_itself_is_common() -> crate::Result {
let repo = named_subrepo_opts(
"make_worktree_repo.sh",
"natively-bare-repo",
gix::open::Options::isolated(),
)?;
assert!(repo.is_bare());
assert_eq!(repo.workdir(), None, "the bare repository itself has no worktree");
assert_eq!(
repo.git_dir(),
repo.common_dir(),
"there is no linked-worktree redirection"
);
assert_eq!(repo.kind(), gix::repository::Kind::Common);
Ok(())
}

#[test]
fn non_bare_non_git_repo_without_worktree() -> crate::Result {
let repo = named_subrepo_opts(
Expand Down
Loading