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