def __init__(self, path=None): """ Create a new repo.Local instance. :param path: local path to valid git repository. :returns: repo.Local instance. """ path = os.path.abspath(os.path.expandvars(os.path.expanduser(path or os.getcwd()))) if not os.path.exists(path): raise RepoError('Invalid path: %s' % path) curpath = path while curpath: if is_git_dir(curpath): self.git_dir = curpath self._working_tree_dir = os.path.dirname(curpath) break gitpath = os.path.join(curpath, '.git') if is_git_dir(gitpath): self.git_dir = gitpath self._working_tree_dir = curpath break curpath, dummy = os.path.split(curpath) if not dummy: break if not is_repo(self.git_dir): raise RepoError('Invalid path: %s' % path) super(Local, self).__init__(self.git_dir) self.name = os.path.basename(path) self.path = path self.abspath = os.path.abspath(self.path) self.user = self.author self.comment = self.message self.type = "local" self.is_bare = self.bare
def is_repo(path): """:return: True if path is a valid repository""" return is_git_dir(path)