config: correct '**' matching in includeIf patterns

The current wildmatch() call for includeIf's gitdir pattern does not pass the WM_PATHNAME flag. Without this flag, '*' is treated _almost_ the same as '**' (because '*' also matches slashes) with one exception: '/**/' can match a single slash. The pattern 'foo/**/bar' matches 'foo/bar'. But '/*/', which is essentially what wildmatch engine sees without WM_PATHNAME, has to match two slashes (and '*' matches nothing). Which means 'foo/*/bar' cannot match 'foo/bar'. It can only match 'foo//bar'. The result of this is the current wildmatch() call works most of the time until the user depends on '/**/' matching no path component. And also '*' matches slashes while it should not, but people probably haven't noticed this yet. The fix is straightforward. Reported-by: Jason Karns <jason.karns@gmail.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Mar 26, 2019 at 16:41 UTC 19e7fdaa582598fb915e0a421a14b559c06587fd
2 files changed +14 -1
config.c
+1 -1
@@ -242,7 +242,7 @@ again:
242 }
243
244 ret = !wildmatch(pattern.buf + prefix, text.buf + prefix,
245 - icase ? WM_CASEFOLD : 0);
245 + WM_PATHNAME | (icase ? WM_CASEFOLD : 0));
246
247 if (!ret && !already_tried_absolute) {
248 /*
t/t1305-config-include.sh
+13
@@ -229,6 +229,19 @@ test_expect_success 'conditional include, early config reading' '
229 )
230 '
231
232 +test_expect_success 'conditional include with /**/' '
233 + REPO=foo/bar/repo &&
234 + git init $REPO &&
235 + cat >>$REPO/.git/config <<-\EOF &&
236 + [includeIf "gitdir:**/foo/**/bar/**"]
237 + path=bar7
238 + EOF
239 + echo "[test]seven=7" >$REPO/.git/bar7 &&
240 + echo 7 >expect &&
241 + git -C $REPO config test.seven >actual &&
242 + test_cmp expect actual
243 +'
244 +
245 test_expect_success SYMLINKS 'conditional include, set up symlinked $HOME' '
246 mkdir real-home &&
247 ln -s real-home home &&