git_config: add support for repo-specific settings

This allows people to write ~/.repoconfig/config akin to ~/.gitconfig
and .repo/config akin to .git/config.  This allows us to add settings
specific to repo without mixing up git, and to persist in general.

Change-Id: I1c6fbe31e63fb8ce26aa85335349c6ae5b1712c6
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/255832
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Tested-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
Mike Frysinger 2020-02-18 21:31:51 -05:00
parent c0d1866b35
commit f841ca48c1
2 changed files with 16 additions and 1 deletions

View File

@ -23,6 +23,10 @@ It is always safe to re-run `repo init` in existing repo client checkouts.
For example, if you want to change the manifest branch, you can simply run
`repo init --manifest-branch=<new name>` and repo will take care of the rest.
* `config`: Per-repo client checkout settings using [git-config] file format.
* `.repo_config.json`: JSON cache of the `config` file for repo to
read/process quickly.
### repo/ state
* `repo/`: A git checkout of the repo project. This is how `repo` re-execs
@ -198,12 +202,15 @@ The `[branch]` settings are updated by `repo start` and `git branch`.
Repo will create & maintain a few files in the user's home directory.
* `.repoconfig/`: Repo's per-user directory for all random config files/state.
* `.repoconfig/config`: Per-user settings using [git-config] file format.
* `.repoconfig/keyring-version`: Cache file for checking if the gnupg subdir
has all the same keys as the repo launcher. Used to avoid running gpg
constantly as that can be quite slow.
* `.repoconfig/gnupg/`: GnuPG's internal state directory used when repo needs
to run `gpg`. This provides isolation from the user's normal `~/.gnupg/`.
* `.repoconfig/.repo_config.json`: JSON cache of the `.repoconfig/config`
file for repo to read/process quickly.
* `.repo_.gitconfig.json`: JSON cache of the `.gitconfig` file for repo to
read/process quickly.

View File

@ -88,10 +88,12 @@ def _key(name):
class GitConfig(object):
_ForUser = None
_USER_CONFIG = '~/.gitconfig'
@classmethod
def ForUser(cls):
if cls._ForUser is None:
cls._ForUser = cls(configfile=os.path.expanduser('~/.gitconfig'))
cls._ForUser = cls(configfile=os.path.expanduser(cls._USER_CONFIG))
return cls._ForUser
@classmethod
@ -373,6 +375,12 @@ class GitConfig(object):
GitError('git config %s: %s' % (str(args), p.stderr))
class RepoConfig(GitConfig):
"""User settings for repo itself."""
_USER_CONFIG = '~/.repoconfig/config'
class RefSpec(object):
"""A Git refspec line, split into its components: