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
'output to keep user entertained during multi-pick' '
59 cat <<-\EOF >expected &&
61 Author: A U Thor <author@example.com>
62 1 file changed, 1 insertion(+)
64 Author: A U Thor <author@example.com>
65 1 file changed, 1 insertion(+)
67 Author: A U Thor <author@example.com>
68 1 file changed, 1 insertion(+)
71 git checkout -f master &&
72 git reset --hard first &&
74 git cherry-pick first..fourth >actual &&
75 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
76 test_line_count -ge 3 actual.fuzzy &&
77 test_i18ncmp expected actual.fuzzy
80 test_expect_success
'cherry-pick --strategy resolve first..fourth works' '
81 git checkout -f master &&
82 git reset --hard first &&
84 git cherry-pick --strategy resolve first..fourth &&
85 git diff --quiet other &&
86 git diff --quiet HEAD other &&
87 check_head_differs_from fourth
90 test_expect_success
'output during multi-pick indicates merge strategy' '
91 cat <<-\EOF >expected &&
94 Author: A U Thor <author@example.com>
95 1 file changed, 1 insertion(+)
98 Author: A U Thor <author@example.com>
99 1 file changed, 1 insertion(+)
101 [master OBJID] fourth
102 Author: A U Thor <author@example.com>
103 1 file changed, 1 insertion(+)
106 git checkout -f master &&
107 git reset --hard first &&
109 git cherry-pick --strategy resolve first..fourth >actual &&
110 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
111 test_i18ncmp expected actual.fuzzy
114 test_expect_success
'cherry-pick --ff first..fourth works' '
115 git checkout -f master &&
116 git reset --hard first &&
118 git cherry-pick --ff first..fourth &&
119 git diff --quiet other &&
120 git diff --quiet HEAD other &&
121 check_head_equals fourth
124 test_expect_success
'cherry-pick -n first..fourth works' '
125 git checkout -f master &&
126 git reset --hard first &&
128 git cherry-pick -n first..fourth &&
129 git diff --quiet other &&
130 git diff --cached --quiet other &&
131 git diff --quiet HEAD first
134 test_expect_success
'revert first..fourth works' '
135 git checkout -f master &&
136 git reset --hard fourth &&
138 git revert first..fourth &&
139 git diff --quiet first &&
140 git diff --cached --quiet first &&
141 git diff --quiet HEAD first
144 test_expect_success
'revert ^first fourth works' '
145 git checkout -f master &&
146 git reset --hard fourth &&
148 git revert ^first fourth &&
149 git diff --quiet first &&
150 git diff --cached --quiet first &&
151 git diff --quiet HEAD first
154 test_expect_success
'revert fourth fourth~1 fourth~2 works' '
155 git checkout -f master &&
156 git reset --hard fourth &&
158 git revert fourth fourth~1 fourth~2 &&
159 git diff --quiet first &&
160 git diff --cached --quiet first &&
161 git diff --quiet HEAD first
164 test_expect_success
'cherry-pick -3 fourth works' '
165 git checkout -f master &&
166 git reset --hard first &&
168 git cherry-pick -3 fourth &&
169 git diff --quiet other &&
170 git diff --quiet HEAD other &&
171 check_head_differs_from fourth
174 test_expect_success
'cherry-pick --stdin works' '
175 git checkout -f master &&
176 git reset --hard first &&
178 git rev-list --reverse first..fourth | git cherry-pick --stdin &&
179 git diff --quiet other &&
180 git diff --quiet HEAD other &&
181 check_head_differs_from fourth