diff options
author | Junio C Hamano <gitster@pobox.com> | 2012-05-10 10:33:05 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-05-10 10:33:05 -0700 |
commit | db8d6646786a9aa3242dc9eafbcef2e9f77ba7ab (patch) | |
tree | 17a6a3a49f7b4fd5678b8f382747880ce49d0a20 | |
parent | Merge branch 'cc/fix-missing-va-end-in-revert' into maint (diff) | |
parent | config: expand tildes in include.path variable (diff) | |
download | tgif-db8d6646786a9aa3242dc9eafbcef2e9f77ba7ab.tar.xz |
Merge branch 'mm/include-userpath' into maint
By Jeff King
* mm/include-userpath:
config: expand tildes in include.path variable
-rw-r--r-- | Documentation/config.txt | 5 | ||||
-rw-r--r-- | config.c | 6 | ||||
-rwxr-xr-x | t/t1305-config-include.sh | 8 |
3 files changed, 18 insertions, 1 deletions
diff --git a/Documentation/config.txt b/Documentation/config.txt index c081657be7..e67c8ef369 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -95,7 +95,9 @@ included file is expanded immediately, as if its contents had been found at the location of the include directive. If the value of the `include.path` variable is a relative path, the path is considered to be relative to the configuration file in which the include directive was -found. See below for examples. +found. The value of `include.path` is subject to tilde expansion: `{tilde}/` +is expanded to the value of `$HOME`, and `{tilde}user/` to the specified +user's home directory. See below for examples. Example ~~~~~~~ @@ -122,6 +124,7 @@ Example [include] path = /path/to/foo.inc ; include by absolute path path = foo ; expand "foo" relative to the current file + path = ~/foo ; expand "foo" in your $HOME directory Variables ~~~~~~~~~ @@ -37,6 +37,11 @@ static int handle_path_include(const char *path, struct config_include_data *inc { int ret = 0; struct strbuf buf = STRBUF_INIT; + char *expanded = expand_user_path(path); + + if (!expanded) + return error("Could not expand include path '%s'", path); + path = expanded; /* * Use an absolute path as-is, but interpret relative paths @@ -63,6 +68,7 @@ static int handle_path_include(const char *path, struct config_include_data *inc inc->depth--; } strbuf_release(&buf); + free(expanded); return ret; } diff --git a/t/t1305-config-include.sh b/t/t1305-config-include.sh index 4b1cbaa028..a70707620f 100755 --- a/t/t1305-config-include.sh +++ b/t/t1305-config-include.sh @@ -29,6 +29,14 @@ test_expect_success 'chained relative paths' ' test_cmp expect actual ' +test_expect_success 'include paths get tilde-expansion' ' + echo "[test]one = 1" >one && + echo "[include]path = ~/one" >.gitconfig && + echo 1 >expect && + git config test.one >actual && + test_cmp expect actual +' + test_expect_success 'include options can still be examined' ' echo "[test]one = 1" >one && echo "[include]path = one" >.gitconfig && |