diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-05-30 11:16:43 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-05-30 11:16:44 +0900 |
commit | b784d0be5dc05f2146c1505d1adf637edba4b1bb (patch) | |
tree | 543ec519f90dc41e9825c079e11d072b3dddcaa7 /config.c | |
parent | 02c531eba2925d89856baca8dc6a9d1b31bc4d7f (diff) | |
parent | 0624c63ce6a488d3d8bccc4b1e79cc2093e2c4a4 (diff) | |
download | git-b784d0be5dc05f2146c1505d1adf637edba4b1bb.tar.gz |
Merge branch 'ab/conditional-config-with-symlinks'
The recently introduced "[includeIf "gitdir:$dir"] path=..."
mechansim has further been taught to take symlinks into account.
The directory "$dir" specified in "gitdir:$dir" may be a symlink to
a real location, not something that $(getcwd) may return. In such
a case, a realpath of "$dir" is compared with the real path of the
current repository to determine if the contents from the named path
should be included.
* ab/conditional-config-with-symlinks:
config: match both symlink & realpath versions in IncludeIf.gitdir:*
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -214,6 +214,7 @@ static int include_by_gitdir(const struct config_options *opts, struct strbuf pattern = STRBUF_INIT; int ret = 0, prefix; const char *git_dir; + int already_tried_absolute = 0; if (opts->git_dir) git_dir = opts->git_dir; @@ -226,6 +227,7 @@ static int include_by_gitdir(const struct config_options *opts, strbuf_add(&pattern, cond, cond_len); prefix = prepare_include_condition_pattern(&pattern); +again: if (prefix < 0) goto done; @@ -245,6 +247,20 @@ static int include_by_gitdir(const struct config_options *opts, ret = !wildmatch(pattern.buf + prefix, text.buf + prefix, icase ? WM_CASEFOLD : 0, NULL); + if (!ret && !already_tried_absolute) { + /* + * We've tried e.g. matching gitdir:~/work, but if + * ~/work is a symlink to /mnt/storage/work + * strbuf_realpath() will expand it, so the rule won't + * match. Let's match against a + * strbuf_add_absolute_path() version of the path, + * which'll do the right thing + */ + strbuf_reset(&text); + strbuf_add_absolute_path(&text, git_dir); + already_tried_absolute = 1; + goto again; + } done: strbuf_release(&pattern); strbuf_release(&text); |