summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGavin Mak <gavinmak@google.com>2023-01-26 23:27:51 +0000
committerGavin Mak <gavinmak@google.com>2023-01-28 02:05:52 +0000
commit7e3b65beb72ea4cc3ca8bfbd0816413217a520d0 (patch)
tree0b53df44ed1644a5878a72dc8613fd160cfc3074
parentc3d61ec2529790bb690071e229511cc641cea5ad (diff)
downloadgit-repo-7e3b65beb72ea4cc3ca8bfbd0816413217a520d0.tar.gz
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 <gavinmak@google.com> Reviewed-by: Mike Frysinger <vapier@google.com>
-rw-r--r--docs/internal-fs-layout.md4
-rw-r--r--git_config.py13
-rwxr-xr-xrepo5
3 files changed, 15 insertions, 7 deletions
diff --git a/docs/internal-fs-layout.md b/docs/internal-fs-layout.md
index 8be61782..401ebda1 100644
--- a/docs/internal-fs-layout.md
+++ b/docs/internal-fs-layout.md
@@ -243,7 +243,9 @@ The `[branch]` settings are updated by `repo start` and `git branch`.
243 243
244## ~/ dotconfig layout 244## ~/ dotconfig layout
245 245
246Repo will create & maintain a few files in the user's home directory. 246Repo will create & maintain a few files under the `.repoconfig/` directory.
247This is placed in the user's home directory by default but can be changed by
248setting `REPO_CONFIG_DIR`.
247 249
248* `.repoconfig/`: Repo's per-user directory for all random config files/state. 250* `.repoconfig/`: Repo's per-user directory for all random config files/state.
249* `.repoconfig/config`: Per-user settings using [git-config] file format. 251* `.repoconfig/config`: Per-user settings using [git-config] file format.
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):
69class GitConfig(object): 69class GitConfig(object):
70 _ForUser = None 70 _ForUser = None
71 71
72 _USER_CONFIG = '~/.gitconfig'
73
74 _ForSystem = None 72 _ForSystem = None
75 _SYSTEM_CONFIG = '/etc/gitconfig' 73 _SYSTEM_CONFIG = '/etc/gitconfig'
76 74
@@ -83,9 +81,13 @@ class GitConfig(object):
83 @classmethod 81 @classmethod
84 def ForUser(cls): 82 def ForUser(cls):
85 if cls._ForUser is None: 83 if cls._ForUser is None:
86 cls._ForUser = cls(configfile=os.path.expanduser(cls._USER_CONFIG)) 84 cls._ForUser = cls(configfile=cls._getUserConfig())
87 return cls._ForUser 85 return cls._ForUser
88 86
87 @staticmethod
88 def _getUserConfig():
89 return os.path.expanduser('~/.gitconfig')
90
89 @classmethod 91 @classmethod
90 def ForRepository(cls, gitdir, defaults=None): 92 def ForRepository(cls, gitdir, defaults=None):
91 return cls(configfile=os.path.join(gitdir, 'config'), 93 return cls(configfile=os.path.join(gitdir, 'config'),
@@ -415,7 +417,10 @@ class GitConfig(object):
415class RepoConfig(GitConfig): 417class RepoConfig(GitConfig):
416 """User settings for repo itself.""" 418 """User settings for repo itself."""
417 419
418 _USER_CONFIG = '~/.repoconfig/config' 420 @staticmethod
421 def _getUserConfig():
422 repo_config_dir = os.getenv('REPO_CONFIG_DIR', os.path.expanduser('~'))
423 return os.path.join(repo_config_dir, '.repoconfig/config')
419 424
420 425
421class RefSpec(object): 426class RefSpec(object):
diff --git a/repo b/repo
index 8030afbd..ce3df054 100755
--- a/repo
+++ b/repo
@@ -149,7 +149,7 @@ if not REPO_REV:
149BUG_URL = 'https://bugs.chromium.org/p/gerrit/issues/entry?template=Repo+tool+issue' 149BUG_URL = 'https://bugs.chromium.org/p/gerrit/issues/entry?template=Repo+tool+issue'
150 150
151# increment this whenever we make important changes to this script 151# increment this whenever we make important changes to this script
152VERSION = (2, 30) 152VERSION = (2, 32)
153 153
154# increment this if the MAINTAINER_KEYS block is modified 154# increment this if the MAINTAINER_KEYS block is modified
155KEYRING_VERSION = (2, 3) 155KEYRING_VERSION = (2, 3)
@@ -265,7 +265,8 @@ else:
265 urllib.error = urllib2 265 urllib.error = urllib2
266 266
267 267
268home_dot_repo = os.path.expanduser('~/.repoconfig') 268repo_config_dir = os.getenv('REPO_CONFIG_DIR', os.path.expanduser('~'))
269home_dot_repo = os.path.join(repo_config_dir, '.repoconfig')
269gpg_dir = os.path.join(home_dot_repo, 'gnupg') 270gpg_dir = os.path.join(home_dot_repo, 'gnupg')
270 271
271 272