Skip to content

Commit

Permalink
Merge branch 'mm/include-userpath'
Browse files Browse the repository at this point in the history
The new "include.path" directive in the configuration files learned
to understand "~/path" and "~user/path".

By Jeff King
* mm/include-userpath:
  config: expand tildes in include.path variable
  • Loading branch information
Junio C Hamano committed Apr 30, 2012
2 parents f61977f + 4c0a89f commit 5fa8bf6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~
Expand All @@ -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
~~~~~~~~~
Expand Down
6 changes: 6 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
8 changes: 8 additions & 0 deletions t/t1305-config-include.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit 5fa8bf6

Please sign in to comment.