MCPcopy Index your code
hub / github.com/pre-commit/pre-commit / get_root

Function get_root

pre_commit/git.py:51–73  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49
50
51def get_root() -> str:
52 # Git 2.25 introduced a change to "rev-parse --show-toplevel" that exposed
53 # underlying volumes for Windows drives mapped with SUBST. We use
54 # "rev-parse --show-cdup" to get the appropriate path, but must perform
55 # an extra check to see if we are in the .git directory.
56 try:
57 root = os.path.abspath(
58 cmd_output('git', 'rev-parse', '--show-cdup')[1].strip(),
59 )
60 inside_git_dir = cmd_output(
61 'git', 'rev-parse', '--is-inside-git-dir',
62 )[1].strip()
63 except CalledProcessError:
64 raise FatalError(
65 'git failed. Is it installed, and are you in a Git repository '
66 'directory?',
67 )
68 if inside_git_dir != 'false':
69 raise FatalError(
70 'git toplevel unexpectedly empty! make sure you are not '
71 'inside the `.git` directory of your repository.',
72 )
73 return root
74
75
76def get_git_dir(git_root: str = '.') -> str:

Callers 1

Calls 2

cmd_outputFunction · 0.90
FatalErrorClass · 0.90

Tested by

no test coverage detected