File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -44,8 +44,18 @@ def get_git_root_path(filepath):
44
44
45
45
# search up to five directories above for the git repo root
46
46
for _ in range (6 ):
47
- if dir_exists (os .path .join (gitroot_path , ".git" )):
47
+ dot_git = os .path .join (gitroot_path , ".git" )
48
+ if dir_exists (dot_git ):
48
49
return gitroot_path
50
+ elif file_exists (dot_git ):
51
+ # Could be a worktree, in which case .git is a file with content like:
52
+ # gitdir: /home/atk/Tools/font-v/.git/worktrees/work-worktrees-work
53
+ with open (dot_git , "r" ) as dot_git :
54
+ line = dot_git .readline ()
55
+ # "gitdir: font-v/.git/worktrees/work-worktrees-work" -> "font-v/.git/worktrees/work-worktrees-work"
56
+ worktree_path = line .split (" " , 2 )[1 ]
57
+ # "font-v/.git/worktrees/work-worktrees-work" -> "font-v/.git"
58
+ gitroot_path = worktree_path .split ("/worktrees/" , 2 )[0 ]
49
59
gitroot_path = os .path .dirname (gitroot_path )
50
60
51
61
raise IOError (
You can’t perform that action at this time.
0 commit comments