git_config: Fix bugs in processing RepoConfig.

- Automatically create all the parent directories for `git confing
  --file ...`
- Prevent `RepoConfig` from inheriting caches from `GitConfig`. These
  two are different files.

Bug: 569927750
Test: ./run_tests
Change-Id: I9c60cecff75c1fb62be3ff63425d9618c0f56b06
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/643263
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Insaf Latypov <saferif@google.com>
Commit-Queue: Insaf Latypov <saferif@google.com>
This commit is contained in:
Insaf Latypov authored and gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com committed 2026-10-14 07:49:21 -07:00
1 parent 3448df3954
commit a0bc2b14a3
2 files changed
+32

No files matched your search

+12
View File
@@ -266,6 +266,13 @@ class GitConfig:
except KeyError:
old = []
if self.file != self._SYSTEM_CONFIG:
# `git config --file` does not create missing parent directories
# (e.g. ~/.repoconfig/ on first use).
parent_dir = os.path.dirname(self.file)
if parent_dir:
os.makedirs(parent_dir, exist_ok=True)
if value is None:
if old:
del self._cache[key]
@@ -444,6 +451,11 @@ class GitConfig:
class RepoConfig(GitConfig):
"""User settings for repo itself."""
# Keep separate caches from GitConfig, otherwise ForUser()/ForSystem()
# would return the already-cached ~/.gitconfig instance of the parent.
_ForUser = None
_ForSystem = None
@staticmethod
def _getUserConfig():
repo_config_dir = os.getenv("REPO_CONFIG_DIR", os.path.expanduser("~"))