GeezerVison is showing github.com — fix: initialize common directory before config · gitpython-developers/GitPython@f2d1c4c
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: git/repo/base.py +8-8Lines changed: 8 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -356,23 +356,23 @@ def __init__( |
356 | 356 | raise InvalidGitRepositoryError(epath) |
357 | 357 | self.git_dir = git_dir |
358 | 358 |
|
359 | | - self._bare = False |
360 | | - try: |
361 | | - self._bare = self.config_reader("repository").getboolean("core", "bare") |
362 | | - except Exception: |
363 | | - # Let's not assume the option exists, although it should. |
364 | | - pass |
365 | | - |
366 | 359 | common_dir = os.getenv("GIT_COMMON_DIR") |
367 | 360 | if common_dir is not None: |
368 | | - self._common_dir = common_dir |
| 361 | + self._common_dir = osp.abspath(common_dir) |
369 | 362 | else: |
370 | 363 | try: |
371 | 364 | common_dir = (Path(self.git_dir) / "commondir").read_text().splitlines()[0].strip() |
372 | 365 | self._common_dir = osp.join(self.git_dir, common_dir) |
373 | 366 | except OSError: |
374 | 367 | self._common_dir = "" |
375 | 368 |
|
| 369 | + self._bare = False |
| 370 | + try: |
| 371 | + self._bare = self.config_reader("repository").getboolean("core", "bare") |
| 372 | + except Exception: |
| 373 | + # Let's not assume the option exists, although it should. |
| 374 | + pass |
| 375 | + |
376 | 376 | # Adjust the working directory in case we are actually bare - we didn't know |
377 | 377 | # that in the first place. |
378 | 378 | if self._bare: |
|
Collapse file
Copy file name to clipboardExpand all lines: test/test_repo.py +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -171,12 +171,15 @@ def test_repo_discovery_uses_git_common_dir(self): |
171 | 171 | (git_dir / "HEAD").write_text("ref: refs/heads/main\n") |
172 | 172 | (common_dir / "objects").mkdir() |
173 | 173 | (common_dir / "refs").mkdir() |
| 174 | + (common_dir / "config").write_text("[core]\n\tbare = true\n") |
174 | 175 |
|
175 | | - with mock.patch.dict(os.environ, {"GIT_DIR": str(git_dir), "GIT_COMMON_DIR": str(common_dir)}): |
176 | | - repo = Repo() |
| 176 | + with cwd(tdir): |
| 177 | + with mock.patch.dict(os.environ, {"GIT_DIR": "git", "GIT_COMMON_DIR": "common"}): |
| 178 | + repo = Repo() |
177 | 179 |
|
178 | 180 | assert osp.samefile(repo.common_dir, common_dir) |
179 | 181 | assert osp.samefile(repo.odb.root_path(), common_dir / "objects") |
| 182 | + assert repo.bare |
180 | 183 |
|
181 | 184 | @with_rw_repo("0.3.2.1") |
182 | 185 | def test_repo_creation_from_different_paths(self, rw_repo): |
|