t8*: adjust the references to the default branch name "main"
[git] / t / t3508-cherry-pick-many-commits.sh
1 #!/bin/sh
2
3 test_description='test cherry-picking many commits'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 check_head_differs_from() {
11         test_cmp_rev ! HEAD "$1"
12 }
13
14 check_head_equals() {
15         test_cmp_rev HEAD "$1"
16 }
17
18 test_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
36 test_expect_success 'cherry-pick first..fourth works' '
37         git checkout -f main &&
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
46 test_expect_success 'cherry-pick three one two works' '
47         git checkout -f first &&
48         test_commit one &&
49         test_commit two &&
50         test_commit three &&
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
57 one
58 two"
59 '
60
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:
65 '
66
67 test_expect_success 'output to keep user entertained during multi-pick' '
68         cat <<-\EOF >expected &&
69         [main OBJID] second
70          Author: A U Thor <author@example.com>
71          Date: Thu Apr 7 15:14:13 2005 -0700
72          1 file changed, 1 insertion(+)
73         [main OBJID] third
74          Author: A U Thor <author@example.com>
75          Date: Thu Apr 7 15:15:13 2005 -0700
76          1 file changed, 1 insertion(+)
77         [main OBJID] fourth
78          Author: A U Thor <author@example.com>
79          Date: Thu Apr 7 15:16:13 2005 -0700
80          1 file changed, 1 insertion(+)
81         EOF
82
83         git checkout -f main &&
84         git reset --hard first &&
85         test_tick &&
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_i18ncmp expected actual.fuzzy
90 '
91
92 test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
93         git checkout -f main &&
94         git reset --hard first &&
95         test_tick &&
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
100 '
101
102 test_expect_success 'output during multi-pick indicates merge strategy' '
103         cat <<-\EOF >expected &&
104         Trying simple merge.
105         [main OBJID] second
106          Author: A U Thor <author@example.com>
107          Date: Thu Apr 7 15:14:13 2005 -0700
108          1 file changed, 1 insertion(+)
109         Trying simple merge.
110         [main OBJID] third
111          Author: A U Thor <author@example.com>
112          Date: Thu Apr 7 15:15:13 2005 -0700
113          1 file changed, 1 insertion(+)
114         Trying simple merge.
115         [main OBJID] fourth
116          Author: A U Thor <author@example.com>
117          Date: Thu Apr 7 15:16:13 2005 -0700
118          1 file changed, 1 insertion(+)
119         EOF
120
121         git checkout -f main &&
122         git reset --hard first &&
123         test_tick &&
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_i18ncmp expected actual.fuzzy
127 '
128
129 test_expect_success 'cherry-pick --ff first..fourth works' '
130         git checkout -f main &&
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 &&
136         check_head_equals fourth
137 '
138
139 test_expect_success 'cherry-pick -n first..fourth works' '
140         git checkout -f main &&
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
149 test_expect_success 'revert first..fourth works' '
150         git checkout -f main &&
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
159 test_expect_success 'revert ^first fourth works' '
160         git checkout -f main &&
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
169 test_expect_success 'revert fourth fourth~1 fourth~2 works' '
170         git checkout -f main &&
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
179 test_expect_success 'cherry-pick -3 fourth works' '
180         git checkout -f main &&
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 &&
186         check_head_differs_from fourth
187 '
188
189 test_expect_success 'cherry-pick --stdin works' '
190         git checkout -f main &&
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 &&
196         check_head_differs_from fourth
197 '
198
199 test_done