From 706d3a28b6fa2d7ff90bbc564a53f4007321534f Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 19 Nov 2014 11:20:01 +0100 Subject: Minor fix to make read_gitfile work . --- git/repo/fun.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'git/repo/fun.py') diff --git a/git/repo/fun.py b/git/repo/fun.py index f5abc27a..0bff677a 100644 --- a/git/repo/fun.py +++ b/git/repo/fun.py @@ -13,7 +13,8 @@ from gitdb.util import ( ) from string import digits -__all__ = ('rev_parse', 'is_git_dir', 'touch') +__all__ = ('rev_parse', 'is_git_dir', 'touch', 'read_gitfile', 'find_git_dir', 'name_to_object', + 'short_to_long', 'deref_tag', 'to_commit') def touch(filename): @@ -46,16 +47,20 @@ def find_git_dir(d): return None def read_gitfile(f): - """ This is taken from the git setup.c:read_gitfile function. - :return gitdir path or None if gitfile is invalid.""" - - if not isfile(f): - return None - line = open(f, 'r').readline().rstrip() - if line[0:8] != 'gitdir: ': - return None - path = os.path.realpath(line[8:]) - return path if is_git_dir(path) else None + """ This is taken from the git setup.c:read_gitfile function. + :return gitdir path or None if gitfile is invalid.""" + if f is None: + return None + try: + line = open(f, 'r').readline().rstrip() + except (OSError, IOError): + # File might not exist or is unreadable - ignore + return None + # end handle file access + if line[0:8] != 'gitdir: ': + return None + path = os.path.realpath(line[8:]) + return path if is_git_dir(path) else None def short_to_long(odb, hexsha): """:return: long hexadecimal sha1 from the given less-than-40 byte hexsha -- cgit v1.2.1