mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Fix rev-parse for older git versions
This commit is contained in:
parent
4b0a22a8ba
commit
18b6f4b519
1 changed files with 7 additions and 10 deletions
|
|
@ -31,16 +31,13 @@ def get_root():
|
||||||
|
|
||||||
|
|
||||||
def get_git_dir(git_root):
|
def get_git_dir(git_root):
|
||||||
def _git_dir(opt):
|
opts = ('--git-common-dir', '--git-dir')
|
||||||
return os.path.normpath(os.path.join(
|
_, out, _ = cmd_output('git', 'rev-parse', *opts, cwd=git_root)
|
||||||
git_root,
|
for line, opt in zip(out.splitlines(), opts):
|
||||||
cmd_output('git', 'rev-parse', opt, cwd=git_root)[1].strip(),
|
if line != opt: # pragma: no branch (git < 2.5)
|
||||||
))
|
return os.path.normpath(os.path.join(git_root, line))
|
||||||
|
else:
|
||||||
try:
|
raise AssertionError('unreachable: no git dir')
|
||||||
return _git_dir('--git-common-dir')
|
|
||||||
except CalledProcessError: # pragma: no cover (git < 2.5)
|
|
||||||
return _git_dir('--git-dir')
|
|
||||||
|
|
||||||
|
|
||||||
def get_remote_url(git_root):
|
def get_remote_url(git_root):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue