Re: [PATCH] config: introduce GIT_GLOBAL_CONFIG to override ~/.gitconfig
From: Matthieu Moy <hidden>
Date: 2016-06-15 22:54:52
Ramkumar Ramachandra [off-list ref] writes:
quoted hunk
diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index eaea079..c8db03f 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt@@ -205,6 +205,9 @@ $GIT_DIR/config:: User-specific configuration file. Also called "global" configuration file. +$GIT_GLOBAL_CONFIG:: + Overrides the path of the global configuration file. +
I'm not particularly in favor of introducing another environment variable, but if you are to introduce it, why just override the configuration file, and not $HOME completely (e.g. to override $HOME/.git-credentials too). There was a patch proposing that here ($GIT_HOME to override $HOME): http://thread.gmane.org/gmane.comp.version-control.git/135447/focus=135494 I don't remember exactly what happened to the patch, I can't find an explicit reason to reject it in the thread, but it seems it didn't make its way to git.git.
quoted hunk
index cbbdf7d..9b09cee 100644--- a/path.c +++ b/path.c@@ -131,10 +131,15 @@ char *git_path(const char *fmt, ...) void home_config_paths(char **global, char **xdg, char *file) { + char *global_config = getenv("GIT_GLOBAL_CONFIG"); char *xdg_home = getenv("XDG_CONFIG_HOME"); char *home = getenv("HOME"); char *to_free = NULL; + if (global_config) { + *global = mkpathdup("%s", global_config); + return; + }
If you return here, haven't you completely broken the XDG stuff, since *xdg is set a few lines below in the function? Also, I guess home_config_paths(..., "ignore") will return the path to the configuration file instead of the ignore file?
quoted hunk
--- a/t/t1306-xdg-files.sh +++ b/t/t1306-xdg-files.sh@@ -28,6 +28,14 @@ test_expect_success 'read config: xdg file exists and ~/.gitconfig exists' ' test_cmp expected actual ' +test_expect_success 'read config: $GIT_GLOBAL_CONFIG is set and ~/.gitconfig exists' ' + >.gitconfig && + echo "[alias]" >.gittestconfig && + echo " myalias = !echo in_gitconfig" >>.gittestconfig && + echo in_gitconfig >expected && + GIT_GLOBAL_CONFIG=~/.gittestconfig git myalias >actual && + test_cmp expected actual +'
You should check that "git config --set" works too, as the codepath for writing to configuration is relatively different from the one to read. For example, I *think* that "git config --global" will write to $GIT_GLOBAL_CONFIG and "git config" without --global will ignore it, but a test would be welcome. -- Matthieu Moy http://www-verimag.imag.fr/~moy/