Title
Repo instantiated from a bare-repository worktree incorrectly sets bare = True
Description
Since 3.1.58+, instantiating a git.Repo targeting a working tree folder that was created from a bare repository (via git worktree add) inherits the bare = True setting from the main repository's .git location.
This causes repo.working_tree_dir to resolve to None, which causes operations like index.add() / _entries_for_paths to fail with:
InvalidGitRepositoryError: Cannot rewrite paths without a working tree
Minimal Reproduction Example
from git import Repo
import subprocess, tempfile, os
with tempfile.TemporaryDirectory() as tmpdir:
bare_path = os.path.join(tmpdir, "bare.git")
worktree_path = os.path.join(tmpdir, "wt")
# 1. Init bare repo and add a commit
repo_bare = Repo.init(bare_path, bare=True)
# 2. Add a worktree
repo_bare.git.worktree("add", "-b", "main", worktree_path)
# 3. Open worktree repo
wt_repo = Repo(worktree_path)
# Expected: wt_repo.bare is False, wt_repo.working_tree_dir is worktree_path
# Actual: wt_repo.bare is True, wt_repo.working_tree_dir is None
print("Is bare:", wt_repo.bare)
print("Working tree dir:", wt_repo.working_tree_dir)
Is bare: True
Working tree dir: None
while using 3.1.57 the same code produces the correct results
Is bare: False
Working tree dir: /tmp/tmpgz7gz3y6/wt
Title
Repo instantiated from a bare-repository worktree incorrectly sets
bare = TrueDescription
Since 3.1.58+, instantiating a
git.Repotargeting a working tree folder that was created from a bare repository (viagit worktree add) inherits thebare = Truesetting from the main repository's.gitlocation.This causes
repo.working_tree_dirto resolve toNone, which causes operations likeindex.add()/_entries_for_pathsto fail with:InvalidGitRepositoryError: Cannot rewrite paths without a working treeMinimal Reproduction Example