]>
Commit | Line | Data |
---|---|---|
aa29ccf4 CC |
1 | #!/bin/sh |
2 | ||
3 | test_description='test cherry-picking many commits' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
6bc83cdd CC |
7 | check_head_differs_from() { |
8 | head=$(git rev-parse --verify HEAD) && | |
9 | arg=$(git rev-parse --verify "$1") && | |
10 | test "$head" != "$arg" | |
11 | } | |
12 | ||
13 | check_head_equals() { | |
14 | head=$(git rev-parse --verify HEAD) && | |
15 | arg=$(git rev-parse --verify "$1") && | |
16 | test "$head" = "$arg" | |
17 | } | |
18 | ||
aa29ccf4 CC |
19 | test_expect_success setup ' |
20 | echo first > file1 && | |
21 | git add file1 && | |
22 | test_tick && | |
23 | git commit -m "first" && | |
24 | git tag first && | |
25 | ||
26 | git checkout -b other && | |
27 | for val in second third fourth | |
28 | do | |
29 | echo $val >> file1 && | |
30 | git add file1 && | |
31 | test_tick && | |
32 | git commit -m "$val" && | |
33 | git tag $val | |
34 | done | |
35 | ' | |
36 | ||
37 | test_expect_success 'cherry-pick first..fourth works' ' | |
2593633f JN |
38 | git checkout -f master && |
39 | git reset --hard first && | |
40 | test_tick && | |
41 | git cherry-pick first..fourth && | |
42 | git diff --quiet other && | |
43 | git diff --quiet HEAD other && | |
44 | check_head_differs_from fourth | |
45 | ' | |
46 | ||
a73e22e9 | 47 | test_expect_success 'cherry-pick three one two works' ' |
d023c248 MZ |
48 | git checkout -f first && |
49 | test_commit one && | |
50 | test_commit two && | |
51 | test_commit three && | |
52 | git checkout -f master && | |
53 | git reset --hard first && | |
54 | git cherry-pick three one two && | |
55 | git diff --quiet three && | |
56 | git diff --quiet HEAD three && | |
57 | test "$(git log --reverse --format=%s first..)" = "three | |
58 | one | |
59 | two" | |
60 | ' | |
61 | ||
2593633f | 62 | test_expect_success 'output to keep user entertained during multi-pick' ' |
130ab8ab JN |
63 | cat <<-\EOF >expected && |
64 | [master OBJID] second | |
65 | Author: A U Thor <author@example.com> | |
7f814632 | 66 | 1 file changed, 1 insertion(+) |
130ab8ab JN |
67 | [master OBJID] third |
68 | Author: A U Thor <author@example.com> | |
7f814632 | 69 | 1 file changed, 1 insertion(+) |
130ab8ab JN |
70 | [master OBJID] fourth |
71 | Author: A U Thor <author@example.com> | |
7f814632 | 72 | 1 file changed, 1 insertion(+) |
7b53b92f CC |
73 | EOF |
74 | ||
75 | git checkout -f master && | |
76 | git reset --hard first && | |
77 | test_tick && | |
130ab8ab | 78 | git cherry-pick first..fourth >actual && |
2593633f JN |
79 | sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy && |
80 | test_line_count -ge 3 actual.fuzzy && | |
81 | test_i18ncmp expected actual.fuzzy | |
82 | ' | |
83 | ||
84 | test_expect_success 'cherry-pick --strategy resolve first..fourth works' ' | |
85 | git checkout -f master && | |
86 | git reset --hard first && | |
87 | test_tick && | |
88 | git cherry-pick --strategy resolve first..fourth && | |
7b53b92f CC |
89 | git diff --quiet other && |
90 | git diff --quiet HEAD other && | |
6bc83cdd | 91 | check_head_differs_from fourth |
7b53b92f CC |
92 | ' |
93 | ||
2593633f | 94 | test_expect_success 'output during multi-pick indicates merge strategy' ' |
130ab8ab JN |
95 | cat <<-\EOF >expected && |
96 | Trying simple merge. | |
97 | [master OBJID] second | |
98 | Author: A U Thor <author@example.com> | |
7f814632 | 99 | 1 file changed, 1 insertion(+) |
130ab8ab JN |
100 | Trying simple merge. |
101 | [master OBJID] third | |
102 | Author: A U Thor <author@example.com> | |
7f814632 | 103 | 1 file changed, 1 insertion(+) |
130ab8ab JN |
104 | Trying simple merge. |
105 | [master OBJID] fourth | |
106 | Author: A U Thor <author@example.com> | |
7f814632 | 107 | 1 file changed, 1 insertion(+) |
7b53b92f CC |
108 | EOF |
109 | ||
18c8ff46 | 110 | git checkout -f master && |
aa29ccf4 CC |
111 | git reset --hard first && |
112 | test_tick && | |
130ab8ab | 113 | git cherry-pick --strategy resolve first..fourth >actual && |
130ab8ab | 114 | sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy && |
2593633f | 115 | test_i18ncmp expected actual.fuzzy |
aa29ccf4 CC |
116 | ' |
117 | ||
118 | test_expect_success 'cherry-pick --ff first..fourth works' ' | |
18c8ff46 | 119 | git checkout -f master && |
aa29ccf4 CC |
120 | git reset --hard first && |
121 | test_tick && | |
122 | git cherry-pick --ff first..fourth && | |
123 | git diff --quiet other && | |
124 | git diff --quiet HEAD other && | |
6bc83cdd | 125 | check_head_equals fourth |
aa29ccf4 CC |
126 | ' |
127 | ||
128 | test_expect_success 'cherry-pick -n first..fourth works' ' | |
18c8ff46 | 129 | git checkout -f master && |
aa29ccf4 CC |
130 | git reset --hard first && |
131 | test_tick && | |
132 | git cherry-pick -n first..fourth && | |
133 | git diff --quiet other && | |
134 | git diff --cached --quiet other && | |
135 | git diff --quiet HEAD first | |
136 | ' | |
137 | ||
138 | test_expect_success 'revert first..fourth works' ' | |
18c8ff46 | 139 | git checkout -f master && |
aa29ccf4 CC |
140 | git reset --hard fourth && |
141 | test_tick && | |
142 | git revert first..fourth && | |
143 | git diff --quiet first && | |
144 | git diff --cached --quiet first && | |
145 | git diff --quiet HEAD first | |
146 | ' | |
147 | ||
148 | test_expect_success 'revert ^first fourth works' ' | |
18c8ff46 | 149 | git checkout -f master && |
aa29ccf4 CC |
150 | git reset --hard fourth && |
151 | test_tick && | |
152 | git revert ^first fourth && | |
153 | git diff --quiet first && | |
154 | git diff --cached --quiet first && | |
155 | git diff --quiet HEAD first | |
156 | ' | |
157 | ||
158 | test_expect_success 'revert fourth fourth~1 fourth~2 works' ' | |
18c8ff46 | 159 | git checkout -f master && |
aa29ccf4 CC |
160 | git reset --hard fourth && |
161 | test_tick && | |
162 | git revert fourth fourth~1 fourth~2 && | |
163 | git diff --quiet first && | |
164 | git diff --cached --quiet first && | |
165 | git diff --quiet HEAD first | |
166 | ' | |
167 | ||
65281b70 | 168 | test_expect_success 'cherry-pick -3 fourth works' ' |
18c8ff46 | 169 | git checkout -f master && |
aa29ccf4 CC |
170 | git reset --hard first && |
171 | test_tick && | |
172 | git cherry-pick -3 fourth && | |
173 | git diff --quiet other && | |
174 | git diff --quiet HEAD other && | |
6bc83cdd | 175 | check_head_differs_from fourth |
aa29ccf4 CC |
176 | ' |
177 | ||
f873a273 CC |
178 | test_expect_success 'cherry-pick --stdin works' ' |
179 | git checkout -f master && | |
180 | git reset --hard first && | |
181 | test_tick && | |
182 | git rev-list --reverse first..fourth | git cherry-pick --stdin && | |
183 | git diff --quiet other && | |
184 | git diff --quiet HEAD other && | |
6bc83cdd | 185 | check_head_differs_from fourth |
f873a273 CC |
186 | ' |
187 | ||
aa29ccf4 | 188 | test_done |