mirror of
https://github.com/git/git.git
synced 2024-10-31 22:37:54 +01:00
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
This commit is contained in:
commit
331fe94fed
2 changed files with 59 additions and 11 deletions
|
@ -326,15 +326,34 @@ test_expect_success 'split hunk "add -p (edit)"' '
|
||||||
# 2. Correct version applies the (not)edited version, and asks
|
# 2. Correct version applies the (not)edited version, and asks
|
||||||
# about the next hunk, against which we say q and program
|
# about the next hunk, against which we say q and program
|
||||||
# exits.
|
# exits.
|
||||||
for a in s e q n q q
|
printf "%s\n" s e q n q q |
|
||||||
do
|
|
||||||
echo $a
|
|
||||||
done |
|
|
||||||
EDITOR=: git add -p &&
|
EDITOR=: git add -p &&
|
||||||
git diff >actual &&
|
git diff >actual &&
|
||||||
! grep "^+15" actual
|
! grep "^+15" actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_failure 'split hunk "add -p (no, yes, edit)"' '
|
||||||
|
cat >test <<-\EOF &&
|
||||||
|
5
|
||||||
|
10
|
||||||
|
20
|
||||||
|
21
|
||||||
|
30
|
||||||
|
31
|
||||||
|
40
|
||||||
|
50
|
||||||
|
60
|
||||||
|
EOF
|
||||||
|
git reset &&
|
||||||
|
# test sequence is s(plit), n(o), y(es), e(dit)
|
||||||
|
# q n q q is there to make sure we exit at the end.
|
||||||
|
printf "%s\n" s n y e q n q q |
|
||||||
|
EDITOR=: git add -p 2>error &&
|
||||||
|
test_must_be_empty error &&
|
||||||
|
git diff >actual &&
|
||||||
|
! grep "^+31" actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'patch mode ignores unmerged entries' '
|
test_expect_success 'patch mode ignores unmerged entries' '
|
||||||
git reset --hard &&
|
git reset --hard &&
|
||||||
test_commit conflict &&
|
test_commit conflict &&
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
test_description='git checkout --patch'
|
test_description='stash -p'
|
||||||
. ./lib-patch-mode.sh
|
. ./lib-patch-mode.sh
|
||||||
|
|
||||||
test_expect_success PERL 'setup' '
|
if ! test_have_prereq PERL
|
||||||
|
then
|
||||||
|
skip_all='skipping stash -p tests, perl not available'
|
||||||
|
test_done
|
||||||
|
fi
|
||||||
|
|
||||||
|
test_expect_success 'setup' '
|
||||||
mkdir dir &&
|
mkdir dir &&
|
||||||
echo parent > dir/foo &&
|
echo parent > dir/foo &&
|
||||||
echo dummy > bar &&
|
echo dummy > bar &&
|
||||||
|
@ -20,7 +26,7 @@ test_expect_success PERL 'setup' '
|
||||||
|
|
||||||
# note: order of files with unstaged changes: HEAD bar dir/foo
|
# note: order of files with unstaged changes: HEAD bar dir/foo
|
||||||
|
|
||||||
test_expect_success PERL 'saying "n" does nothing' '
|
test_expect_success 'saying "n" does nothing' '
|
||||||
set_state HEAD HEADfile_work HEADfile_index &&
|
set_state HEAD HEADfile_work HEADfile_index &&
|
||||||
set_state dir/foo work index &&
|
set_state dir/foo work index &&
|
||||||
(echo n; echo n; echo n) | test_must_fail git stash save -p &&
|
(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' '
|
||||||
verify_state dir/foo work index
|
verify_state dir/foo work index
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success PERL 'git stash -p' '
|
test_expect_success 'git stash -p' '
|
||||||
(echo y; echo n; echo y) | git stash save -p &&
|
(echo y; echo n; echo y) | git stash save -p &&
|
||||||
verify_state HEAD committed HEADfile_index &&
|
verify_state HEAD committed HEADfile_index &&
|
||||||
verify_saved_state bar &&
|
verify_saved_state bar &&
|
||||||
|
@ -41,7 +47,7 @@ test_expect_success PERL 'git stash -p' '
|
||||||
verify_state dir/foo work head
|
verify_state dir/foo work head
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success PERL 'git stash -p --no-keep-index' '
|
test_expect_success 'git stash -p --no-keep-index' '
|
||||||
set_state HEAD HEADfile_work HEADfile_index &&
|
set_state HEAD HEADfile_work HEADfile_index &&
|
||||||
set_state bar bar_work bar_index &&
|
set_state bar bar_work bar_index &&
|
||||||
set_state dir/foo work index &&
|
set_state dir/foo work index &&
|
||||||
|
@ -56,7 +62,7 @@ test_expect_success PERL 'git stash -p --no-keep-index' '
|
||||||
verify_state dir/foo work index
|
verify_state dir/foo work index
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success PERL 'git stash --no-keep-index -p' '
|
test_expect_success 'git stash --no-keep-index -p' '
|
||||||
set_state HEAD HEADfile_work HEADfile_index &&
|
set_state HEAD HEADfile_work HEADfile_index &&
|
||||||
set_state bar bar_work bar_index &&
|
set_state bar bar_work bar_index &&
|
||||||
set_state dir/foo work index &&
|
set_state dir/foo work index &&
|
||||||
|
@ -71,8 +77,31 @@ test_expect_success PERL 'git stash --no-keep-index -p' '
|
||||||
verify_state dir/foo work index
|
verify_state dir/foo work index
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success PERL 'none of this moved HEAD' '
|
test_expect_success 'none of this moved HEAD' '
|
||||||
verify_saved_head
|
verify_saved_head
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_failure 'stash -p with split hunk' '
|
||||||
|
git reset --hard &&
|
||||||
|
cat >test <<-\EOF &&
|
||||||
|
aaa
|
||||||
|
bbb
|
||||||
|
ccc
|
||||||
|
EOF
|
||||||
|
git add test &&
|
||||||
|
git commit -m "initial" &&
|
||||||
|
cat >test <<-\EOF &&
|
||||||
|
aaa
|
||||||
|
added line 1
|
||||||
|
bbb
|
||||||
|
added line 2
|
||||||
|
ccc
|
||||||
|
EOF
|
||||||
|
printf "%s\n" s n y q |
|
||||||
|
test_might_fail git stash -p 2>error &&
|
||||||
|
! test_must_be_empty error &&
|
||||||
|
grep "added line 1" test &&
|
||||||
|
! grep "added line 2" test
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in a new issue