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