summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorLibravatar Johannes Schindelin <johannes.schindelin@gmx.de>2020-05-27 21:09:06 +0000
committerLibravatar Junio C Hamano <gitster@pobox.com>2020-05-27 14:50:20 -0700
commit2c8bd8471a6abc68064dafc743362547fc730f77 (patch)
tree31442c60ddd564c9cffbfb33810ad79acaf0bfc1 /t
parentci: include the built-in `git add -i` in the `linux-gcc` job (diff)
downloadtgif-2c8bd8471a6abc68064dafc743362547fc730f77.tar.xz
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>
Diffstat (limited to 't')
-rwxr-xr-xt/t3701-add-interactive.sh19
1 files changed, 19 insertions, 0 deletions
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index ac43f835a5..7bc0c3fe6e 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -403,6 +403,25 @@ test_expect_success 'deleting an empty file' '
diff_cmp expected diff
'
+test_expect_success 'adding an empty file' '
+ git init added &&
+ (
+ cd added &&
+ test_commit initial &&
+ >empty &&
+ git add empty &&
+ test_tick &&
+ git commit -m empty &&
+ git tag added-file &&
+ git reset --hard HEAD^ &&
+ test_path_is_missing empty &&
+
+ echo y | git checkout -p added-file -- >actual &&
+ test_path_is_file empty &&
+ test_i18ngrep "Apply addition to index and worktree" actual
+ )
+'
+
test_expect_success 'split hunk setup' '
git reset --hard &&
test_write_lines 10 20 30 40 50 60 >test &&