3 test_description
='stash -p'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_expect_success
'setup' '
10 echo parent > dir/foo &&
12 echo committed > HEAD &&
13 git add bar dir/foo HEAD &&
14 git commit -m initial &&
16 test_commit second dir/foo head &&
17 echo index > dir/foo &&
19 set_and_save_state bar bar_work bar_index &&
23 # note: order of files with unstaged changes: HEAD bar dir/foo
25 test_expect_success
'saying "n" does nothing' '
26 set_state HEAD HEADfile_work HEADfile_index &&
27 set_state dir/foo work index &&
28 test_write_lines n n n | test_must_fail git stash save -p &&
29 verify_state HEAD HEADfile_work HEADfile_index &&
30 verify_saved_state bar &&
31 verify_state dir/foo work index
34 test_expect_success
'git stash -p' '
35 test_write_lines y n y | git stash save -p &&
36 verify_state HEAD committed HEADfile_index &&
37 verify_saved_state bar &&
38 verify_state dir/foo head index &&
41 verify_state HEAD HEADfile_work committed &&
42 verify_state bar dummy dummy &&
43 verify_state dir/foo work head
46 test_expect_success
'git stash -p --no-keep-index' '
47 set_state HEAD HEADfile_work HEADfile_index &&
48 set_state bar bar_work bar_index &&
49 set_state dir/foo work index &&
50 test_write_lines y n y | git stash save -p --no-keep-index &&
51 verify_state HEAD committed committed &&
52 verify_state bar bar_work dummy &&
53 verify_state dir/foo head head &&
55 git stash apply --index &&
56 verify_state HEAD HEADfile_work HEADfile_index &&
57 verify_state bar dummy bar_index &&
58 verify_state dir/foo work index
61 test_expect_success
'git stash --no-keep-index -p' '
62 set_state HEAD HEADfile_work HEADfile_index &&
63 set_state bar bar_work bar_index &&
64 set_state dir/foo work index &&
65 test_write_lines y n y | git stash save --no-keep-index -p &&
66 verify_state HEAD committed committed &&
67 verify_state dir/foo head head &&
68 verify_state bar bar_work dummy &&
70 git stash apply --index &&
71 verify_state HEAD HEADfile_work HEADfile_index &&
72 verify_state bar dummy bar_index &&
73 verify_state dir/foo work index
76 test_expect_success
'stash -p --no-keep-index -- <pathspec> does not unstage other files' '
77 set_state HEAD HEADfile_work HEADfile_index &&
78 set_state dir/foo work index &&
79 echo y | git stash push -p --no-keep-index -- HEAD &&
80 verify_state HEAD committed committed &&
81 verify_state dir/foo work index
84 test_expect_success
'none of this moved HEAD' '
88 test_expect_success
'stash -p with split hunk' '
96 git commit -m "initial" &&
104 printf "%s\n" s n y q |
105 git stash -p 2>error &&
106 test_must_be_empty error &&
107 grep "added line 1" test &&
108 ! grep "added line 2" test