Git 2.45
[git/gitster.git] / t / t3904-stash-patch.sh
blob368fc2a6cc16755e4e2c6e9a7fba0e88bba5a033
1 #!/bin/sh
3 test_description='stash -p'
4 . ./lib-patch-mode.sh
6 test_expect_success 'setup' '
7 mkdir dir &&
8 echo parent > dir/foo &&
9 echo dummy > bar &&
10 echo committed > HEAD &&
11 git add bar dir/foo HEAD &&
12 git commit -m initial &&
13 test_tick &&
14 test_commit second dir/foo head &&
15 echo index > dir/foo &&
16 git add dir/foo &&
17 set_and_save_state bar bar_work bar_index &&
18 save_head
21 # note: order of files with unstaged changes: HEAD bar dir/foo
23 test_expect_success 'saying "n" does nothing' '
24 set_state HEAD HEADfile_work HEADfile_index &&
25 set_state dir/foo work index &&
26 test_write_lines n n n | test_must_fail git stash save -p &&
27 verify_state HEAD HEADfile_work HEADfile_index &&
28 verify_saved_state bar &&
29 verify_state dir/foo work index
32 test_expect_success 'git stash -p' '
33 test_write_lines y n y | git stash save -p &&
34 verify_state HEAD committed HEADfile_index &&
35 verify_saved_state bar &&
36 verify_state dir/foo head index &&
37 git reset --hard &&
38 git stash apply &&
39 verify_state HEAD HEADfile_work committed &&
40 verify_state bar dummy dummy &&
41 verify_state dir/foo work head
44 test_expect_success 'git stash -p --no-keep-index' '
45 set_state HEAD HEADfile_work HEADfile_index &&
46 set_state bar bar_work bar_index &&
47 set_state dir/foo work index &&
48 test_write_lines y n y | git stash save -p --no-keep-index &&
49 verify_state HEAD committed committed &&
50 verify_state bar bar_work dummy &&
51 verify_state dir/foo head head &&
52 git reset --hard &&
53 git stash apply --index &&
54 verify_state HEAD HEADfile_work HEADfile_index &&
55 verify_state bar dummy bar_index &&
56 verify_state dir/foo work index
59 test_expect_success 'git stash --no-keep-index -p' '
60 set_state HEAD HEADfile_work HEADfile_index &&
61 set_state bar bar_work bar_index &&
62 set_state dir/foo work index &&
63 test_write_lines y n y | git stash save --no-keep-index -p &&
64 verify_state HEAD committed committed &&
65 verify_state dir/foo head head &&
66 verify_state bar bar_work dummy &&
67 git reset --hard &&
68 git stash apply --index &&
69 verify_state HEAD HEADfile_work HEADfile_index &&
70 verify_state bar dummy bar_index &&
71 verify_state dir/foo work index
74 test_expect_success 'stash -p --no-keep-index -- <pathspec> does not unstage other files' '
75 set_state HEAD HEADfile_work HEADfile_index &&
76 set_state dir/foo work index &&
77 echo y | git stash push -p --no-keep-index -- HEAD &&
78 verify_state HEAD committed committed &&
79 verify_state dir/foo work index
82 test_expect_success 'none of this moved HEAD' '
83 verify_saved_head
86 test_expect_success 'stash -p with split hunk' '
87 git reset --hard &&
88 cat >test <<-\EOF &&
89 aaa
90 bbb
91 ccc
92 EOF
93 git add test &&
94 git commit -m "initial" &&
95 cat >test <<-\EOF &&
96 aaa
97 added line 1
98 bbb
99 added line 2
102 printf "%s\n" s n y q |
103 git stash -p 2>error &&
104 test_must_be_empty error &&
105 grep "added line 1" test &&
106 ! grep "added line 2" test
109 test_done