fix get_root() for the case of called from the git dir

This commit is contained in:
Daniel Schürmann 2021-08-06 22:48:11 +02:00
parent cc9f8f66c8
commit c43698e942

View file

@ -55,13 +55,15 @@ def get_root() -> str:
root = os.path.abspath( root = os.path.abspath(
cmd_output('git', 'rev-parse', '--show-cdup')[1].strip(), cmd_output('git', 'rev-parse', '--show-cdup')[1].strip(),
) )
git_dir = os.path.abspath(get_git_common_dir()) inside_git_dir = cmd_output(
'git', 'rev-parse', '--is-inside-git-dir',
)[1].strip()
except CalledProcessError: except CalledProcessError:
raise FatalError( raise FatalError(
'git failed. Is it installed, and are you in a Git repository ' 'git failed. Is it installed, and are you in a Git repository '
'directory?', 'directory?',
) )
if os.path.samefile(root, git_dir): if inside_git_dir != 'false':
raise FatalError( raise FatalError(
'git toplevel unexpectedly empty! make sure you are not ' 'git toplevel unexpectedly empty! make sure you are not '
'inside the `.git` directory of your repository.', 'inside the `.git` directory of your repository.',