From: "René Scharfe" <l.s.r@web.de>
To: git@vger.kernel.org
Cc: 81625@debbugs.gnu.org, "Lester Longley" <lester@ieee.org>,
"Sean Whitton" <spwhitton@spwhitton.name>,
"Elijah Newren" <newren@gmail.com>,
"Martin Ågren" <martin.agren@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>
Subject: [PATCH] dir: skip excluded directory with nested repo on prefix match
Date: Fri, 18 Sep 2026 13:04:06 +0200 [thread overview]
Message-ID: <be53c379-b0e1-4242-8504-e96c2c49d294@web.de> (raw)
In-Reply-To: <87ld94klhf.fsf@athena.silentflame.com>
95c11ecc73 (Fix error-prone fill_directory() API; make it only return
matches, 2020-04-01) optimized away pathspec matching too eagerly and
cada7308ad (dir: check pathspecs before returning `path_excluded`,
2020-07-20) fixed that for files and symlinks.
A corner case remained unaddressed: Ignored directories that contain a
nested repository. Make sure to run match_pathspec_with_flags() for it
if necessary.
Reported-by: Sean Whitton <spwhitton@spwhitton.name>
Reported-by: Lester Longley <lester@ieee.org>
Signed-off-by: René Scharfe <l.s.r@web.de>
---
dir.c | 25 ++++++++++++++++++-------
t/t7061-wtstatus-ignore.sh | 5 +++++
2 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/dir.c b/dir.c
index 95d8a1cce9..0557a59d5e 100644
--- a/dir.c
+++ b/dir.c
@@ -1930,6 +1930,16 @@ static enum exist_status directory_exists_in_index(struct index_state *istate,
return index_nonexistent;
}
+static int dir_match(struct index_state *istate,
+ const struct pathspec *pathspec,
+ const char *dirname, int len)
+{
+ return match_pathspec_with_flags(istate, pathspec, dirname, len,
+ 0 /* prefix */,
+ NULL /* seen */,
+ DO_MATCH_LEADING_PATHSPEC);
+}
+
/*
* When we find a directory when traversing the filesystem, we
* have three distinct cases:
@@ -1996,11 +2006,7 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
* for matching patterns.
*/
if (pathspec && !excluded) {
- matches_how = match_pathspec_with_flags(istate, pathspec,
- dirname, len,
- 0 /* prefix */,
- NULL /* seen */,
- DO_MATCH_LEADING_PATHSPEC);
+ matches_how = dir_match(istate, pathspec, dirname, len);
if (!matches_how)
return path_none;
}
@@ -2034,8 +2040,13 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
strbuf_release(&sb);
if (nested_repo) {
- if ((dir->flags & DIR_SKIP_NESTED_GIT) ||
- (matches_how == MATCHED_RECURSIVELY_LEADING_PATHSPEC))
+ if (dir->flags & DIR_SKIP_NESTED_GIT)
+ return path_none;
+ if (!matches_how)
+ matches_how = dir_match(istate, pathspec,
+ dirname, len);
+ if (!matches_how ||
+ matches_how == MATCHED_RECURSIVELY_LEADING_PATHSPEC)
return path_none;
return excluded ? path_excluded : path_untracked;
}
diff --git a/t/t7061-wtstatus-ignore.sh b/t/t7061-wtstatus-ignore.sh
index 14ddaba2f3..182933471f 100755
--- a/t/t7061-wtstatus-ignore.sh
+++ b/t/t7061-wtstatus-ignore.sh
@@ -340,4 +340,9 @@ test_expect_success 'status ignores submodule in excluded directory' '
test_cmp expected actual
'
+test_expect_success 'status omits excluded directory with submodule on prefix match' '
+ git status --porcelain --ignored -u tracke >actual &&
+ test_must_be_empty actual
+'
+
test_done
--
2.55.0
next prev parent reply other threads:[~2026-09-18 11:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 13:31 [BUG] 'git status --ignored' <pathspec> matches partial names Sean Whitton
2026-09-15 15:54 ` René Scharfe
2026-09-18 11:04 ` René Scharfe [this message]
2026-09-22 4:57 ` [PATCH] dir: skip excluded directory with nested repo on prefix match Junio C Hamano
2026-09-26 10:51 ` René Scharfe
2026-09-26 10:48 ` [PATCH v2] " René Scharfe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=be53c379-b0e1-4242-8504-e96c2c49d294@web.de \
--to=l.s.r@web.de \
--cc=81625@debbugs.gnu.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=lester@ieee.org \
--cc=martin.agren@gmail.com \
--cc=newren@gmail.com \
--cc=spwhitton@spwhitton.name \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox