diff options
author | Johannes Schindelin <Johannes.Schindelin@gmx.de> | 2006-06-20 01:48:03 +0200 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-06-19 17:53:13 -0700 |
commit | 5f1a63e0efc750c54a25644a36cf2905495a9b93 (patch) | |
tree | 45773aa356b3cabd718f9cbb9b32d08c79fd70fa /config.c | |
parent | 9c3796fc0474ac6fc77da4886a246a37a7fbe856 (diff) | |
download | git-5f1a63e0efc750c54a25644a36cf2905495a9b93.tar.gz git-5f1a63e0efc750c54a25644a36cf2905495a9b93.tar.xz |
Read configuration also from $HOME/.gitconfig
This patch is based on Pasky's, with three notable differences:
- I did not yet update the documentation
- I named it .gitconfig, not .gitrc
- git-repo-config does not barf when a unique key is overridden locally
The last means that if you have something like
[alias]
l = log --stat -M
in ~/.gitconfig, and
[alias]
l = log --stat -M next..
in $GIT_DIR/config, then
git-repo-config alias.l
returns only one value, namely the value from $GIT_DIR/config.
If you set the environment variable GIT_CONFIG, $HOME/.gitconfig is not
read, and neither $GIT_DIR/config, but $GIT_CONFIG instead.
If you set GIT_CONFIG_LOCAL instead, it is interpreted instead of
$GIT_DIR/config, but $HOME/.gitconfig is still read.
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 34 |
1 files changed, 25 insertions, 9 deletions
@@ -317,17 +317,33 @@ int git_config_from_file(config_fn_t fn, const char *filename) int git_config(config_fn_t fn) { - const char *filename = git_path("config"); - /* Forward-compatibility cue: $GIT_CONFIG makes git read _only_ - * the given config file, $GIT_CONFIG_LOCAL will make it process - * it in addition to the global config file, the same way it would - * the per-repository config file otherwise. */ - if (getenv("GIT_CONFIG")) { - filename = getenv("GIT_CONFIG"); - } else if (getenv("GIT_CONFIG_LOCAL")) { + int ret = 0; + char *repo_config = NULL; + const char *home = NULL, *filename; + + /* $GIT_CONFIG makes git read _only_ the given config file, + * $GIT_CONFIG_LOCAL will make it process it in addition to the + * global config file, the same way it would the per-repository + * config file otherwise. */ + filename = getenv("GIT_CONFIG"); + if (!filename) { + home = getenv("HOME"); filename = getenv("GIT_CONFIG_LOCAL"); + if (!filename) + filename = repo_config = strdup(git_path("config")); } - return git_config_from_file(fn, filename); + + if (home) { + char *user_config = strdup(mkpath("%s/.gitconfig", home)); + if (access(user_config, R_OK) > 0) + ret = git_config_from_file(fn, user_config); + free(user_config); + } + + ret += git_config_from_file(fn, filename); + if (repo_config) + free(repo_config); + return ret; } /* |