Merge branch 'ja/doc-synopsis-markup'
[git/gitster.git] / t / t3904-stash-patch.sh
blobaa5019fd6c3d59cc4f3ad870607c7e6e531e628b
1 #!/bin/sh
3 test_description='stash -p'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./lib-patch-mode.sh
8 test_expect_success 'setup' '
9 mkdir dir &&
10 echo parent > dir/foo &&
11 echo dummy > bar &&
12 echo committed > HEAD &&
13 git add bar dir/foo HEAD &&
14 git commit -m initial &&
15 test_tick &&
16 test_commit second dir/foo head &&
17 echo index > dir/foo &&
18 git add dir/foo &&
19 set_and_save_state bar bar_work bar_index &&
20 save_head
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 &&
39 git reset --hard &&
40 git stash apply &&
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 &&
54 git reset --hard &&
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 &&
69 git reset --hard &&
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' '
85 verify_saved_head
88 test_expect_success 'stash -p with split hunk' '
89 git reset --hard &&
90 cat >test <<-\EOF &&
91 aaa
92 bbb
93 ccc
94 EOF
95 git add test &&
96 git commit -m "initial" &&
97 cat >test <<-\EOF &&
98 aaa
99 added line 1
101 added line 2
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
111 test_done