| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bfce49f commit 96c6ab4
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ Changelog | |||
| 8 | 8 | * diff() can now properly detect renames, both in patch and raw format. Previously it only worked when create_patch was True. | |
| 9 | 9 | * repo.odb.update_cache() is now called automatically after fetch and pull operations. In case you did that in your own code, you might want to remove your line to prevent a double-update that causes unnecessary IO. | |
| 10 | 10 | * A list of all fixed issues can be found here: https://github.com/gitpython-developers/GitPython/issues?q=milestone%3A%22v0.3.5+-+bugfixes%22+ | |
| 11 | + * `Repo(path)` will not automatically search upstream anymore and find any git directory on its way up. If you need that behaviour, you can turn it back on using the new `search_parent_directories=True` flag when constructing a `Repo` object. | ||
| 11 | 12 | ||
| 12 | 13 | 0.3.4 - Python 3 Support | |
| 13 | 14 | ======================== | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,7 +46,6 @@ | |||
| 46 | 46 | rev_parse, | |
| 47 | 47 | is_git_dir, | |
| 48 | 48 | find_git_dir, | |
| 49 | - read_gitfile, | ||
| 50 | 49 | touch, | |
| 51 | 50 | ) | |
| 52 | 51 | from git.compat import ( | |
@@ -96,7 +95,7 @@ class Repo(object): | |||
| 96 | 95 | # represents the configuration level of a configuration file | |
| 97 | 96 | config_level = ("system", "global", "repository") | |
| 98 | 97 | ||
| 99 | - def __init__(self, path=None, odbt=DefaultDBType): | ||
| 98 | + def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=False): | ||
| 100 | 99 | """Create a new Repo instance | |
| 101 | 100 | ||
| 102 | 101 | :param path: is the path to either the root git directory or the bare git repo:: | |
@@ -128,15 +127,14 @@ def __init__(self, path=None, odbt=DefaultDBType): | |||
| 128 | 127 | self.git_dir = curpath | |
| 129 | 128 | self._working_tree_dir = os.path.dirname(curpath) | |
| 130 | 129 | break | |
| 130 | + | ||
| 131 | 131 | gitpath = find_git_dir(join(curpath, '.git')) | |
| 132 | 132 | if gitpath is not None: | |
| 133 | 133 | self.git_dir = gitpath | |
| 134 | 134 | self._working_tree_dir = curpath | |
| 135 | 135 | break | |
| 136 | - gitpath = read_gitfile(curpath) | ||
| 137 | - if gitpath: | ||
| 138 | - self.git_dir = gitpath | ||
| 139 | - self._working_tree_dir = curpath | ||
| 136 | + | ||
| 137 | + if not search_parent_directories: | ||
| 140 | 138 | break | |
| 141 | 139 | curpath, dummy = os.path.split(curpath) | |
| 142 | 140 | if not dummy: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,8 +19,8 @@ | |||
| 19 | 19 | from git.compat import xrange | |
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | - __all__ = ('rev_parse', 'is_git_dir', 'touch', 'read_gitfile', 'find_git_dir', 'name_to_object', | ||
| 23 | - 'short_to_long', 'deref_tag', 'to_commit') | ||
| 22 | + __all__ = ('rev_parse', 'is_git_dir', 'touch', 'find_git_dir', 'name_to_object', 'short_to_long', 'deref_tag', | ||
| 23 | + 'to_commit') | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | 26 | def touch(filename): | |
@@ -44,32 +44,21 @@ def is_git_dir(d): | |||
| 44 | 44 | def find_git_dir(d): | |
| 45 | 45 | if is_git_dir(d): | |
| 46 | 46 | return d | |
| 47 | - elif isfile(d): | ||
| 47 | + | ||
| 48 | + try: | ||
| 48 | 49 | with open(d) as fp: | |
| 49 | 50 | content = fp.read().rstrip() | |
| 51 | + except (IOError, OSError): | ||
| 52 | + # it's probably not a file | ||
| 53 | + pass | ||
| 54 | + else: | ||
| 50 | 55 | if content.startswith('gitdir: '): | |
| 51 | 56 | d = join(dirname(d), content[8:]) | |
| 52 | 57 | return find_git_dir(d) | |
| 58 | + # end handle exception | ||
| 53 | 59 | return None | |
| 54 | 60 | ||
| 55 | 61 | ||
| 56 | - def read_gitfile(f): | ||
| 57 | - """ This is taken from the git setup.c:read_gitfile function. | ||
| 58 | - :return gitdir path or None if gitfile is invalid.""" | ||
| 59 | - if f is None: | ||
| 60 | - return None | ||
| 61 | - try: | ||
| 62 | - line = open(f, 'r').readline().rstrip() | ||
| 63 | - except (OSError, IOError): | ||
| 64 | - # File might not exist or is unreadable - ignore | ||
| 65 | - return None | ||
| 66 | - # end handle file access | ||
| 67 | - if line[0:8] != 'gitdir: ': | ||
| 68 | - return None | ||
| 69 | - path = os.path.realpath(line[8:]) | ||
| 70 | - return path if is_git_dir(path) else None | ||
| 71 | - | ||
| 72 | - | ||
| 73 | 62 | def short_to_long(odb, hexsha): | |
| 74 | 63 | """:return: long hexadecimal sha1 from the given less-than-40 byte hexsha | |
| 75 | 64 | or None if no candidate could be found. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,8 +56,8 @@ def setUp(self): | |||
| 56 | 56 | "your choice - defaulting to the gitpython repository") | |
| 57 | 57 | repo_path = os.path.dirname(__file__) | |
| 58 | 58 | # end set some repo path | |
| 59 | - self.gitrorepo = Repo(repo_path, odbt=GitCmdObjectDB) | ||
| 60 | - self.puregitrorepo = Repo(repo_path, odbt=GitDB) | ||
| 59 | + self.gitrorepo = Repo(repo_path, odbt=GitCmdObjectDB, search_parent_directories=True) | ||
| 60 | + self.puregitrorepo = Repo(repo_path, odbt=GitDB, search_parent_directories=True) | ||
| 61 | 61 | ||
| 62 | 62 | def tearDown(self): | |
| 63 | 63 | self.gitrorepo.git.clear_cache() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments