Re: [PATCH 2/5] apply: read in the index in --intent-to-add mode
From: Raymond E. Pasco <hidden>
Date: 2025-07-01 05:32:44
On 25/06/30 11:47AM, Junio C Hamano wrote:
"Raymond E. Pasco" [off-list ref] writes:quoted
There are three main modes of operation for apply: applying only to the worktree, applying to the worktree and index (--index), and applying only to the index (--cached). The --intent-to-add flag modifies the first of these modes, applying only to the worktree, in a way which touches the index, because intents to add are special index entries. However, it has not ever worked correctly in any but the most trivial (empty repository) cases, because the index was never read in (in apply, this is done in read_apply_cache()) before writing to it.As the inventor of "add -N", I think what "apply -N" does may be wrong (only judging from the above description; it's been a while since I really read the code in apply.c). It does not make any sense to write a new index that has only the ITA entries.
Yeah, that's the bug; it writes a new index with just ITA entries (iow, the index thinks every existing file has been deleted); the fix is to instead write ITA entries to the existing index, not make a new one. And the root cause is not having read the index, so it's starting from an empty tree.