Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ def __init__(
# Let's not assume the option exists, although it should.
pass

# A linked worktree is not bare even when its main repository is.
if self._bare and self._working_tree_dir and osp.isfile(osp.join(self.git_dir, "commondir")):
self._bare = False

# Adjust the working directory in case we are actually bare - we didn't know
# that in the first place.
if self._bare:
Expand Down
17 changes: 17 additions & 0 deletions test/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,23 @@ def test_git_work_tree_dotgit(self, rw_dir, use_relative_paths=False):

self.assertIsInstance(repo.heads["aaaaaaaa"], Head)

@with_rw_directory
def test_git_work_tree_from_bare_repo(self, rw_dir):
if Git().version_info[:3] < (2, 5, 1):
pytest.skip("worktree feature unsupported, needs git 2.5.1 or later")

bare_repo = self.rorepo.clone(join_path_native(rw_dir, "bare_repo"), bare=True)
worktree_path = join_path_native(rw_dir, "worktree_repo")
if Git.is_cygwin():
worktree_path = cygpath(worktree_path)
bare_repo.git.worktree("add", "--detach", worktree_path)
Comment thread
Copilot marked this conversation as resolved.

repo = Repo(worktree_path)

assert Git(worktree_path).rev_parse("--is-bare-repository") == "false"
assert not repo.bare
assert osp.samefile(repo.working_tree_dir, worktree_path)

def test_git_work_tree_dotgit_relative(self):
"""Check that we find .git as a worktree file containing a relative path
and find the worktree based on it."""
Expand Down
Loading