Sync with 'master'
[alt-git.git] / t / t3508-cherry-pick-many-commits.sh
blobafa7727a4af8e489b8b3f36213a15ed83dc9e561
1 #!/bin/sh
3 test_description='test cherry-picking many commits'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 check_head_differs_from() {
12 test_cmp_rev ! HEAD "$1"
15 check_head_equals() {
16 test_cmp_rev HEAD "$1"
19 test_expect_success setup '
20 echo first > file1 &&
21 git add file1 &&
22 test_tick &&
23 git commit -m "first" &&
24 git tag first &&
26 git checkout -b other &&
27 for val in second third fourth
29 echo $val >> file1 &&
30 git add file1 &&
31 test_tick &&
32 git commit -m "$val" &&
33 git tag $val || return 1
34 done
37 test_expect_success 'cherry-pick first..fourth works' '
38 git checkout -f main &&
39 git reset --hard first &&
40 test_tick &&
41 git cherry-pick first..fourth &&
42 git diff --quiet other &&
43 git diff --quiet HEAD other &&
44 check_head_differs_from fourth
47 test_expect_success 'cherry-pick three one two works' '
48 git checkout -f first &&
49 test_commit one &&
50 test_commit two &&
51 test_commit three &&
52 git checkout -f main &&
53 git reset --hard first &&
54 git cherry-pick three one two &&
55 git diff --quiet three &&
56 git diff --quiet HEAD three &&
57 test "$(git log --reverse --format=%s first..)" = "three
58 one
59 two"
62 test_expect_success 'cherry-pick three one two: fails' '
63 git checkout -f main &&
64 git reset --hard first &&
65 test_must_fail git cherry-pick three one two:
68 test_expect_success 'output to keep user entertained during multi-pick' '
69 cat <<-\EOF >expected &&
70 [main OBJID] second
71 Author: A U Thor <author@example.com>
72 Date: Thu Apr 7 15:14:13 2005 -0700
73 1 file changed, 1 insertion(+)
74 [main OBJID] third
75 Author: A U Thor <author@example.com>
76 Date: Thu Apr 7 15:15:13 2005 -0700
77 1 file changed, 1 insertion(+)
78 [main OBJID] fourth
79 Author: A U Thor <author@example.com>
80 Date: Thu Apr 7 15:16:13 2005 -0700
81 1 file changed, 1 insertion(+)
82 EOF
84 git checkout -f main &&
85 git reset --hard first &&
86 test_tick &&
87 git cherry-pick first..fourth >actual &&
88 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
89 test_line_count -ge 3 actual.fuzzy &&
90 test_cmp expected actual.fuzzy
93 test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
94 git checkout -f main &&
95 git reset --hard first &&
96 test_tick &&
97 git cherry-pick --strategy resolve first..fourth &&
98 git diff --quiet other &&
99 git diff --quiet HEAD other &&
100 check_head_differs_from fourth
103 test_expect_success 'output during multi-pick indicates merge strategy' '
104 cat <<-\EOF >expected &&
105 Trying simple merge.
106 [main OBJID] second
107 Author: A U Thor <author@example.com>
108 Date: Thu Apr 7 15:14:13 2005 -0700
109 1 file changed, 1 insertion(+)
110 Trying simple merge.
111 [main OBJID] third
112 Author: A U Thor <author@example.com>
113 Date: Thu Apr 7 15:15:13 2005 -0700
114 1 file changed, 1 insertion(+)
115 Trying simple merge.
116 [main OBJID] fourth
117 Author: A U Thor <author@example.com>
118 Date: Thu Apr 7 15:16:13 2005 -0700
119 1 file changed, 1 insertion(+)
122 git checkout -f main &&
123 git reset --hard first &&
124 test_tick &&
125 git cherry-pick --strategy resolve first..fourth >actual &&
126 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
127 test_cmp expected actual.fuzzy
130 test_expect_success 'cherry-pick --ff first..fourth works' '
131 git checkout -f main &&
132 git reset --hard first &&
133 test_tick &&
134 git cherry-pick --ff first..fourth &&
135 git diff --quiet other &&
136 git diff --quiet HEAD other &&
137 check_head_equals fourth
140 test_expect_success 'cherry-pick -n first..fourth works' '
141 git checkout -f main &&
142 git reset --hard first &&
143 test_tick &&
144 git cherry-pick -n first..fourth &&
145 git diff --quiet other &&
146 git diff --cached --quiet other &&
147 git diff --quiet HEAD first
150 test_expect_success 'revert first..fourth works' '
151 git checkout -f main &&
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
160 test_expect_success 'revert ^first fourth works' '
161 git checkout -f main &&
162 git reset --hard fourth &&
163 test_tick &&
164 git revert ^first fourth &&
165 git diff --quiet first &&
166 git diff --cached --quiet first &&
167 git diff --quiet HEAD first
170 test_expect_success 'revert fourth fourth~1 fourth~2 works' '
171 git checkout -f main &&
172 git reset --hard fourth &&
173 test_tick &&
174 git revert fourth fourth~1 fourth~2 &&
175 git diff --quiet first &&
176 git diff --cached --quiet first &&
177 git diff --quiet HEAD first
180 test_expect_success 'cherry-pick -3 fourth works' '
181 git checkout -f main &&
182 git reset --hard first &&
183 test_tick &&
184 git cherry-pick -3 fourth &&
185 git diff --quiet other &&
186 git diff --quiet HEAD other &&
187 check_head_differs_from fourth
190 test_expect_success 'cherry-pick --stdin works' '
191 git checkout -f main &&
192 git reset --hard first &&
193 test_tick &&
194 git rev-list --reverse first..fourth | git cherry-pick --stdin &&
195 git diff --quiet other &&
196 git diff --quiet HEAD other &&
197 check_head_differs_from fourth
200 test_done