{"thread":{"id":"66893","subject":"[PATCH] dir: invalidate parents of stale cached directories","startedAt":"2026-11-20T05:33:03Z","lastAt":"2026-11-20T05:33:03Z","messageCount":1,"participants":["Maik Riechert via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"558907","messageId":"pull.2321.git.1795152783221.gitgitgadget@gmail.com","threadId":"66893","inReplyTo":null,"subject":"[PATCH] dir: invalidate parents of stale cached directories","fromName":"Maik Riechert via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-20T05:33:03Z","receivedAt":"2026-11-20T05:33:03Z","isPatch":true,"sender":{"key":"name:Maik Riechert","avatar":null},"body":"From: Maik Riechert <letmaik@outlook.com>\n\nAfter a failed fsmonitor query or a trivial response, \"git status\"\ncan report both an untracked directory and a directory below it,\nfor example \"?? three/\" and \"?? three/deep/\".\n\n1cf98cb4d9 (fsmonitor: check the untracked cache after a trivial\nresponse, 2026-11-09) added a stat check before writing the untracked\ncache alongside a new fsmonitor token after these responses.  The check\ninvalidates stale directories, but does not propagate the invalidation\nto their parents.\n\nIn normal mode, a parent's cached untracked list can contain \"three/\"\nfrom a check-only scan of the child.  Writing the invalid child clears\nits check_only flag.  The next cached walk then recurses into the child\nand reports \"three/deep/\", while the parent's list still reports\n\"three/\".\n\nInvalidate ancestors too when DIR_SHOW_OTHER_DIRECTORIES is set, as\ninvalidate_one_component() does.  Leave all-files mode unchanged and\nreuse the existing traversal without adding stat calls.\n\nAdd normal-mode regression tests for failed queries and trivial\nresponses.  Use fixed directory mtimes and force an index write without\nscanning untracked files.\n\nSigned-off-by: Maik Riechert <letmaik@outlook.com>\n---\n    dir: invalidate parents of stale cached directories\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2321%2Fletmaik%2Funtracked-cache-stale-dirs-parents-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2321/letmaik/untracked-cache-stale-dirs-parents-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2321\n\n dir.c                       |  6 +++++\n t/t7519-status-fsmonitor.sh | 46 +++++++++++++++++++++++++++++++++++++\n 2 files changed, 52 insertions(+)\n\ndiff --git a/dir.c b/dir.c\nindex 4f748800b1..633d259d7a 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -4094,6 +4094,12 @@ static int invalidate_stale_dirs(struct untracked_cache *uc,\n \t\tstrbuf_setlen(path, len);\n \t}\n \n+\tif (nr_invalidated && ucd->valid &&\n+\t    (uc->dir_flags & DIR_SHOW_OTHER_DIRECTORIES)) {\n+\t\tinvalidate_one_directory(uc, ucd);\n+\t\tnr_invalidated++;\n+\t}\n+\n \treturn nr_invalidated;\n }\n \ndiff --git a/t/t7519-status-fsmonitor.sh b/t/t7519-status-fsmonitor.sh\nindex 27c3194ae0..3877140b77 100755\n--- a/t/t7519-status-fsmonitor.sh\n+++ b/t/t7519-status-fsmonitor.sh\n@@ -388,6 +388,52 @@ test_expect_success UNTRACKED_CACHE 'untracked cache is checked after a trivial\n \t)\n '\n \n+for response in trivial failed\n+do\n+\ttest_expect_success UNTRACKED_CACHE,!MINGW \"stale check-only directories invalidate parents after a $response response\" '\n+\t\ttest_when_finished \"rm -rf stale-$response\" &&\n+\t\tgit init stale-$response &&\n+\t\t(\n+\t\t\tcd stale-$response &&\n+\t\t\tmkdir -p parent/three/deep &&\n+\t\t\t>parent/keep &&\n+\t\t\t>parent/three/deep/tracked &&\n+\t\t\tgit add parent &&\n+\t\t\tgit commit -m initial &&\n+\t\t\tgit rm --cached parent/three/deep/tracked &&\n+\t\t\tgit config core.untrackedCache true &&\n+\t\t\tgit config status.showUntrackedFiles normal &&\n+\t\t\tgit config core.fsmonitor \"$TEST_DIRECTORY/t7519/fsmonitor-none\" &&\n+\t\t\tgit config core.fsmonitorHookVersion 1 &&\n+\t\t\ttest-tool chmtime =1000000000 . parent parent/three parent/three/deep &&\n+\t\t\tcat >../expect <<-\\EOF &&\n+\t\t\tD  parent/three/deep/tracked\n+\t\t\t?? parent/three/\n+\t\t\tEOF\n+\t\t\tgit status --porcelain >../actual &&\n+\t\t\ttest_cmp ../expect ../actual &&\n+\n+\t\t\t# Change only the check-only directory after caching it.\n+\t\t\t# Write the index without scanning untracked files.\n+\t\t\ttest-tool chmtime +60 parent/three &&\n+\t\t\tif test \"$response\" = trivial\n+\t\t\tthen\n+\t\t\t\thook_version=1\n+\t\t\telse\n+\t\t\t\t# fsmonitor-all fails for version 2.\n+\t\t\t\thook_version=2\n+\t\t\tfi &&\n+\t\t\tgit -c core.fsmonitor=\"$TEST_DIRECTORY/t7519/fsmonitor-all\" \\\n+\t\t\t\t-c core.fsmonitorHookVersion=$hook_version \\\n+\t\t\t\tupdate-index --force-write-index &&\n+\t\t\tgit status --porcelain >../actual &&\n+\t\t\ttest_cmp ../expect ../actual &&\n+\t\t\tgit status --porcelain >../actual &&\n+\t\t\ttest_cmp ../expect ../actual\n+\t\t)\n+\t'\n+done\n+\n # test that splitting the index doesn't interfere\n test_expect_success 'splitting the index results in the same state' '\n \twrite_integration_script &&\n\nbase-commit: f7de81456940dd6f3274e461149bba12965de609\n-- \ngitgitgadget\n\n"}]}