File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,21 +47,26 @@ def no_git_env(
4747
4848
4949def get_root () -> str :
50+ # Git 2.25 introduced a change to "rev-parse --show-toplevel" that exposed
51+ # underlying volumes for Windows drives mapped with SUBST. We use
52+ # "rev-parse --show-cdup" to get the appropriate path, but must perform
53+ # an extra check to see if we are in the .git directory.
5054 try :
51- root = cmd_output ('git' , 'rev-parse' , '--show-toplevel' )[1 ].strip ()
55+ root = os .path .realpath (
56+ cmd_output ('git' , 'rev-parse' , '--show-cdup' )[1 ].strip (),
57+ )
58+ git_dir = os .path .realpath (get_git_dir ())
5259 except CalledProcessError :
5360 raise FatalError (
5461 'git failed. Is it installed, and are you in a Git repository '
5562 'directory?' ,
5663 )
57- else :
58- if root == '' : # pragma: no cover (old git)
59- raise FatalError (
60- 'git toplevel unexpectedly empty! make sure you are not '
61- 'inside the `.git` directory of your repository.' ,
62- )
63- else :
64- return root
64+ if os .path .commonpath ((root , git_dir )) == git_dir :
65+ raise FatalError (
66+ 'git toplevel unexpectedly empty! make sure you are not '
67+ 'inside the `.git` directory of your repository.' ,
68+ )
69+ return root
6570
6671
6772def get_git_dir (git_root : str = '.' ) -> str :
You can’t perform that action at this time.
0 commit comments