Skip to content

Commit 19e7fda

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aeb582a commit 19e7fda

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static int include_by_gitdir(const struct config_options *opts,
242242
}
243243

244244
ret = !wildmatch(pattern.buf + prefix, text.buf + prefix,
245-
icase ? WM_CASEFOLD : 0);
245+
WM_PATHNAME | (icase ? WM_CASEFOLD : 0));
246246

247247
if (!ret && !already_tried_absolute) {
248248
/*

t/t1305-config-include.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,19 @@ test_expect_success 'conditional include, early config reading' '
229229
)
230230
'
231231

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+
232245
test_expect_success SYMLINKS 'conditional include, set up symlinked $HOME' '
233246
mkdir real-home &&
234247
ln -s real-home home &&

0 commit comments

Comments
 (0)