]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3508-cherry-pick-many-commits.sh
remote-bzr: improve tag handling
[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
2593633f 58test_expect_success 'output to keep user entertained during multi-pick' '
130ab8ab
JN
59 cat <<-\EOF >expected &&
60 [master OBJID] second
61 Author: A U Thor <author@example.com>
7f814632 62 1 file changed, 1 insertion(+)
130ab8ab
JN
63 [master OBJID] third
64 Author: A U Thor <author@example.com>
7f814632 65 1 file changed, 1 insertion(+)
130ab8ab
JN
66 [master OBJID] fourth
67 Author: A U Thor <author@example.com>
7f814632 68 1 file changed, 1 insertion(+)
7b53b92f
CC
69 EOF
70
71 git checkout -f master &&
72 git reset --hard first &&
73 test_tick &&
130ab8ab 74 git cherry-pick first..fourth >actual &&
2593633f
JN
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
78'
79
80test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
81 git checkout -f master &&
82 git reset --hard first &&
83 test_tick &&
84 git cherry-pick --strategy resolve first..fourth &&
7b53b92f
CC
85 git diff --quiet other &&
86 git diff --quiet HEAD other &&
6bc83cdd 87 check_head_differs_from fourth
7b53b92f
CC
88'
89
2593633f 90test_expect_success 'output during multi-pick indicates merge strategy' '
130ab8ab
JN
91 cat <<-\EOF >expected &&
92 Trying simple merge.
93 [master OBJID] second
94 Author: A U Thor <author@example.com>
7f814632 95 1 file changed, 1 insertion(+)
130ab8ab
JN
96 Trying simple merge.
97 [master OBJID] third
98 Author: A U Thor <author@example.com>
7f814632 99 1 file changed, 1 insertion(+)
130ab8ab
JN
100 Trying simple merge.
101 [master OBJID] fourth
102 Author: A U Thor <author@example.com>
7f814632 103 1 file changed, 1 insertion(+)
7b53b92f
CC
104 EOF
105
18c8ff46 106 git checkout -f master &&
aa29ccf4
CC
107 git reset --hard first &&
108 test_tick &&
130ab8ab 109 git cherry-pick --strategy resolve first..fourth >actual &&
130ab8ab 110 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
2593633f 111 test_i18ncmp expected actual.fuzzy
aa29ccf4
CC
112'
113
114test_expect_success 'cherry-pick --ff first..fourth works' '
18c8ff46 115 git checkout -f master &&
aa29ccf4
CC
116 git reset --hard first &&
117 test_tick &&
118 git cherry-pick --ff first..fourth &&
119 git diff --quiet other &&
120 git diff --quiet HEAD other &&
6bc83cdd 121 check_head_equals fourth
aa29ccf4
CC
122'
123
124test_expect_success 'cherry-pick -n first..fourth works' '
18c8ff46 125 git checkout -f master &&
aa29ccf4
CC
126 git reset --hard first &&
127 test_tick &&
128 git cherry-pick -n first..fourth &&
129 git diff --quiet other &&
130 git diff --cached --quiet other &&
131 git diff --quiet HEAD first
132'
133
134test_expect_success 'revert first..fourth works' '
18c8ff46 135 git checkout -f master &&
aa29ccf4
CC
136 git reset --hard fourth &&
137 test_tick &&
138 git revert first..fourth &&
139 git diff --quiet first &&
140 git diff --cached --quiet first &&
141 git diff --quiet HEAD first
142'
143
144test_expect_success 'revert ^first fourth works' '
18c8ff46 145 git checkout -f master &&
aa29ccf4
CC
146 git reset --hard fourth &&
147 test_tick &&
148 git revert ^first fourth &&
149 git diff --quiet first &&
150 git diff --cached --quiet first &&
151 git diff --quiet HEAD first
152'
153
154test_expect_success 'revert fourth fourth~1 fourth~2 works' '
18c8ff46 155 git checkout -f master &&
aa29ccf4
CC
156 git reset --hard fourth &&
157 test_tick &&
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
162'
163
65281b70 164test_expect_success 'cherry-pick -3 fourth works' '
18c8ff46 165 git checkout -f master &&
aa29ccf4
CC
166 git reset --hard first &&
167 test_tick &&
168 git cherry-pick -3 fourth &&
169 git diff --quiet other &&
170 git diff --quiet HEAD other &&
6bc83cdd 171 check_head_differs_from fourth
aa29ccf4
CC
172'
173
f873a273
CC
174test_expect_success 'cherry-pick --stdin works' '
175 git checkout -f master &&
176 git reset --hard first &&
177 test_tick &&
178 git rev-list --reverse first..fourth | git cherry-pick --stdin &&
179 git diff --quiet other &&
180 git diff --quiet HEAD other &&
6bc83cdd 181 check_head_differs_from fourth
f873a273
CC
182'
183
aa29ccf4 184test_done