Do not use .strip(), add two check git has
This commit is contained in:
parent
ba45a002dc
commit
c603410843
|
@ -28,8 +28,13 @@ def git_directory(directory):
|
||||||
path = os.path.join(directory, '.git')
|
path = os.path.join(directory, '.git')
|
||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
with open(path, 'rb') as f:
|
with open(path, 'rb') as f:
|
||||||
raw = f.read().partition(b':')[2].strip()
|
raw = f.read()
|
||||||
return os.path.abspath(os.path.join(directory, raw.decode(sys.getfilesystemencoding() or 'utf-8')))
|
if not raw.startswith(b'gitdir: '):
|
||||||
|
raise IOError('invalid gitfile format')
|
||||||
|
raw = raw[8:].decode(sys.getfilesystemencoding() or 'utf-8')
|
||||||
|
if not raw:
|
||||||
|
raise IOError('no path in gitfile')
|
||||||
|
return os.path.abspath(os.path.join(directory, raw))
|
||||||
else:
|
else:
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue