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 1 file changed, 1 insertion(+)
70 Author: A U Thor <author@example.com>
71 1 file changed, 1 insertion(+)
73 Author: A U Thor <author@example.com>
74 1 file changed, 1 insertion(+)
77 git checkout -f master &&
78 git reset --hard first &&
80 git cherry-pick first..fourth >actual &&
81 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
82 test_line_count -ge 3 actual.fuzzy &&
83 test_i18ncmp expected actual.fuzzy
86 test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
87 git checkout -f master &&
88 git reset --hard first &&
90 git cherry-pick --strategy resolve first..fourth &&
91 git diff --quiet other &&
92 git diff --quiet HEAD other &&
93 check_head_differs_from fourth
96 test_expect_success 'output during multi-pick indicates merge strategy' '
97 cat <<-\EOF >expected &&
100 Author: A U Thor <author@example.com>
101 1 file changed, 1 insertion(+)
104 Author: A U Thor <author@example.com>
105 1 file changed, 1 insertion(+)
107 [master OBJID] fourth
108 Author: A U Thor <author@example.com>
109 1 file changed, 1 insertion(+)
112 git checkout -f master &&
113 git reset --hard first &&
115 git cherry-pick --strategy resolve first..fourth >actual &&
116 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
117 test_i18ncmp expected actual.fuzzy
120 test_expect_success 'cherry-pick --ff first..fourth works' '
121 git checkout -f master &&
122 git reset --hard first &&
124 git cherry-pick --ff first..fourth &&
125 git diff --quiet other &&
126 git diff --quiet HEAD other &&
127 check_head_equals fourth
130 test_expect_success 'cherry-pick -n first..fourth works' '
131 git checkout -f master &&
132 git reset --hard first &&
134 git cherry-pick -n first..fourth &&
135 git diff --quiet other &&
136 git diff --cached --quiet other &&
137 git diff --quiet HEAD first
140 test_expect_success 'revert first..fourth works' '
141 git checkout -f master &&
142 git reset --hard fourth &&
144 git revert first..fourth &&
145 git diff --quiet first &&
146 git diff --cached --quiet first &&
147 git diff --quiet HEAD first
150 test_expect_success 'revert ^first fourth works' '
151 git checkout -f master &&
152 git reset --hard fourth &&
154 git revert ^first fourth &&
155 git diff --quiet first &&
156 git diff --cached --quiet first &&
157 git diff --quiet HEAD first
160 test_expect_success 'revert fourth fourth~1 fourth~2 works' '
161 git checkout -f master &&
162 git reset --hard fourth &&
164 git revert fourth fourth~1 fourth~2 &&
165 git diff --quiet first &&
166 git diff --cached --quiet first &&
167 git diff --quiet HEAD first
170 test_expect_success 'cherry-pick -3 fourth works' '
171 git checkout -f master &&
172 git reset --hard first &&
174 git cherry-pick -3 fourth &&
175 git diff --quiet other &&
176 git diff --quiet HEAD other &&
177 check_head_differs_from fourth
180 test_expect_success 'cherry-pick --stdin works' '
181 git checkout -f master &&
182 git reset --hard first &&
184 git rev-list --reverse first..fourth | git cherry-pick --stdin &&
185 git diff --quiet other &&
186 git diff --quiet HEAD other &&
187 check_head_differs_from fourth