3 test_description
='test cherry-picking many commits'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 check_head_differs_from
() {
11 test_cmp_rev
! HEAD
"$1"
15 test_cmp_rev HEAD
"$1"
18 test_expect_success setup
'
22 git commit -m "first" &&
25 git checkout -b other &&
26 for val in second third fourth
31 git commit -m "$val" &&
32 git tag $val || return 1
36 test_expect_success
'cherry-pick first..fourth works' '
37 git checkout -f main &&
38 git reset --hard first &&
40 git cherry-pick first..fourth &&
41 git diff --quiet other &&
42 git diff --quiet HEAD other &&
43 check_head_differs_from fourth
46 test_expect_success
'cherry-pick three one two works' '
47 git checkout -f first &&
51 git checkout -f main &&
52 git reset --hard first &&
53 git cherry-pick three one two &&
54 git diff --quiet three &&
55 git diff --quiet HEAD three &&
56 test "$(git log --reverse --format=%s first..)" = "three
61 test_expect_success
'cherry-pick three one two: fails' '
62 git checkout -f main &&
63 git reset --hard first &&
64 test_must_fail git cherry-pick three one two:
67 test_expect_success
'output to keep user entertained during multi-pick' '
68 cat <<-\EOF >expected &&
70 Author: A U Thor <author@example.com>
71 Date: Thu Apr 7 15:14:13 2005 -0700
72 1 file changed, 1 insertion(+)
74 Author: A U Thor <author@example.com>
75 Date: Thu Apr 7 15:15:13 2005 -0700
76 1 file changed, 1 insertion(+)
78 Author: A U Thor <author@example.com>
79 Date: Thu Apr 7 15:16:13 2005 -0700
80 1 file changed, 1 insertion(+)
83 git checkout -f main &&
84 git reset --hard first &&
86 git cherry-pick first..fourth >actual &&
87 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
88 test_line_count -ge 3 actual.fuzzy &&
89 test_cmp expected actual.fuzzy
92 test_expect_success
'cherry-pick --strategy resolve first..fourth works' '
93 git checkout -f main &&
94 git reset --hard first &&
96 git cherry-pick --strategy resolve first..fourth &&
97 git diff --quiet other &&
98 git diff --quiet HEAD other &&
99 check_head_differs_from fourth
102 test_expect_success
'output during multi-pick indicates merge strategy' '
103 cat <<-\EOF >expected &&
106 Author: A U Thor <author@example.com>
107 Date: Thu Apr 7 15:14:13 2005 -0700
108 1 file changed, 1 insertion(+)
111 Author: A U Thor <author@example.com>
112 Date: Thu Apr 7 15:15:13 2005 -0700
113 1 file changed, 1 insertion(+)
116 Author: A U Thor <author@example.com>
117 Date: Thu Apr 7 15:16:13 2005 -0700
118 1 file changed, 1 insertion(+)
121 git checkout -f main &&
122 git reset --hard first &&
124 git cherry-pick --strategy resolve first..fourth >actual &&
125 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
126 test_cmp expected actual.fuzzy
129 test_expect_success
'cherry-pick --ff first..fourth works' '
130 git checkout -f main &&
131 git reset --hard first &&
133 git cherry-pick --ff first..fourth &&
134 git diff --quiet other &&
135 git diff --quiet HEAD other &&
136 check_head_equals fourth
139 test_expect_success
'cherry-pick -n first..fourth works' '
140 git checkout -f main &&
141 git reset --hard first &&
143 git cherry-pick -n first..fourth &&
144 git diff --quiet other &&
145 git diff --cached --quiet other &&
146 git diff --quiet HEAD first
149 test_expect_success
'revert first..fourth works' '
150 git checkout -f main &&
151 git reset --hard fourth &&
153 git revert first..fourth &&
154 git diff --quiet first &&
155 git diff --cached --quiet first &&
156 git diff --quiet HEAD first
159 test_expect_success
'revert ^first fourth works' '
160 git checkout -f main &&
161 git reset --hard fourth &&
163 git revert ^first fourth &&
164 git diff --quiet first &&
165 git diff --cached --quiet first &&
166 git diff --quiet HEAD first
169 test_expect_success
'revert fourth fourth~1 fourth~2 works' '
170 git checkout -f main &&
171 git reset --hard fourth &&
173 git revert fourth fourth~1 fourth~2 &&
174 git diff --quiet first &&
175 git diff --cached --quiet first &&
176 git diff --quiet HEAD first
179 test_expect_success
'cherry-pick -3 fourth works' '
180 git checkout -f main &&
181 git reset --hard first &&
183 git cherry-pick -3 fourth &&
184 git diff --quiet other &&
185 git diff --quiet HEAD other &&
186 check_head_differs_from fourth
189 test_expect_success
'cherry-pick --stdin works' '
190 git checkout -f main &&
191 git reset --hard first &&
193 git rev-list --reverse first..fourth | git cherry-pick --stdin &&
194 git diff --quiet other &&
195 git diff --quiet HEAD other &&
196 check_head_differs_from fourth