Subject: [PATCH 3/5] apply: only write intents to add for new files

From: "Raymond E. Pasco" <[email-masked]>
Date: Sat, 28 Jun 2025 18:52:05 -0400

In the "update only the worktree" mode, the index should not be touched
except to record intents to add when --intent-to-add is on. Because
having --intent-to-add on sets update_index, to indicate that we are
touching the index, we can't rely only on that flag to decide whether to
write an index entry.

Instead, we must test whether we are in a mode which updates the
index, or else are in worktree-only mode with --intent-to-add on and
the current file being an addition. We do not need to check
state->apply, because we only enter write_out_results() if state->apply
is already set.

Signed-off-by: Raymond E. Pasco <[email-masked]>
---
 apply.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/apply.c b/apply.c
index 1757d34618..5064a91fbf 100644
--- a/apply.c
+++ b/apply.c
@@ -4569,7 +4569,7 @@ static int create_file(struct apply_state *state, struct patch *patch)
 
 	if (patch->conflicted_threeway)
 		return add_conflicted_stages_file(state, patch);
-	else if (state->update_index)
+	else if (state->check_index || (state->ita_only && patch->is_new > 0))
 		return add_index_file(state, path, mode, buf, size);
 	return 0;
 }
-- 
2.50.0.195.g74e6fc65d0