diff --git a/dir.c b/dir.c index 130fa98766..465c22ff68 100644 --- a/dir.c +++ b/dir.c @@ -1369,6 +1369,12 @@ int match_pathname(const char *pathname, int pathlen, if (patternlen == prefix && namelen == prefix) return 1; + /* + * Retain one character of the prefix to + * pass to fnmatch, which lets it distinguish + * the start of a directory component correctly. + */ + prefix--; pattern += prefix; patternlen -= prefix; name += prefix; diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh index 273d71411f..db8bde280e 100755 --- a/t/t0008-ignores.sh +++ b/t/t0008-ignores.sh @@ -847,6 +847,17 @@ test_expect_success 'directories and ** matches' ' test_cmp expect actual ' +test_expect_success '** not confused by matching leading prefix' ' + cat >.gitignore <<-\EOF && + foo**/bar + EOF + git check-ignore foobar foo/bar >actual && + cat >expect <<-\EOF && + foo/bar + EOF + test_cmp expect actual +' + ############################################################################ # # test whitespace handling