Skip to content

Commit 47e0380

Browse files
committed
Merge branch 'tk/empty-untracked-cache'
The untracked cache newly computed weren't written back to the on-disk index file when there is no other change to the index, which has been corrected. * tk/empty-untracked-cache: untracked-cache: write index when populating empty untracked cache t7519: populate untracked cache before test t7519: avoid file to index mtime race for untracked cache
2 parents 5b9c98b + 317956d commit 47e0380

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

dir.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2781,7 +2781,8 @@ void remove_untracked_cache(struct index_state *istate)
27812781

27822782
static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *dir,
27832783
int base_len,
2784-
const struct pathspec *pathspec)
2784+
const struct pathspec *pathspec,
2785+
struct index_state *istate)
27852786
{
27862787
struct untracked_cache_dir *root;
27872788
static int untracked_cache_disabled = -1;
@@ -2845,8 +2846,11 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
28452846
return NULL;
28462847
}
28472848

2848-
if (!dir->untracked->root)
2849+
if (!dir->untracked->root) {
2850+
/* Untracked cache existed but is not initialized; fix that */
28492851
FLEX_ALLOC_STR(dir->untracked->root, name, "");
2852+
istate->cache_changed |= UNTRACKED_CHANGED;
2853+
}
28502854

28512855
/* Validate $GIT_DIR/info/exclude and core.excludesfile */
28522856
root = dir->untracked->root;
@@ -2916,7 +2920,7 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
29162920
return dir->nr;
29172921
}
29182922

2919-
untracked = validate_untracked_cache(dir, len, pathspec);
2923+
untracked = validate_untracked_cache(dir, len, pathspec, istate);
29202924
if (!untracked)
29212925
/*
29222926
* make sure untracked cache code path is disabled,

t/t7519-status-fsmonitor.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,17 +324,24 @@ test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR'
324324
cd dot-git &&
325325
mkdir -p .git/hooks &&
326326
: >tracked &&
327+
test-tool chmtime =-60 tracked &&
327328
: >modified &&
329+
test-tool chmtime =-60 modified &&
328330
mkdir dir1 &&
329331
: >dir1/tracked &&
332+
test-tool chmtime =-60 dir1/tracked &&
330333
: >dir1/modified &&
334+
test-tool chmtime =-60 dir1/modified &&
331335
mkdir dir2 &&
332336
: >dir2/tracked &&
337+
test-tool chmtime =-60 dir2/tracked &&
333338
: >dir2/modified &&
339+
test-tool chmtime =-60 dir2/modified &&
334340
write_integration_script &&
335341
git config core.fsmonitor .git/hooks/fsmonitor-test &&
336342
git update-index --untracked-cache &&
337343
git update-index --fsmonitor &&
344+
git status &&
338345
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace-before" \
339346
git status &&
340347
test-tool dump-untracked-cache >../before

0 commit comments

Comments
 (0)