]>
Commit | Line | Data |
---|---|---|
4f353658 TR |
1 | #!/bin/sh |
2 | ||
3 | test_description='git checkout --patch' | |
4 | ||
5 | . ./lib-patch-mode.sh | |
6 | ||
f2f7b6a5 | 7 | test_expect_success PERL 'setup' ' |
4f353658 TR |
8 | mkdir dir && |
9 | echo parent > dir/foo && | |
10 | echo dummy > bar && | |
11 | git add bar dir/foo && | |
12 | git commit -m initial && | |
13 | test_tick && | |
14 | test_commit second dir/foo head && | |
15 | set_and_save_state bar bar_work bar_index && | |
16 | save_head | |
17 | ' | |
18 | ||
19 | # note: bar sorts before dir/foo, so the first 'n' is always to skip 'bar' | |
20 | ||
f2f7b6a5 | 21 | test_expect_success PERL 'saying "n" does nothing' ' |
4f353658 | 22 | set_and_save_state dir/foo work head && |
0590ff26 | 23 | test_write_lines n n | git checkout -p && |
4f353658 TR |
24 | verify_saved_state bar && |
25 | verify_saved_state dir/foo | |
26 | ' | |
27 | ||
f2f7b6a5 | 28 | test_expect_success PERL 'git checkout -p' ' |
0590ff26 | 29 | test_write_lines n y | git checkout -p && |
4f353658 TR |
30 | verify_saved_state bar && |
31 | verify_state dir/foo head head | |
32 | ' | |
33 | ||
f2f7b6a5 | 34 | test_expect_success PERL 'git checkout -p with staged changes' ' |
a48fcd83 | 35 | set_state dir/foo work index && |
0590ff26 | 36 | test_write_lines n y | git checkout -p && |
4f353658 TR |
37 | verify_saved_state bar && |
38 | verify_state dir/foo index index | |
39 | ' | |
40 | ||
f2f7b6a5 | 41 | test_expect_success PERL 'git checkout -p HEAD with NO staged changes: abort' ' |
4f353658 | 42 | set_and_save_state dir/foo work head && |
0590ff26 | 43 | test_write_lines n y n | git checkout -p HEAD && |
4f353658 TR |
44 | verify_saved_state bar && |
45 | verify_saved_state dir/foo | |
46 | ' | |
47 | ||
f2f7b6a5 | 48 | test_expect_success PERL 'git checkout -p HEAD with NO staged changes: apply' ' |
0590ff26 | 49 | test_write_lines n y y | git checkout -p HEAD && |
4f353658 TR |
50 | verify_saved_state bar && |
51 | verify_state dir/foo head head | |
52 | ' | |
53 | ||
f2f7b6a5 | 54 | test_expect_success PERL 'git checkout -p HEAD with change already staged' ' |
a814615a | 55 | set_state dir/foo index index && |
4f353658 | 56 | # the third n is to get out in case it mistakenly does not apply |
0590ff26 | 57 | test_write_lines n y n | git checkout -p HEAD && |
4f353658 TR |
58 | verify_saved_state bar && |
59 | verify_state dir/foo head head | |
60 | ' | |
61 | ||
5602b500 DL |
62 | test_expect_success PERL 'git checkout -p HEAD^...' ' |
63 | # the third n is to get out in case it mistakenly does not apply | |
64 | test_write_lines n y n | git checkout -p HEAD^... && | |
65 | verify_saved_state bar && | |
66 | verify_state dir/foo parent parent | |
67 | ' | |
68 | ||
f2f7b6a5 | 69 | test_expect_success PERL 'git checkout -p HEAD^' ' |
4f353658 | 70 | # the third n is to get out in case it mistakenly does not apply |
0590ff26 | 71 | test_write_lines n y n | git checkout -p HEAD^ && |
4f353658 TR |
72 | verify_saved_state bar && |
73 | verify_state dir/foo parent parent | |
74 | ' | |
75 | ||
f2f7b6a5 | 76 | test_expect_success PERL 'git checkout -p handles deletion' ' |
e1327ed5 JK |
77 | set_state dir/foo work index && |
78 | rm dir/foo && | |
0590ff26 | 79 | test_write_lines n y | git checkout -p && |
e1327ed5 JK |
80 | verify_saved_state bar && |
81 | verify_state dir/foo index index | |
82 | ' | |
83 | ||
4f353658 TR |
84 | # The idea in the rest is that bar sorts first, so we always say 'y' |
85 | # first and if the path limiter fails it'll apply to bar instead of | |
86 | # dir/foo. There's always an extra 'n' to reject edits to dir/foo in | |
87 | # the failure case (and thus get out of the loop). | |
88 | ||
f2f7b6a5 | 89 | test_expect_success PERL 'path limiting works: dir' ' |
4f353658 | 90 | set_state dir/foo work head && |
0590ff26 | 91 | test_write_lines y n | git checkout -p dir && |
4f353658 TR |
92 | verify_saved_state bar && |
93 | verify_state dir/foo head head | |
94 | ' | |
95 | ||
f2f7b6a5 | 96 | test_expect_success PERL 'path limiting works: -- dir' ' |
4f353658 | 97 | set_state dir/foo work head && |
0590ff26 | 98 | test_write_lines y n | git checkout -p -- dir && |
4f353658 TR |
99 | verify_saved_state bar && |
100 | verify_state dir/foo head head | |
101 | ' | |
102 | ||
f2f7b6a5 | 103 | test_expect_success PERL 'path limiting works: HEAD^ -- dir' ' |
4f353658 | 104 | # the third n is to get out in case it mistakenly does not apply |
0590ff26 | 105 | test_write_lines y n n | git checkout -p HEAD^ -- dir && |
4f353658 TR |
106 | verify_saved_state bar && |
107 | verify_state dir/foo parent parent | |
108 | ' | |
109 | ||
f2f7b6a5 | 110 | test_expect_success PERL 'path limiting works: foo inside dir' ' |
4f353658 TR |
111 | set_state dir/foo work head && |
112 | # the third n is to get out in case it mistakenly does not apply | |
0590ff26 | 113 | test_write_lines y n n | (cd dir && git checkout -p foo) && |
4f353658 TR |
114 | verify_saved_state bar && |
115 | verify_state dir/foo head head | |
116 | ' | |
117 | ||
f2f7b6a5 | 118 | test_expect_success PERL 'none of this moved HEAD' ' |
4f353658 TR |
119 | verify_saved_head |
120 | ' | |
121 | ||
122 | test_done |