Skip to content

Commit 328b4a2

Browse files
committed
fsmonitor: demonstrate that it is not refreshed after discard_index()
This one is tricky. When `core.fsmonitor` is set, a `refresh_index()` will not perform a full scan of files that might be modified, but will query the fsmonitor and refresh only the ones that have been actually touched. Due to implementation details, the fsmonitor is queried in `refresh_cache_ent()`, but of course it only has to be queried once, so we set a flag when we did that. But when the index was discarded, we did not re-set that flag. So far, this is only covered by our test suite when running with GIT_TEST_FSMONITOR=$PWD/t7519/fsmonitor-all, and only due to the way the built-in stash interacts with the recursive merge machinery. Let's introduce a straight-forward regression test for this. We simply extend the "read & discard index" loop in `test-tool read-cache` to optionally refresh the index, report on a given file's status, and then modify that file. Due to the bug described above, only the first refresh will actually query the fsmonitor; subsequent loop iterations will not. This problem was reported by Ævar Arnfjörð Bjarmason. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 8104ec9 commit 328b4a2

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

t/helper/test-read-cache.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
11
#include "test-tool.h"
22
#include "cache.h"
3+
#include "config.h"
34

45
int cmd__read_cache(int argc, const char **argv)
56
{
6-
int i, cnt = 1;
7+
int i, cnt = 1, namelen;
8+
const char *name = NULL;
9+
10+
if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
11+
namelen = strlen(name);
12+
argc--;
13+
argv++;
14+
}
15+
716
if (argc == 2)
817
cnt = strtol(argv[1], NULL, 0);
918
setup_git_directory();
19+
git_config(git_default_config, NULL);
1020
for (i = 0; i < cnt; i++) {
1121
read_cache();
22+
if (name) {
23+
int pos;
24+
25+
refresh_index(&the_index, REFRESH_QUIET,
26+
NULL, NULL, NULL);
27+
pos = index_name_pos(&the_index, name, namelen);
28+
if (pos < 0)
29+
die("%s not in index", name);
30+
printf("%s is%s up to date\n", name,
31+
ce_uptodate(the_index.cache[pos]) ? "" : " not");
32+
write_file(name, "%d\n", i);
33+
}
1234
discard_cache();
1335
}
1436
return 0;

t/t7519-status-fsmonitor.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,12 @@ test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR'
346346
test_cmp before after
347347
'
348348

349+
test_expect_failure 'discard_index() also discards fsmonitor info' '
350+
test_config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-all" &&
351+
test_might_fail git update-index --refresh &&
352+
test-tool read-cache --print-and-refresh=tracked 2 >actual &&
353+
printf "tracked is%s up to date\n" "" " not" >expect &&
354+
test_cmp expect actual
355+
'
356+
349357
test_done

0 commit comments

Comments
 (0)