From 96c6ab4f7572fd5ca8638f3cb6e342d5000955e7 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 10 Jan 2015 18:22:48 +0100 Subject: Added search_parent_directories keyword argument to Repo type. Now by default, we will not walk up the directory structure and possibly find git directories that the user didn't intend to find. If required, that kind of behaviour can be turned back on. Fixes #65 --- git/repo/base.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'git/repo/base.py') diff --git a/git/repo/base.py b/git/repo/base.py index dbca4697..97e49aa2 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -46,7 +46,6 @@ from .fun import ( rev_parse, is_git_dir, find_git_dir, - read_gitfile, touch, ) from git.compat import ( @@ -96,7 +95,7 @@ class Repo(object): # represents the configuration level of a configuration file config_level = ("system", "global", "repository") - def __init__(self, path=None, odbt=DefaultDBType): + def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=False): """Create a new Repo instance :param path: is the path to either the root git directory or the bare git repo:: @@ -128,15 +127,14 @@ class Repo(object): self.git_dir = curpath self._working_tree_dir = os.path.dirname(curpath) break + gitpath = find_git_dir(join(curpath, '.git')) if gitpath is not None: self.git_dir = gitpath self._working_tree_dir = curpath break - gitpath = read_gitfile(curpath) - if gitpath: - self.git_dir = gitpath - self._working_tree_dir = curpath + + if not search_parent_directories: break curpath, dummy = os.path.split(curpath) if not dummy: -- cgit v1.2.1