Skip to content

Commit 2065d1e

Browse files
committed
get_git_root_path: support worktrees
1 parent 6b7dea4 commit 2065d1e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/fontv/utilities.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import os
1212

13+
import git.repo.fun
14+
1315

1416
def dir_exists(dirpath):
1517
"""Tests for existence of a directory on the string filepath"""
@@ -44,8 +46,16 @@ def get_git_root_path(filepath):
4446

4547
# search up to five directories above for the git repo root
4648
for _ in range(6):
47-
if dir_exists(os.path.join(gitroot_path, ".git")):
49+
dot_git = os.path.join(gitroot_path, ".git")
50+
if git.repo.fun.is_git_dir(dot_git):
4851
return gitroot_path
52+
elif file_exists(dot_git):
53+
# Returns something like ".../font-v/.git/worktrees/work-worktrees-work"
54+
worktree_path = git.repo.fun.find_worktree_git_dir(dot_git)
55+
if worktree_path:
56+
# ".../font-v/.git/worktrees/work-worktrees-work" -> ".../font-v"
57+
return worktree_path.split("/.git/worktrees/", 2)[0]
58+
4959
gitroot_path = os.path.dirname(gitroot_path)
5060

5161
raise IOError(

0 commit comments

Comments
 (0)