From c603410843756c62c1573c3d75f5b0fe186db01c Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 23 Apr 2014 06:36:24 +0400 Subject: [PATCH] Do not use .strip(), add two check git has --- powerline/lib/vcs/git.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/powerline/lib/vcs/git.py b/powerline/lib/vcs/git.py index d3d112fa..77d1f387 100644 --- a/powerline/lib/vcs/git.py +++ b/powerline/lib/vcs/git.py @@ -28,8 +28,13 @@ def git_directory(directory): path = os.path.join(directory, '.git') if os.path.isfile(path): with open(path, 'rb') as f: - raw = f.read().partition(b':')[2].strip() - return os.path.abspath(os.path.join(directory, raw.decode(sys.getfilesystemencoding() or 'utf-8'))) + raw = f.read() + 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: return path