| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -98,7 +98,9 @@ def __init__(self, git_dir=None): | |||
| 98 | 98 | ||
| 99 | 99 | ``git_dir`` | |
| 100 | 100 | Git directory we should work in. If None, we always work in the current | |
| 101 | - directory as returned by os.getcwd() | ||
| 101 | + directory as returned by os.getcwd(). | ||
| 102 | + It is meant to be the working tree directory if available, or the | ||
| 103 | + .git directory in case of bare repositories. | ||
| 102 | 104 | """ | |
| 103 | 105 | super(Git, self).__init__() | |
| 104 | 106 | self.git_dir = git_dir | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -88,7 +88,7 @@ def __init__(self, path=None): | |||
| 88 | 88 | while curpath: | |
| 89 | 89 | if is_git_dir(curpath): | |
| 90 | 90 | self.path = curpath | |
| 91 | - self.wd = curpath | ||
| 91 | + self.wd = os.path.dirname(curpath) | ||
| 92 | 92 | break | |
| 93 | 93 | gitpath = os.path.join(curpath, '.git') | |
| 94 | 94 | if is_git_dir(gitpath): | |
@@ -99,16 +99,21 @@ def __init__(self, path=None): | |||
| 99 | 99 | if not dummy: | |
| 100 | 100 | break | |
| 101 | 101 | # END while curpath | |
| 102 | + | ||
| 103 | + if self.path is None: | ||
| 104 | + raise InvalidGitRepositoryError(epath) | ||
| 102 | 105 | ||
| 103 | 106 | self._bare = False | |
| 104 | 107 | try: | |
| 105 | 108 | self._bare = self.config_reader("repository").getboolean('core','bare') | |
| 106 | 109 | except Exception: | |
| 107 | 110 | # lets not assume the option exists, although it should | |
| 108 | 111 | pass | |
| 109 | - | ||
| 110 | - if self.path is None: | ||
| 111 | - raise InvalidGitRepositoryError(epath) | ||
| 112 | + | ||
| 113 | + # adjust the wd in case we are actually bare - we didn't know that | ||
| 114 | + # in the first place | ||
| 115 | + if self._bare: | ||
| 116 | + self.wd = self.path | ||
| 112 | 117 | ||
| 113 | 118 | self.git = Git(self.wd) | |
| 114 | 119 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,6 +20,13 @@ def test_new_should_raise_on_invalid_repo_location(self): | |||
| 20 | 20 | def test_new_should_raise_on_non_existant_path(self): | |
| 21 | 21 | Repo("repos/foobar") | |
| 22 | 22 | ||
| 23 | + def test_repo_creation_from_different_paths(self): | ||
| 24 | + r_from_gitdir = Repo(self.rorepo.path) | ||
| 25 | + assert r_from_gitdir.path == self.rorepo.path | ||
| 26 | + assert r_from_gitdir.path.endswith('.git') | ||
| 27 | + assert not self.rorepo.git.git_dir.endswith('.git') | ||
| 28 | + assert r_from_gitdir.git.git_dir == self.rorepo.git.git_dir | ||
| 29 | + | ||
| 23 | 30 | def test_description(self): | |
| 24 | 31 | txt = "Test repository" | |
| 25 | 32 | self.rorepo.description = txt | |
| Back | FazBrowse Home | New Git URL |
0 commit comments