3 test_description
='test cherry-picking many commits'
7 check_head_differs_from
() {
8 test_cmp_rev
! HEAD
"$1"
12 test_cmp_rev HEAD
"$1"
15 test_expect_success setup
'
19 git commit -m "first" &&
22 git checkout -b other &&
23 for val in second third fourth
28 git commit -m "$val" &&
33 test_expect_success
'cherry-pick first..fourth works' '
34 git checkout -f master &&
35 git reset --hard first &&
37 git cherry-pick first..fourth &&
38 git diff --quiet other &&
39 git diff --quiet HEAD other &&
40 check_head_differs_from fourth
43 test_expect_success
'cherry-pick three one two works' '
44 git checkout -f first &&
48 git checkout -f master &&
49 git reset --hard first &&
50 git cherry-pick three one two &&
51 git diff --quiet three &&
52 git diff --quiet HEAD three &&
53 test "$(git log --reverse --format=%s first..)" = "three
58 test_expect_success
'cherry-pick three one two: fails' '
59 git checkout -f master &&
60 git reset --hard first &&
61 test_must_fail git cherry-pick three one two:
64 test_expect_success
'output to keep user entertained during multi-pick' '
65 cat <<-\EOF >expected &&
67 Author: A U Thor <author@example.com>
68 Date: Thu Apr 7 15:14:13 2005 -0700
69 1 file changed, 1 insertion(+)
71 Author: A U Thor <author@example.com>
72 Date: Thu Apr 7 15:15:13 2005 -0700
73 1 file changed, 1 insertion(+)
75 Author: A U Thor <author@example.com>
76 Date: Thu Apr 7 15:16:13 2005 -0700
77 1 file changed, 1 insertion(+)
80 git checkout -f master &&
81 git reset --hard first &&
83 git cherry-pick first..fourth >actual &&
84 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
85 test_line_count -ge 3 actual.fuzzy &&
86 test_i18ncmp expected actual.fuzzy
89 test_expect_success
'cherry-pick --strategy resolve first..fourth works' '
90 git checkout -f master &&
91 git reset --hard first &&
93 git cherry-pick --strategy resolve first..fourth &&
94 git diff --quiet other &&
95 git diff --quiet HEAD other &&
96 check_head_differs_from fourth
99 test_expect_success
'output during multi-pick indicates merge strategy' '
100 cat <<-\EOF >expected &&
102 [master OBJID] second
103 Author: A U Thor <author@example.com>
104 Date: Thu Apr 7 15:14:13 2005 -0700
105 1 file changed, 1 insertion(+)
108 Author: A U Thor <author@example.com>
109 Date: Thu Apr 7 15:15:13 2005 -0700
110 1 file changed, 1 insertion(+)
112 [master OBJID] fourth
113 Author: A U Thor <author@example.com>
114 Date: Thu Apr 7 15:16:13 2005 -0700
115 1 file changed, 1 insertion(+)
118 git checkout -f master &&
119 git reset --hard first &&
121 git cherry-pick --strategy resolve first..fourth >actual &&
122 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
123 test_i18ncmp expected actual.fuzzy
126 test_expect_success
'cherry-pick --ff first..fourth works' '
127 git checkout -f master &&
128 git reset --hard first &&
130 git cherry-pick --ff first..fourth &&
131 git diff --quiet other &&
132 git diff --quiet HEAD other &&
133 check_head_equals fourth
136 test_expect_success
'cherry-pick -n first..fourth works' '
137 git checkout -f master &&
138 git reset --hard first &&
140 git cherry-pick -n first..fourth &&
141 git diff --quiet other &&
142 git diff --cached --quiet other &&
143 git diff --quiet HEAD first
146 test_expect_success
'revert first..fourth works' '
147 git checkout -f master &&
148 git reset --hard fourth &&
150 git revert first..fourth &&
151 git diff --quiet first &&
152 git diff --cached --quiet first &&
153 git diff --quiet HEAD first
156 test_expect_success
'revert ^first fourth works' '
157 git checkout -f master &&
158 git reset --hard fourth &&
160 git revert ^first fourth &&
161 git diff --quiet first &&
162 git diff --cached --quiet first &&
163 git diff --quiet HEAD first
166 test_expect_success
'revert fourth fourth~1 fourth~2 works' '
167 git checkout -f master &&
168 git reset --hard fourth &&
170 git revert fourth fourth~1 fourth~2 &&
171 git diff --quiet first &&
172 git diff --cached --quiet first &&
173 git diff --quiet HEAD first
176 test_expect_success
'cherry-pick -3 fourth works' '
177 git checkout -f master &&
178 git reset --hard first &&
180 git cherry-pick -3 fourth &&
181 git diff --quiet other &&
182 git diff --quiet HEAD other &&
183 check_head_differs_from fourth
186 test_expect_success
'cherry-pick --stdin works' '
187 git checkout -f master &&
188 git reset --hard first &&
190 git rev-list --reverse first..fourth | git cherry-pick --stdin &&
191 git diff --quiet other &&
192 git diff --quiet HEAD other &&
193 check_head_differs_from fourth