Skip to content
Merged
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
6 changes: 5 additions & 1 deletion flit/vcs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
def identify_vcs(directory: Path):
directory = directory.resolve()
for p in [directory] + list(directory.parents):
if (p / '.git').is_dir():
# In a linked git worktree (`git worktree add ...`) or inside a
# git submodule, `.git` is a regular file containing a
# `gitdir: <path>` pointer rather than a directory.
git_entry = p / '.git'
if git_entry.is_dir() or git_entry.is_file():
return git
if (p / '.hg').is_dir():
return hg
Expand Down
11 changes: 11 additions & 0 deletions tests/test_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,14 @@ def test_identify_git_parent():
subdir.mkdir()
with cwd(subdir):
assert vcs.identify_vcs(Path('.')).name == 'git'

def test_identify_git_worktree():
# In a linked git worktree (or submodule) `.git` is a regular file
# containing a `gitdir:` pointer rather than a directory.
with TemporaryDirectory() as td:
td = Path(td)
(td / '.git').write_text('gitdir: /path/to/main/.git/worktrees/feature\n')
subdir = (td / 'subdir')
subdir.mkdir()
with cwd(subdir):
assert vcs.identify_vcs(Path('.')).name == 'git'