summaryrefslogtreecommitdiff
path: root/lib/git/cmd.py
diff options
context:
space:
mode:
authorDavid Aguilar <davvid@gmail.com>2008-06-15 16:45:29 -0700
committerDavid Aguilar <davvid@gmail.com>2008-06-15 16:45:29 -0700
commitfd5f111439e7a2e730b602a155aa533c68badbf8 (patch)
treea9d2ae2b7b1fcc63fa75dac8d9134f749940e8de /lib/git/cmd.py
parentabc2e538c6f2fe50f93e6c3fe927236bb41f94f4 (diff)
downloadgitpython-fd5f111439e7a2e730b602a155aa533c68badbf8.tar.gz
cmd: better support for bare repositories
In order to avoid the expense of parsing .git/config just to know whether or not a repository is bare at __init__ time, we just pass an optional flag to Git.__init__(): bare_repo with a default value of False. Repo.init_bare() was updated to pass this flag. We could have an optional Git.read_bare_status() function that does the expensive lookup. Then, users can optionally call it at runtime if they really need to know whether or not a repository is bare. That seems like a decent tradeoff between speed, correctness, and common use cases. Signed-off-by: David Aguilar <davvid@gmail.com>
Diffstat (limited to 'lib/git/cmd.py')
-rw-r--r--lib/git/cmd.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/git/cmd.py b/lib/git/cmd.py
index d3a7e36b..1a764ed3 100644
--- a/lib/git/cmd.py
+++ b/lib/git/cmd.py
@@ -12,12 +12,13 @@ class Git(MethodMissingMixin):
"""
The Git class manages communication with the Git binary
"""
- def __init__(self, git_dir=None):
+ def __init__(self, git_dir=None, bare_repo=False):
super(Git, self).__init__()
if git_dir:
self._location = os.path.abspath(git_dir)
else:
self._location = os.getcwd()
+ self._is_bare_repo = bare_repo
self.refresh()
def refresh(self):
@@ -25,7 +26,7 @@ class Git(MethodMissingMixin):
self._is_in_repo = not not self.get_git_dir()
self._work_tree = None
self._cwd = self._git_dir
- if self._git_dir:
+ if self._git_dir and not self._is_bare_repo:
self._cwd = self.get_work_tree()
def _is_git_dir(self, d):
@@ -61,6 +62,8 @@ class Git(MethodMissingMixin):
return self._git_dir
def get_work_tree(self):
+ if self._is_bare_repo:
+ return None
if not self._work_tree:
self._work_tree = os.getenv('GIT_WORK_TREE')
if not self._work_tree or not os.path.isdir(self._work_tree):