GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • git/repo
    • base.py
  • test
    • test_repo.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎git/repo/base.py‎

Copy file name to clipboardExpand all lines: git/repo/base.py
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,23 +356,23 @@ def __init__(
356356
raise InvalidGitRepositoryError(epath)
357357
self.git_dir = git_dir
358358

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-
366359
common_dir = os.getenv("GIT_COMMON_DIR")
367360
if common_dir is not None:
368-
self._common_dir = common_dir
361+
self._common_dir = osp.abspath(common_dir)
369362
else:
370363
try:
371364
common_dir = (Path(self.git_dir) / "commondir").read_text().splitlines()[0].strip()
372365
self._common_dir = osp.join(self.git_dir, common_dir)
373366
except OSError:
374367
self._common_dir = ""
375368

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+
376376
# Adjust the working directory in case we are actually bare - we didn't know
377377
# that in the first place.
378378
if self._bare:
Collapse file

‎test/test_repo.py‎

Copy file name to clipboardExpand all lines: test/test_repo.py
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,15 @@ def test_repo_discovery_uses_git_common_dir(self):
171171
(git_dir / "HEAD").write_text("ref: refs/heads/main\n")
172172
(common_dir / "objects").mkdir()
173173
(common_dir / "refs").mkdir()
174+
(common_dir / "config").write_text("[core]\n\tbare = true\n")
174175

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()
177179

178180
assert osp.samefile(repo.common_dir, common_dir)
179181
assert osp.samefile(repo.odb.root_path(), common_dir / "objects")
182+
assert repo.bare
180183

181184
@with_rw_repo("0.3.2.1")
182185
def test_repo_creation_from_different_paths(self, rw_repo):

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.