From: Huynh Khoi Nguyen NGUYEN Date: Sun, 03 Jun 2012 20:14:41 GMT Subject: [PATCHv5 4/4] Write to $XDG_CONFIG_HOME/git/config file Message-ID: <1338754481-27012-4-git-send-email-Huynh-Khoi-Nguyen.Nguyen@ensimag.imag.fr> In-Reply-To: <1338754481-27012-1-git-send-email-Huynh-Khoi-Nguyen.Nguyen@ensimag.imag.fr> From: NGUYEN Huynh Khoi Nguyen Git will be able to write to $XDG_CONFIG_HOME/git/config, a new configuration file following XDG specification, if: - this file already exists, and - $HOME/.gitconfig file doesn't, and - global option is used. Otherwise Git writes to $HOME/.gitconfig with global option, as usual. If you don't create $XDG_CONFIG_HOME/git/config, there is ABSOLUTELY NO change. Users can use this new file ONLY if they want. If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config will be used. Advice for users who often come back to an old version of GIT: you shouldn't create this file. Signed-off-by: Huynh Khoi Nguyen NGUYEN Signed-off-by: Valentin DUPERRAY Signed-off-by: Franck JONAS Signed-off-by: Thomas NGUY Signed-off-by: Lucien KONG Signed-off-by: Matthieu Moy --- Documentation/git-config.txt | 3 ++- builtin/config.c | 5 +---- t/t1306-xdg-files.sh | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 7e344a2..a2b4786 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -97,7 +97,8 @@ OPTIONS --global:: For writing options: write to global ~/.gitconfig file rather than - the repository .git/config. + the repository .git/config, write to $XDG_CONFIG_HOME/git/config file + if this file exists and ~/.gitconfig file doesn't. + For reading options: read only from global ~/.gitconfig and from $XDG_CONFIG_HOME/git/config rather than from all available files. diff --git a/builtin/config.c b/builtin/config.c index da54fd1..e8e1c0a 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -387,10 +387,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) home_config_paths(&user_config, &xdg_config, "config"); - if (access(user_config, R_OK) && !access(xdg_config, R_OK) && - (actions == ACTION_LIST || - actions == ACTION_GET_COLOR || - actions == ACTION_GET_COLORBOOL)) + if (access(user_config, R_OK) && !access(xdg_config, R_OK)) given_config_file = xdg_config; else if (user_config) given_config_file = user_config; diff --git a/t/t1306-xdg-files.sh b/t/t1306-xdg-files.sh index 80621ed..1ff709d 100755 --- a/t/t1306-xdg-files.sh +++ b/t/t1306-xdg-files.sh @@ -114,4 +114,22 @@ test_expect_success 'Checking attributes in a non-XDG global attributes file' ' test_cmp expected actual ' +test_expect_success 'write: xdg file exists and ~/.gitconfig doesn'\''t' ' + mkdir -p .config/git && + >.config/git/config && + rm .gitconfig && + git config --global user.name "write_config" && + echo "[user]" >expected && + echo " name = write_config" >>expected && + test_cmp expected .config/git/config +' + +test_expect_success 'write: xdg file exists and ~/.gitconfig exists' ' + >.gitconfig && + git config --global user.name "write_gitconfig" && + echo "[user]" >expected && + echo " name = write_gitconfig" >>expected && + test_cmp expected .gitconfig +' + test_done -- 1.7.8