diff options
author | Junio C Hamano <gitster@pobox.com> | 2012-07-09 09:00:35 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-07-09 09:00:36 -0700 |
commit | d02d7ac303b1a22c7de4a6c3a00074d38b498134 (patch) | |
tree | 00bb203b30a44c8e389119694f722a5d09bcda49 /config.c | |
parent | 8228a23b35f6bd34a87d4d839d06e7c18ae9e750 (diff) | |
parent | 0e8593dc5b812df00400347e88f5707225fe831e (diff) | |
download | git-d02d7ac303b1a22c7de4a6c3a00074d38b498134.tar.gz |
Merge branch 'mm/config-xdg'
Teach git to read various information from $XDG_CONFIG_HOME/git/ to allow
the user to avoid cluttering $HOME.
* mm/config-xdg:
config: write to $XDG_CONFIG_HOME/git/config file when appropriate
Let core.attributesfile default to $XDG_CONFIG_HOME/git/attributes
Let core.excludesfile default to $XDG_CONFIG_HOME/git/ignore
config: read (but not write) from $XDG_CONFIG_HOME/git/config file
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 23 |
1 files changed, 14 insertions, 9 deletions
@@ -929,7 +929,10 @@ int git_config_system(void) int git_config_early(config_fn_t fn, void *data, const char *repo_config) { int ret = 0, found = 0; - const char *home = NULL; + char *xdg_config = NULL; + char *user_config = NULL; + + home_config_paths(&user_config, &xdg_config, "config"); if (git_config_system() && !access(git_etc_gitconfig(), R_OK)) { ret += git_config_from_file(fn, git_etc_gitconfig(), @@ -937,14 +940,14 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config) found += 1; } - home = getenv("HOME"); - if (home) { - char buf[PATH_MAX]; - char *user_config = mksnpath(buf, sizeof(buf), "%s/.gitconfig", home); - if (!access(user_config, R_OK)) { - ret += git_config_from_file(fn, user_config, data); - found += 1; - } + if (!access(xdg_config, R_OK)) { + ret += git_config_from_file(fn, xdg_config, data); + found += 1; + } + + if (!access(user_config, R_OK)) { + ret += git_config_from_file(fn, user_config, data); + found += 1; } if (repo_config && !access(repo_config, R_OK)) { @@ -963,6 +966,8 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config) break; } + free(xdg_config); + free(user_config); return ret == 0 ? found : ret; } |