Subject: git write-tree segfault with core.untrackedCache true and nonexistent index

From: Joey Hess <[email-masked]>
Date: Fri, 22 Jul 2022 13:24:14 -0400

joey@darkstar:/tmp>git init emptyrepo
	Initialized empty Git repository in /tmp/emptyrepo/.git/
	joey@darkstar:/tmp>cd emptyrepo/
	joey@darkstar:/tmp/emptyrepo>git config core.untrackedCache true
	joey@darkstar:/tmp/emptyrepo>git write-tree
	Segmentation fault

I'm seeing this with git 2.37, 2.37.1, and HEAD. 
2.36.1 does not have the problem. 

Note that the index file does not exist prior to git write-tree in the above
test case. When the index does exist, it doesn't segfault. Before, it would
just generate the empty tree when the index did not exist.

Bisecting, e6a653554bb49c26d105f3b478cbdbb1c0648f65 is the first bad commit
commit e6a653554bb49c26d105f3b478cbdbb1c0648f65
Author: Tao Klerks <[email-masked]>
Date:   Thu Mar 31 16:02:15 2022 +0000

    untracked-cache: support '--untracked-files=all' if configured

-- 
see shy jo