summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2017-05-16 08:28:46 +0000
committerJunio C Hamano <gitster@pobox.com>2017-05-17 10:32:26 +0900
commit0624c63ce6a488d3d8bccc4b1e79cc2093e2c4a4 (patch)
treeb78c1b9da859d05fad22c9ee4877bc050a727ee3 /config.c
parentc9672ba4c86a5fb18ea20d1c4a2c0eb6a731f3cb (diff)
downloadgit-0624c63ce6a488d3d8bccc4b1e79cc2093e2c4a4.tar.gz
config: match both symlink & realpath versions in IncludeIf.gitdir:*ab/conditional-config-with-symlinks
Change the conditional inclusion mechanism to support e.g. gitdir:~/git_tree/repo where ~/git_tree is a symlink to /mnt/stuff/repo. This worked in the initial version of this facility[1], but regressed later in the series while solving a related bug[2]. Now gitdir: will match against the symlinked path (e.g. gitdir:~/git_tree/repo) in addition to the current /mnt/stuff/repo path. Since this is already in a release version note in the documentation that this behavior changed, so users who expect their configuration to work on both v2.13.0 and some future version of git with this fix aren't utterly confused. 1. commit 3efd0bedc6 ("config: add conditional include", 2017-03-01) 2. commit 86f9515708 ("config: resolve symlinks in conditional include's patterns", 2017-04-05) Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r--config.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/config.c b/config.c
index b4a3205da3..f978428695 100644
--- a/config.c
+++ b/config.c
@@ -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);