mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #1727 from mrogaski/1610_git_toplevel_relpath
git: changed rev-parse option for Git 2.25 changes to --show-toplevel
This commit is contained in:
commit
eacf4c886e
1 changed files with 14 additions and 9 deletions
|
|
@ -47,20 +47,25 @@ def no_git_env(
|
||||||
|
|
||||||
|
|
||||||
def get_root() -> str:
|
def get_root() -> str:
|
||||||
|
# Git 2.25 introduced a change to "rev-parse --show-toplevel" that exposed
|
||||||
|
# underlying volumes for Windows drives mapped with SUBST. We use
|
||||||
|
# "rev-parse --show-cdup" to get the appropriate path, but must perform
|
||||||
|
# an extra check to see if we are in the .git directory.
|
||||||
try:
|
try:
|
||||||
root = cmd_output('git', 'rev-parse', '--show-toplevel')[1].strip()
|
root = os.path.realpath(
|
||||||
|
cmd_output('git', 'rev-parse', '--show-cdup')[1].strip(),
|
||||||
|
)
|
||||||
|
git_dir = os.path.realpath(get_git_dir())
|
||||||
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?',
|
||||||
)
|
)
|
||||||
else:
|
if os.path.commonpath((root, git_dir)) == git_dir:
|
||||||
if root == '': # pragma: no cover (old git)
|
|
||||||
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.',
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
return root
|
return root
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue