mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Implement our own rev-parse --top-level
This commit is contained in:
parent
086e50728d
commit
bf457349b3
2 changed files with 15 additions and 0 deletions
|
|
@ -6,8 +6,22 @@ from plumbum import local
|
||||||
from pre_commit.util import memoize_by_cwd
|
from pre_commit.util import memoize_by_cwd
|
||||||
|
|
||||||
|
|
||||||
|
def _get_root_original():
|
||||||
|
return local['git']['rev-parse', '--show-toplevel']().strip()
|
||||||
|
|
||||||
|
def _get_root_new():
|
||||||
|
path = os.getcwd()
|
||||||
|
while len(path) > 1:
|
||||||
|
if os.path.exists(os.path.join(path, '.git')):
|
||||||
|
return path
|
||||||
|
else:
|
||||||
|
path = os.path.normpath(os.path.join(path, '../'))
|
||||||
|
raise AssertionError('called from outside of the gits')
|
||||||
|
|
||||||
|
|
||||||
@memoize_by_cwd
|
@memoize_by_cwd
|
||||||
def get_root():
|
def get_root():
|
||||||
|
return _get_root_new()
|
||||||
return local['git']['rev-parse', '--show-toplevel']().strip()
|
return local['git']['rev-parse', '--show-toplevel']().strip()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ from pre_commit import git
|
||||||
def get_pre_commit_dir_path():
|
def get_pre_commit_dir_path():
|
||||||
return os.path.join(git.get_root(), C.HOOKS_WORKSPACE)
|
return os.path.join(git.get_root(), C.HOOKS_WORKSPACE)
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def in_hooks_workspace():
|
def in_hooks_workspace():
|
||||||
"""Change into the hooks workspace. If it does not exist create it."""
|
"""Change into the hooks workspace. If it does not exist create it."""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue