git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] fix apply --intent-to-add
@ 2025-06-28 22:52 Raymond E. Pasco
  2025-06-28 22:52 ` [PATCH 1/5] apply: error on --intent-to-add outside gitdir Raymond E. Pasco
                   ` (6 more replies)
  0 siblings, 7 replies; 26+ messages in thread
From: Raymond E. Pasco @ 2025-06-28 22:52 UTC (permalink / raw)
  To: git
  Cc: Raymond E. Pasco, aclopte, gitster, jason11choca,
	kristofferhaugsbakk, rhodges

The --intent-to-add (-N) flag to apply has not worked properly since its
introduction in Git 2.19; in particular, it creates an empty index
except for any new files in the patch, making it largely useless except
on blank repositories.

This patch series fixes it to work as expected and updates the tests
and documentation for this flag.

Earlier discussion of this issue can be found in the threads associated
with message ids <20211106114202.3486969-1-aclopte@gmail.com> and
<20250511003955.242889-1-ray@ameretat.dev>.

Raymond E. Pasco (5):
  apply: error on --intent-to-add outside gitdir
  apply: read in the index in --intent-to-add mode
  apply: only write intents to add for new files
  t4140: test apply --intent-to-add interactions
  apply docs: clarify wording for --intent-to-add

 Documentation/git-apply.adoc |  8 ++++----
 apply.c                      | 12 ++++++++----
 t/t4140-apply-ita.sh         | 31 ++++++++++++++++++++++++++++++-
 3 files changed, 42 insertions(+), 9 deletions(-)

-- 
2.50.0.195.g74e6fc65d0


^ permalink raw reply	[flat|nested] 26+ messages in thread
* Re: [PATCH v3] apply: --intent-to-add should imply --index
@ 2025-05-03  3:51 Raymond E. Pasco
  2025-05-11  0:36 ` [PATCH 0/5] apply: fix apply --intent-to-add Raymond E. Pasco
  0 siblings, 1 reply; 26+ messages in thread
From: Raymond E. Pasco @ 2025-05-03  3:51 UTC (permalink / raw)
  To: Ryan Hodges
  Cc: Junio C Hamano, Kristoffer Haugsbakk, Jason Cho,
	git@vger.kernel.org, aclopte@gmail.com, Ryan Hodges

Intents to add are a tricky part of the system; I fixed them up
some time ago for `add -p` which uses apply.c machinery, but not for
`apply -N`, which seems to have never worked since its introduction
in Git 2.19.

To recap how this all works, apply has three modes: with no flag, it
applies a diff to the physical files in the worktree; with --index it
applies a diff to both the physical files in the worktree and to the
index, and with --cached it applies to the index but *not* the physical
files in the worktree.

--intent-to-add / -N is intended to apply only to the first of these
modes; this makes sense, because an intent to add is meant to behave
like a diff not added to the index. However, the intent to add lives in
the index; Git just behaves as though it were a worktree change not in
the index.

The behavior `apply -N` actually exhibits is that it clobbers the index
with a new index containing *only* the contents of the diff, nothing
else; my guess is that it was only tested against repositories with
entirely empty trees. If the tree is not empty, then of course an index
with only the intent to add and nothing else shows up as every file in
the tree being deleted.

The patch discussed here (the headers for the thread seem broken,
but the message id is <20211106114202.3486969-1-aclopte@gmail.com>) does
seem like a mostly complete fix for the issue. However, the message is
entirely wrong and confused about how any of this works, which is likely
why the patch fell through the cracks. (Of course --intent-to-add can't
imply --index, they are mutually exclusive options.)

However, the code appears entirely correct. The combination of --cached
with -N doesn't work, despite the message claiming it does, but it can't
possibly work because it includes the file in the index, so it can't
include it as an intent to add in the index. So this just merits a note
that --intent-to-add is mutually exclusive with both --index and
--cached.

If the original author (Johannes Altmanninger) isn't around or doesn't
want to, I can clean this patch up for resubmission.

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2025-07-07 17:51 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 2/5] apply: read in the index in --intent-to-add mode Raymond E. Pasco
2025-06-30 18:47   ` 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 1/5] apply: error on --intent-to-add outside gitdir Raymond E. Pasco

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).