Skip to content

Commit bf45734

Browse files
committed
Implement our own rev-parse --top-level
1 parent 086e507 commit bf45734

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

pre_commit/git.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,22 @@
66
from pre_commit.util import memoize_by_cwd
77

88

9+
def _get_root_original():
10+
return local['git']['rev-parse', '--show-toplevel']().strip()
11+
12+
def _get_root_new():
13+
path = os.getcwd()
14+
while len(path) > 1:
15+
if os.path.exists(os.path.join(path, '.git')):
16+
return path
17+
else:
18+
path = os.path.normpath(os.path.join(path, '../'))
19+
raise AssertionError('called from outside of the gits')
20+
21+
922
@memoize_by_cwd
1023
def get_root():
24+
return _get_root_new()
1125
return local['git']['rev-parse', '--show-toplevel']().strip()
1226

1327

pre_commit/hooks_workspace.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
def get_pre_commit_dir_path():
1111
return os.path.join(git.get_root(), C.HOOKS_WORKSPACE)
1212

13+
1314
@contextlib.contextmanager
1415
def in_hooks_workspace():
1516
"""Change into the hooks workspace. If it does not exist create it."""

0 commit comments

Comments
 (0)