diff options
author | Florian Apolloner <florian@apolloner.eu> | 2008-06-25 00:41:41 +0200 |
---|---|---|
committer | Florian Apolloner <florian@apolloner.eu> | 2008-06-25 00:43:07 +0200 |
commit | 990d1fe06e8c2db48a895aaa7e5e5eda8b330a5c (patch) | |
tree | a529af9a05481053a9286a346be7612fdee15df6 /lib/git/repo.py | |
parent | 7fda0ec787de5159534ebc8b81824920d9613575 (diff) | |
download | gitpython-990d1fe06e8c2db48a895aaa7e5e5eda8b330a5c.tar.gz |
fixed http://groups.google.com/group/git-python/browse_thread/thread/b8f3580abf31f9db?hl=en# and passed Git a working_tree again (sort of).
Diffstat (limited to 'lib/git/repo.py')
-rw-r--r-- | lib/git/repo.py | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/lib/git/repo.py b/lib/git/repo.py index 7621c67b..f1a5a8ee 100644 --- a/lib/git/repo.py +++ b/lib/git/repo.py @@ -1,7 +1,7 @@ import os import re from errors import InvalidGitRepositoryError, NoSuchPathError -from utils import touch +from utils import touch, is_git_dir from cmd import Git from head import Head from blob import Blob @@ -27,25 +27,33 @@ class Repo(object): Returns ``GitPython.Repo`` """ - path = os.path.expanduser(path) - if not os.path.exists(path): - raise NoSuchPathError(path) - - self.git = Git(path) - self.path = self.git.get_git_dir() - if not self.path: - raise InvalidGitRepositoryError(path) - epath = self.git.get_work_tree() - - if os.path.exists(os.path.join(epath, '.git')): - self.bare = False - elif os.path.exists(epath) and epath.endswith('.git'): - self.bare = True - elif os.path.exists(epath): - raise InvalidGitRepositoryError(epath) - else: + + epath = os.path.abspath(os.path.expanduser(path or os.getcwd())) + + if not os.path.exists(epath): raise NoSuchPathError(epath) + self.path = None + curpath = epath + while curpath: + if is_git_dir(curpath): + self.bare = True + self.path, self.wd = curpath + break + gitpath = os.path.join(curpath, '.git') + if is_git_dir(gitpath): + self.bare = False + self.path = gitpath + self.wd = curpath + break + curpath, dummy = os.path.split(curpath) + if not dummy: + break + + if self.path is None: + raise InvalidGitRepositoryError(epath) + + self.git = Git(self.wd) @property def description(self): @@ -281,7 +289,7 @@ class Repo(object): if mkdir and not os.path.exists(path): os.makedirs(path, 0755) - git = Git(path, bare_repo=True) + git = Git(path) output = git.init(**kwargs) return Repo(path) create = init_bare @@ -370,10 +378,7 @@ class Repo(object): Returns None """ - if self.bare: - touch(os.path.join(self.path, DAEMON_EXPORT_FILE)) - else: - touch(os.path.join(self.path, '.git', DAEMON_EXPORT_FILE)) + touch(os.path.join(self.path, DAEMON_EXPORT_FILE)) def disable_daemon_serve(self): """ @@ -383,10 +388,7 @@ class Repo(object): Returns None """ - if self.bare: - return os.remove(os.path.join(self.path, DAEMON_EXPORT_FILE)) - else: - return os.remove(os.path.join(self.path, '.git', DAEMON_EXPORT_FILE)) + return os.remove(os.path.join(self.path, DAEMON_EXPORT_FILE)) def _get_alternates(self): """ |