checkout -p: handle new files correctly
commit2c8bd8471a6abc68064dafc743362547fc730f77
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 27 May 2020 21:09:06 +0000 (27 21:09 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 27 May 2020 21:50:20 +0000 (27 14:50 -0700)
tree31442c60ddd564c9cffbfb33810ad79acaf0bfc1
parentb2627cc3d4be2f8086711097f99d79a32c6a703a
checkout -p: handle new files correctly

The original patch selection code was written for `git add -p`, and the
fundamental unit on which it works is a hunk.

We hacked around that to handle deletions back in 24ab81ae4d
(add-interactive: handle deletion of empty files, 2009-10-27). But `git
add -p` would never see a new file, since we only consider the set of
tracked files in the index.

However, since the same machinery was used for `git checkout -p` &
friends, we can see new files.

Handle this case specifically, adding a new prompt for it that is
modeled after the `deleted file` case.

This also fixes the problem where added _empty_ files could not be
staged via `git checkout -p`.

Reported-by: Merlin Büge <toni@bluenox07.de>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
add-patch.c
git-add--interactive.perl
t/t3701-add-interactive.sh