From: "Raymond E. Pasco" <ray@ameretat•dev>
To: git@vger•kernel.org
Cc: "Raymond E. Pasco" <ray@ameretat•dev>,
Ryan Hodges <rhodges@cisco•com>,
Johannes Altmanninger <aclopte@gmail•com>
Subject: [PATCH 2/5] apply: read in the index in --intent-to-add mode
Date: Sat, 28 Jun 2025 18:52:04 -0400 [thread overview]
Message-ID: <20250628225819.1294068-4-ray@ameretat.dev> (raw)
In-Reply-To: <20250628225819.1294068-2-ray@ameretat.dev>
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.
If we merely gate read_apply_cache() behind update_index, then it will
not be read when state->apply is false, even if it must be checked.
Therefore, we instead read the index if it will be either checked or
updated, because reading the index is a prerequisite to either.
Reported-by: Ryan Hodges <rhodges@cisco•com>
Original-patch-by: Johannes Altmanninger <aclopte@gmail•com>
Signed-off-by: Raymond E. Pasco <ray@ameretat•dev>
---
apply.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/apply.c b/apply.c
index e7856ae6b3..1757d34618 100644
--- a/apply.c
+++ b/apply.c
@@ -4837,7 +4837,7 @@ static int apply_patch(struct apply_state *state,
LOCK_DIE_ON_ERROR);
}
- if (state->check_index && read_apply_cache(state) < 0) {
+ if ((state->check_index || state->update_index) && read_apply_cache(state) < 0) {
error(_("unable to read index file"));
res = -128;
goto end;
--
2.50.0.195.g74e6fc65d0
next prev parent reply other threads:[~2025-06-28 22:59 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-28 22:52 [PATCH 0/5] fix apply --intent-to-add Raymond E. Pasco
2025-06-28 22:52 ` [PATCH 1/5] apply: error on --intent-to-add outside gitdir Raymond E. Pasco
2025-06-30 18:34 ` Junio C Hamano
2025-07-01 5:26 ` Raymond E. Pasco
2025-06-28 22:52 ` Raymond E. Pasco [this message]
2025-06-30 18:47 ` [PATCH 2/5] apply: read in the index in --intent-to-add mode Junio C Hamano
2025-07-01 5:32 ` Raymond E. Pasco
2025-06-28 22:52 ` [PATCH 3/5] apply: only write intents to add for new files Raymond E. Pasco
2025-06-30 18:53 ` Junio C Hamano
2025-07-01 5:44 ` Raymond E. Pasco
2025-06-28 22:52 ` [PATCH 4/5] t4140: test apply --intent-to-add interactions Raymond E. Pasco
2025-06-28 22:52 ` [PATCH 5/5] apply docs: clarify wording for --intent-to-add Raymond E. Pasco
2025-06-29 3:10 ` [PATCH 0/5] fix apply --intent-to-add Lidong Yan
2025-06-30 0:56 ` Raymond E. Pasco
2025-07-02 21:26 ` [PATCH v2 0/4] " Raymond E. Pasco
2025-07-02 21:26 ` [PATCH v2 1/4] apply: read in the index in --intent-to-add mode Raymond E. Pasco
2025-07-02 21:26 ` [PATCH v2 2/4] apply: only write intents to add for new files Raymond E. Pasco
2025-07-02 21:26 ` [PATCH v2 3/4] t4140: test apply --intent-to-add interactions Raymond E. Pasco
2025-07-02 21:26 ` [PATCH v2 4/4] apply docs: clarify wording for --intent-to-add Raymond E. Pasco
2025-07-07 12:12 ` [PATCH v3 0/4] fix apply --intent-to-add Raymond E. Pasco
2025-07-07 12:12 ` [PATCH v3 1/4] apply: read in the index in --intent-to-add mode Raymond E. Pasco
2025-07-07 12:12 ` [PATCH v3 2/4] apply: only write intents to add for new files Raymond E. Pasco
2025-07-07 12:12 ` [PATCH v3 3/4] t4140: test apply --intent-to-add interactions Raymond E. Pasco
2025-07-07 12:12 ` [PATCH v3 4/4] apply docs: clarify wording for --intent-to-add Raymond E. Pasco
2025-07-07 17:51 ` [PATCH v3 0/4] fix apply --intent-to-add Junio C Hamano
-- strict thread matches above, loose matches on Subject: below --
2025-05-03 3:51 [PATCH v3] apply: --intent-to-add should imply --index Raymond E. Pasco
2025-05-11 0:36 ` [PATCH 0/5] apply: fix apply --intent-to-add Raymond E. Pasco
2025-05-11 0:36 ` [PATCH 2/5] apply: read in the index in --intent-to-add mode Raymond E. Pasco
2025-05-12 2:13 ` Raymond E. Pasco
2025-05-13 17:52 ` Jason Cho
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250628225819.1294068-4-ray@ameretat.dev \
--to=ray@ameretat$(echo .)dev \
--cc=aclopte@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=rhodges@cisco$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox