Skip to content

Commit 331fe94

Browse files
committed
Merge branch 'mm/add-p-split-error'
When "add--interactive" splits a hunk into two overlapping hunks and then let the user choose only one, it sometimes feeds an incorrect patch text to "git apply". Add tests to demonstrate this. I have a slight suspicion that this may be $gmane/87202 coming back and biting us (I seem to have said "let's run with this and see what happens" back then). * mm/add-p-split-error: stash -p: demonstrate failure of split with mixed y/n t3904-stash-patch: factor PERL prereq at the top of the file t3904-stash-patch: fix test description add -p: demonstrate failure when running 'edit' after a split t3701-add-interactive: simplify code
2 parents 7e98292 + 7e9e048 commit 331fe94

File tree

2 files changed

+59
-11
lines changed

2 files changed

+59
-11
lines changed

t/t3701-add-interactive.sh

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,34 @@ test_expect_success 'split hunk "add -p (edit)"' '
326326
# 2. Correct version applies the (not)edited version, and asks
327327
# about the next hunk, against which we say q and program
328328
# exits.
329-
for a in s e q n q q
330-
do
331-
echo $a
332-
done |
329+
printf "%s\n" s e q n q q |
333330
EDITOR=: git add -p &&
334331
git diff >actual &&
335332
! grep "^+15" actual
336333
'
337334

335+
test_expect_failure 'split hunk "add -p (no, yes, edit)"' '
336+
cat >test <<-\EOF &&
337+
5
338+
10
339+
20
340+
21
341+
30
342+
31
343+
40
344+
50
345+
60
346+
EOF
347+
git reset &&
348+
# test sequence is s(plit), n(o), y(es), e(dit)
349+
# q n q q is there to make sure we exit at the end.
350+
printf "%s\n" s n y e q n q q |
351+
EDITOR=: git add -p 2>error &&
352+
test_must_be_empty error &&
353+
git diff >actual &&
354+
! grep "^+31" actual
355+
'
356+
338357
test_expect_success 'patch mode ignores unmerged entries' '
339358
git reset --hard &&
340359
test_commit conflict &&

t/t3904-stash-patch.sh

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
#!/bin/sh
22

3-
test_description='git checkout --patch'
3+
test_description='stash -p'
44
. ./lib-patch-mode.sh
55

6-
test_expect_success PERL 'setup' '
6+
if ! test_have_prereq PERL
7+
then
8+
skip_all='skipping stash -p tests, perl not available'
9+
test_done
10+
fi
11+
12+
test_expect_success 'setup' '
713
mkdir dir &&
814
echo parent > dir/foo &&
915
echo dummy > bar &&
@@ -20,7 +26,7 @@ test_expect_success PERL 'setup' '
2026

2127
# note: order of files with unstaged changes: HEAD bar dir/foo
2228

23-
test_expect_success PERL 'saying "n" does nothing' '
29+
test_expect_success 'saying "n" does nothing' '
2430
set_state HEAD HEADfile_work HEADfile_index &&
2531
set_state dir/foo work index &&
2632
(echo n; echo n; echo n) | test_must_fail git stash save -p &&
@@ -29,7 +35,7 @@ test_expect_success PERL 'saying "n" does nothing' '
2935
verify_state dir/foo work index
3036
'
3137

32-
test_expect_success PERL 'git stash -p' '
38+
test_expect_success 'git stash -p' '
3339
(echo y; echo n; echo y) | git stash save -p &&
3440
verify_state HEAD committed HEADfile_index &&
3541
verify_saved_state bar &&
@@ -41,7 +47,7 @@ test_expect_success PERL 'git stash -p' '
4147
verify_state dir/foo work head
4248
'
4349

44-
test_expect_success PERL 'git stash -p --no-keep-index' '
50+
test_expect_success 'git stash -p --no-keep-index' '
4551
set_state HEAD HEADfile_work HEADfile_index &&
4652
set_state bar bar_work bar_index &&
4753
set_state dir/foo work index &&
@@ -56,7 +62,7 @@ test_expect_success PERL 'git stash -p --no-keep-index' '
5662
verify_state dir/foo work index
5763
'
5864

59-
test_expect_success PERL 'git stash --no-keep-index -p' '
65+
test_expect_success 'git stash --no-keep-index -p' '
6066
set_state HEAD HEADfile_work HEADfile_index &&
6167
set_state bar bar_work bar_index &&
6268
set_state dir/foo work index &&
@@ -71,8 +77,31 @@ test_expect_success PERL 'git stash --no-keep-index -p' '
7177
verify_state dir/foo work index
7278
'
7379

74-
test_expect_success PERL 'none of this moved HEAD' '
80+
test_expect_success 'none of this moved HEAD' '
7581
verify_saved_head
7682
'
7783

84+
test_expect_failure 'stash -p with split hunk' '
85+
git reset --hard &&
86+
cat >test <<-\EOF &&
87+
aaa
88+
bbb
89+
ccc
90+
EOF
91+
git add test &&
92+
git commit -m "initial" &&
93+
cat >test <<-\EOF &&
94+
aaa
95+
added line 1
96+
bbb
97+
added line 2
98+
ccc
99+
EOF
100+
printf "%s\n" s n y q |
101+
test_might_fail git stash -p 2>error &&
102+
! test_must_be_empty error &&
103+
grep "added line 1" test &&
104+
! grep "added line 2" test
105+
'
106+
78107
test_done

0 commit comments

Comments
 (0)