From: Maik Riechert via GitGitGadget Date: Fri, 20 Nov 2026 05:33:03 GMT Subject: [PATCH] dir: invalidate parents of stale cached directories Message-ID: From: Maik Riechert After a failed fsmonitor query or a trivial response, "git status" can report both an untracked directory and a directory below it, for example "?? three/" and "?? three/deep/". 1cf98cb4d9 (fsmonitor: check the untracked cache after a trivial response, 2026-11-09) added a stat check before writing the untracked cache alongside a new fsmonitor token after these responses. The check invalidates stale directories, but does not propagate the invalidation to their parents. In normal mode, a parent's cached untracked list can contain "three/" from a check-only scan of the child. Writing the invalid child clears its check_only flag. The next cached walk then recurses into the child and reports "three/deep/", while the parent's list still reports "three/". Invalidate ancestors too when DIR_SHOW_OTHER_DIRECTORIES is set, as invalidate_one_component() does. Leave all-files mode unchanged and reuse the existing traversal without adding stat calls. Add normal-mode regression tests for failed queries and trivial responses. Use fixed directory mtimes and force an index write without scanning untracked files. Signed-off-by: Maik Riechert --- dir: invalidate parents of stale cached directories Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2321%2Fletmaik%2Funtracked-cache-stale-dirs-parents-v1 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2321/letmaik/untracked-cache-stale-dirs-parents-v1 Pull-Request: https://github.com/gitgitgadget/git/pull/2321 dir.c | 6 +++++ t/t7519-status-fsmonitor.sh | 46 +++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/dir.c b/dir.c index 4f748800b1..633d259d7a 100644 --- a/dir.c +++ b/dir.c @@ -4094,6 +4094,12 @@ static int invalidate_stale_dirs(struct untracked_cache *uc, strbuf_setlen(path, len); } + if (nr_invalidated && ucd->valid && + (uc->dir_flags & DIR_SHOW_OTHER_DIRECTORIES)) { + invalidate_one_directory(uc, ucd); + nr_invalidated++; + } + return nr_invalidated; } diff --git a/t/t7519-status-fsmonitor.sh b/t/t7519-status-fsmonitor.sh index 27c3194ae0..3877140b77 100755 --- a/t/t7519-status-fsmonitor.sh +++ b/t/t7519-status-fsmonitor.sh @@ -388,6 +388,52 @@ test_expect_success UNTRACKED_CACHE 'untracked cache is checked after a trivial ) ' +for response in trivial failed +do + test_expect_success UNTRACKED_CACHE,!MINGW "stale check-only directories invalidate parents after a $response response" ' + test_when_finished "rm -rf stale-$response" && + git init stale-$response && + ( + cd stale-$response && + mkdir -p parent/three/deep && + >parent/keep && + >parent/three/deep/tracked && + git add parent && + git commit -m initial && + git rm --cached parent/three/deep/tracked && + git config core.untrackedCache true && + git config status.showUntrackedFiles normal && + git config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-none" && + git config core.fsmonitorHookVersion 1 && + test-tool chmtime =1000000000 . parent parent/three parent/three/deep && + cat >../expect <<-\EOF && + D parent/three/deep/tracked + ?? parent/three/ + EOF + git status --porcelain >../actual && + test_cmp ../expect ../actual && + + # Change only the check-only directory after caching it. + # Write the index without scanning untracked files. + test-tool chmtime +60 parent/three && + if test "$response" = trivial + then + hook_version=1 + else + # fsmonitor-all fails for version 2. + hook_version=2 + fi && + git -c core.fsmonitor="$TEST_DIRECTORY/t7519/fsmonitor-all" \ + -c core.fsmonitorHookVersion=$hook_version \ + update-index --force-write-index && + git status --porcelain >../actual && + test_cmp ../expect ../actual && + git status --porcelain >../actual && + test_cmp ../expect ../actual + ) + ' +done + # test that splitting the index doesn't interfere test_expect_success 'splitting the index results in the same state' ' write_integration_script && base-commit: f7de81456940dd6f3274e461149bba12965de609 -- gitgitgadget