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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/cygwin-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: Install Cygwin
uses: cygwin/cygwin-install-action@v6
with:
packages: git python39 python-pip-wheel python-setuptools-wheel python-wheel-wheel
packages: curl git python39 python-setuptools-wheel
add-to-path: false # No need to change $PATH outside the Cygwin environment.

- name: Arrange for verbose output
Expand Down Expand Up @@ -73,12 +73,15 @@ jobs:

- name: Set up virtual environment
run: |
pip_wheel=/usr/share/python-wheels/pip-26.0.1-py3-none-any.whl
curl -fsSLo "$pip_wheel" https://files.pythonhosted.org/packages/de/f0/c81e05b613866b76d2d1066490adf1a3dbc4ee9d9c839961c3fc8a6997af/pip-26.0.1-py3-none-any.whl
python3.9 -c 'import hashlib, pathlib, sys; assert hashlib.sha256(pathlib.Path(sys.argv[1]).read_bytes()).hexdigest() == sys.argv[2]' "$pip_wheel" bdb1b08f4274833d62c1aa29e20907365a2ceb950410df15fc9521bad440122b
python3.9 -m venv .venv
echo 'BASH_ENV=.venv/bin/activate' >>"$GITHUB_ENV"

- name: Update PyPA packages
run: |
python -m pip install -U pip 'setuptools; python_version<"3.12"' wheel
python -m pip install -U 'setuptools; python_version<"3.12"' wheel

- name: Install project and test dependencies
run: |
Expand Down
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