summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2019-07-16 11:42:43 +0200
committerSebastian Thiel <byronimo@gmail.com>2019-08-11 14:28:45 +0800
commit0b6b90f9f1e5310a6f39b75e17a04c1133269e8f (patch)
treee3ce9c3e318cfaf5264fcf8d0018c283dcffcb22
parentdaa3f353091ada049c0ede23997f4801cbe9941b (diff)
downloadgitpython-0b6b90f9f1e5310a6f39b75e17a04c1133269e8f.tar.gz
use git rev-parse to look for config file
-rw-r--r--git/repo/base.py56
-rw-r--r--git/test/lib/helper.py3
2 files changed, 41 insertions, 18 deletions
diff --git a/git/repo/base.py b/git/repo/base.py
index f3587080..af8e0c74 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -66,7 +66,7 @@ class Repo(object):
'git_dir' is the .git repository directory, which is always set."""
DAEMON_EXPORT_FILE = 'git-daemon-export-ok'
- git = None # Must exist, or __del__ will fail in case we raise on `__init__()`
+ _git = None # Must exist, or __del__ will fail in case we raise on `__init__()`
working_dir = None
_working_tree_dir = None
git_dir = None
@@ -202,7 +202,6 @@ class Repo(object):
# END working dir handling
self.working_dir = self._working_tree_dir or self.common_dir
- self.git = self.GitCommandWrapperType(self.working_dir)
# special handling, in special times
args = [osp.join(self.common_dir, 'objects')]
@@ -210,6 +209,35 @@ class Repo(object):
args.append(self.git)
self.odb = odbt(*args)
+ def _get_git(self):
+ working_dir = self._working_tree_dir or self.common_dir
+ if self._git:
+ if self._git._working_dir != expand_path(working_dir):
+ self.close()
+ self._git = None
+
+ if not self._git:
+ self._git = self.GitCommandWrapperType(working_dir)
+ return self._git
+
+ def _del_git(self):
+ if self._git:
+ self._git.clear_cache()
+ self._git = None
+ # Tempfiles objects on Windows are holding references to
+ # open files until they are collected by the garbage
+ # collector, thus preventing deletion.
+ # TODO: Find these references and ensure they are closed
+ # and deleted synchronously rather than forcing a gc
+ # collection.
+ if is_win:
+ gc.collect()
+ gitdb.util.mman.collect()
+ if is_win:
+ gc.collect()
+
+ git = property(fget=_get_git, fdel=_del_git)
+
def __enter__(self):
return self
@@ -223,19 +251,7 @@ class Repo(object):
pass
def close(self):
- if self.git:
- self.git.clear_cache()
- # Tempfiles objects on Windows are holding references to
- # open files until they are collected by the garbage
- # collector, thus preventing deletion.
- # TODO: Find these references and ensure they are closed
- # and deleted synchronously rather than forcing a gc
- # collection.
- if is_win:
- gc.collect()
- gitdb.util.mman.collect()
- if is_win:
- gc.collect()
+ del self.git
def __eq__(self, rhs):
if isinstance(rhs, Repo):
@@ -431,7 +447,15 @@ class Repo(object):
elif config_level == "global":
return osp.normpath(osp.expanduser("~/.gitconfig"))
elif config_level == "repository":
- return osp.normpath(osp.join(self._common_dir or self.git_dir, "config"))
+ try:
+ config_path = self.git.rev_parse("config", git_path=True)
+ except GitCommandError:
+ return osp.normpath(osp.join(self._common_dir or self.git_dir, "config"))
+ else:
+ if self.git._working_dir:
+ return osp.normpath(osp.join(self.git._working_dir, config_path))
+ else:
+ return config_path
raise ValueError("Invalid configuration level: %r" % config_level)
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py
index 1c06010f..687db990 100644
--- a/git/test/lib/helper.py
+++ b/git/test/lib/helper.py
@@ -366,8 +366,7 @@ class TestBase(TestCase):
@classmethod
def tearDownClass(cls):
- cls.rorepo.git.clear_cache()
- cls.rorepo.git = None
+ del cls.rorepo.git
def _make_file(self, rela_path, data, repo=None):
"""