Skip to content

Commit 4447d41

Browse files
Martin Ågrengitster
authored andcommitted
read-cache: make do_read_index() always set up istate->repo
If there is no index file, e.g., because the repository has just been created, we return zero early (unless `must_exist` makes us die instead.) This early return means we do not set up `istate->repo`. With `core.untrackedCache=true`, the recent e6a6535 ("untracked-cache: support '--untracked-files=all' if configured", 2022-03-31) will eventually pass down `istate->repo` as a null pointer to `repo_config_get_string()`, causing a segmentation fault. If we do hit this early return, set up `istate->repo` similar to when we actually read the index. Reported-by: Joey Hess <[email protected]> Signed-off-by: Martin Ågren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e6a6535 commit 4447d41

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

read-cache.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2268,8 +2268,11 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
22682268
istate->timestamp.nsec = 0;
22692269
fd = open(path, O_RDONLY);
22702270
if (fd < 0) {
2271-
if (!must_exist && errno == ENOENT)
2271+
if (!must_exist && errno == ENOENT) {
2272+
if (!istate->repo)
2273+
istate->repo = the_repository;
22722274
return 0;
2275+
}
22732276
die_errno(_("%s: index file open failed"), path);
22742277
}
22752278

t/t7063-status-untracked-cache.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,4 +985,9 @@ test_expect_success '"status" after file replacement should be clean with UC=fal
985985
status_is_clean
986986
'
987987

988+
test_expect_success 'empty repo (no index) and core.untrackedCache' '
989+
git init emptyrepo &&
990+
git -C emptyrepo -c core.untrackedCache=true write-tree
991+
'
992+
988993
test_done

0 commit comments

Comments
 (0)