From 7e3b65beb72ea4cc3ca8bfbd0816413217a520d0 Mon Sep 17 00:00:00 2001 From: Gavin Mak Date: Thu, 26 Jan 2023 23:27:51 +0000 Subject: Enable use of REPO_CONFIG_DIR to customize .repoconfig location For use cases with multiple instances of repo, eg some CI environments. Bug: https://crbug.com/gerrit/15803 Change-Id: I65c1cfc8f6a98adfeb5efefc7ac6b45bf8e134de Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/356719 Tested-by: Gavin Mak Reviewed-by: Mike Frysinger --- git_config.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'git_config.py') diff --git a/git_config.py b/git_config.py index 029beb4d..9ad979ad 100644 --- a/git_config.py +++ b/git_config.py @@ -69,8 +69,6 @@ def _key(name): class GitConfig(object): _ForUser = None - _USER_CONFIG = '~/.gitconfig' - _ForSystem = None _SYSTEM_CONFIG = '/etc/gitconfig' @@ -83,9 +81,13 @@ class GitConfig(object): @classmethod def ForUser(cls): if cls._ForUser is None: - cls._ForUser = cls(configfile=os.path.expanduser(cls._USER_CONFIG)) + cls._ForUser = cls(configfile=cls._getUserConfig()) return cls._ForUser + @staticmethod + def _getUserConfig(): + return os.path.expanduser('~/.gitconfig') + @classmethod def ForRepository(cls, gitdir, defaults=None): return cls(configfile=os.path.join(gitdir, 'config'), @@ -415,7 +417,10 @@ class GitConfig(object): class RepoConfig(GitConfig): """User settings for repo itself.""" - _USER_CONFIG = '~/.repoconfig/config' + @staticmethod + def _getUserConfig(): + repo_config_dir = os.getenv('REPO_CONFIG_DIR', os.path.expanduser('~')) + return os.path.join(repo_config_dir, '.repoconfig/config') class RefSpec(object): -- cgit v1.2.3-54-g00ecf