]>
Commit | Line | Data |
---|---|---|
dda1f2a5 TR |
1 | #!/bin/sh |
2 | ||
470b11e8 | 3 | test_description='stash -p' |
dda1f2a5 TR |
4 | . ./lib-patch-mode.sh |
5 | ||
798a5b03 | 6 | test_expect_success 'setup' ' |
dda1f2a5 TR |
7 | mkdir dir && |
8 | echo parent > dir/foo && | |
9 | echo dummy > bar && | |
44df2e29 JM |
10 | echo committed > HEAD && |
11 | git add bar dir/foo HEAD && | |
dda1f2a5 TR |
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 | |
19 | ' | |
20 | ||
44df2e29 | 21 | # note: order of files with unstaged changes: HEAD bar dir/foo |
dda1f2a5 | 22 | |
798a5b03 | 23 | test_expect_success 'saying "n" does nothing' ' |
44df2e29 | 24 | set_state HEAD HEADfile_work HEADfile_index && |
a48fcd83 | 25 | set_state dir/foo work index && |
0590ff26 | 26 | test_write_lines n n n | test_must_fail git stash save -p && |
44df2e29 JM |
27 | verify_state HEAD HEADfile_work HEADfile_index && |
28 | verify_saved_state bar && | |
29 | verify_state dir/foo work index | |
dda1f2a5 TR |
30 | ' |
31 | ||
798a5b03 | 32 | test_expect_success 'git stash -p' ' |
0590ff26 | 33 | test_write_lines y n y | git stash save -p && |
44df2e29 | 34 | verify_state HEAD committed HEADfile_index && |
dda1f2a5 | 35 | verify_saved_state bar && |
44df2e29 | 36 | verify_state dir/foo head index && |
dda1f2a5 TR |
37 | git reset --hard && |
38 | git stash apply && | |
44df2e29 JM |
39 | verify_state HEAD HEADfile_work committed && |
40 | verify_state bar dummy dummy && | |
41 | verify_state dir/foo work head | |
dda1f2a5 TR |
42 | ' |
43 | ||
798a5b03 | 44 | test_expect_success 'git stash -p --no-keep-index' ' |
44df2e29 | 45 | set_state HEAD HEADfile_work HEADfile_index && |
dda1f2a5 | 46 | set_state bar bar_work bar_index && |
44df2e29 | 47 | set_state dir/foo work index && |
0590ff26 | 48 | test_write_lines y n y | git stash save -p --no-keep-index && |
44df2e29 | 49 | verify_state HEAD committed committed && |
dda1f2a5 | 50 | verify_state bar bar_work dummy && |
44df2e29 | 51 | verify_state dir/foo head head && |
dda1f2a5 TR |
52 | git reset --hard && |
53 | git stash apply --index && | |
44df2e29 JM |
54 | verify_state HEAD HEADfile_work HEADfile_index && |
55 | verify_state bar dummy bar_index && | |
56 | verify_state dir/foo work index | |
dda1f2a5 TR |
57 | ' |
58 | ||
798a5b03 | 59 | test_expect_success 'git stash --no-keep-index -p' ' |
44df2e29 | 60 | set_state HEAD HEADfile_work HEADfile_index && |
21ec98a7 | 61 | set_state bar bar_work bar_index && |
44df2e29 | 62 | set_state dir/foo work index && |
0590ff26 | 63 | test_write_lines y n y | git stash save --no-keep-index -p && |
44df2e29 | 64 | verify_state HEAD committed committed && |
21ec98a7 DM |
65 | verify_state dir/foo head head && |
66 | verify_state bar bar_work dummy && | |
67 | git reset --hard && | |
68 | git stash apply --index && | |
44df2e29 JM |
69 | verify_state HEAD HEADfile_work HEADfile_index && |
70 | verify_state bar dummy bar_index && | |
71 | verify_state dir/foo work index | |
21ec98a7 DM |
72 | ' |
73 | ||
869fb8f7 TG |
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 | |
80 | ' | |
81 | ||
798a5b03 | 82 | test_expect_success 'none of this moved HEAD' ' |
dda1f2a5 TR |
83 | verify_saved_head |
84 | ' | |
85 | ||
77234361 | 86 | test_expect_success 'stash -p with split hunk' ' |
7e9e0486 MM |
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 | |
100 | ccc | |
101 | EOF | |
102 | printf "%s\n" s n y q | | |
121c0d41 JS |
103 | git stash -p 2>error && |
104 | test_must_be_empty error && | |
7e9e0486 MM |
105 | grep "added line 1" test && |
106 | ! grep "added line 2" test | |
107 | ' | |
108 | ||
dda1f2a5 | 109 | test_done |