summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/git/cmd.py4
-rw-r--r--lib/git/repo.py13
-rw-r--r--test/git/test_repo.py7
3 files changed, 19 insertions, 5 deletions
diff --git a/lib/git/cmd.py b/lib/git/cmd.py
index 6ee8f355..b97381f4 100644
--- a/lib/git/cmd.py
+++ b/lib/git/cmd.py
@@ -98,7 +98,9 @@ class Git(object):
``git_dir``
Git directory we should work in. If None, we always work in the current
- directory as returned by os.getcwd()
+ directory as returned by os.getcwd().
+ It is meant to be the working tree directory if available, or the
+ .git directory in case of bare repositories.
"""
super(Git, self).__init__()
self.git_dir = git_dir
diff --git a/lib/git/repo.py b/lib/git/repo.py
index aba6cff0..3250230e 100644
--- a/lib/git/repo.py
+++ b/lib/git/repo.py
@@ -88,7 +88,7 @@ class Repo(object):
while curpath:
if is_git_dir(curpath):
self.path = curpath
- self.wd = curpath
+ self.wd = os.path.dirname(curpath)
break
gitpath = os.path.join(curpath, '.git')
if is_git_dir(gitpath):
@@ -99,6 +99,9 @@ class Repo(object):
if not dummy:
break
# END while curpath
+
+ if self.path is None:
+ raise InvalidGitRepositoryError(epath)
self._bare = False
try:
@@ -106,9 +109,11 @@ class Repo(object):
except Exception:
# lets not assume the option exists, although it should
pass
-
- if self.path is None:
- raise InvalidGitRepositoryError(epath)
+
+ # adjust the wd in case we are actually bare - we didn't know that
+ # in the first place
+ if self._bare:
+ self.wd = self.path
self.git = Git(self.wd)
diff --git a/test/git/test_repo.py b/test/git/test_repo.py
index 93ab7a90..e94a45bd 100644
--- a/test/git/test_repo.py
+++ b/test/git/test_repo.py
@@ -20,6 +20,13 @@ class TestRepo(TestBase):
def test_new_should_raise_on_non_existant_path(self):
Repo("repos/foobar")
+ def test_repo_creation_from_different_paths(self):
+ r_from_gitdir = Repo(self.rorepo.path)
+ assert r_from_gitdir.path == self.rorepo.path
+ assert r_from_gitdir.path.endswith('.git')
+ assert not self.rorepo.git.git_dir.endswith('.git')
+ assert r_from_gitdir.git.git_dir == self.rorepo.git.git_dir
+
def test_description(self):
txt = "Test repository"
self.rorepo.description = txt