From: Phillip Wood Date: Sat, 08 Aug 2020 15:48:03 GMT Subject: Re: [PATCH v5 2/3] apply: make i-t-a entries never match worktree Message-ID: In-Reply-To: Hi Raymond On 08/08/2020 15:07, Raymond E. Pasco wrote: > On Sat Aug 8, 2020 at 9:46 AM EDT, Phillip Wood wrote: >>> By definition, an intent-to-add index entry can never match the >>> worktree, because worktrees have no concept of intent-to-add entries. >>> Therefore, "apply --index" should always fail on intent-to-add paths. >> >> I'm not sure I understand the logic for this. If I run 'git add -N >> ' and does not exist in the worktree what's the reason to >> stop a patch that creates from applying? > > "apply --index" requires the index and worktree to match, and applies > the same path to both to get the same result in both. I brainstormed the > logic a few emails upthread, and that's what's consistent with > everything else. I had a quick scan of the earlier email and found > The index and the filesystem are both able to represent "no file" > and "a file exists" states, but the index has an additional > state (i-t-a) with no direct representation in the > worktree. By (correctly) emitting "new file" patches when > comparing a file to an i-t-a index entry, we are setting down the > rule that a "new file" patch is not merely the diff between "no > file" and "a file exists", but also the diff between i-t-a and "a > file exists". > > Similarly, "deleted file" patches are the diff between "a file > exists" and "no file exists", but they are also the diff between > i-t-a and "no file exists" - if you add -N a file and then delete > it from the worktree, "deleted file" is what git diff (correctly) > shows. As a consequence of these rules, "new file" and "deleted > file" diffs are now the only diffs that validly apply to an i-t-a > entry. So apply needs to handle them (in "--cached" mode, > anyway). If I've understood correctly an i-t-a entry in the index combined with nothing in the worktree is a deletion and that is why we don't want --index to succeed when applying a creation patch? If so an expanded explanation in the commit message to this patch would help rather than just saying 'by definition'. I'm still a bit confused as we don't count it as a deletion when using --cached or applying to the worktree. >> I was relieved to see from the next patch that this does not affect >> --cached even though the documentation says it implies --index. It might >> be worth mentioning that in the commit message. Also it would be easier >> to follow if the tests were in the same patch (this is what we usually >> do). > > --cached doesn't really imply --index - the docs are wrong and should be > changed. If anything, --index is closer to implying --cached - but > really, [no flags], --cached, and --index are three different modes with > different behavior. (Just removing "this implies --index" would be > sufficient to make the docs correct.) > >> How this does it affect --check? `git add -p` uses --check to verify >> that hunks that the user has edited still apply. It does not let the >> user edit the hunk for a newly added file at the moment but that is >> something I'm thinking of adding. > > --check goes through all the same code, The same code as --cached or --index? (I assume it's the former but wanted to be sure) Thanks Phillip >it just doesn't actually touch > anything in the index or worktree. Splittable/editable new file patches > are a logical related feature, IMO. (This is just to squash an error > that shouldn't happen.) >