2.36 fast-export regression fix
[git.git] / t / t3508-cherry-pick-many-commits.sh
blob2d53ce754c5fb75ceeaa43dc1ba2f748fd58f43e
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-lib.sh
10 check_head_differs_from() {
11 test_cmp_rev ! HEAD "$1"
14 check_head_equals() {
15 test_cmp_rev HEAD "$1"
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 &&
25 git checkout -b other &&
26 for val in second third fourth
28 echo $val >> file1 &&
29 git add file1 &&
30 test_tick &&
31 git commit -m "$val" &&
32 git tag $val || return 1
33 done
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
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"
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:
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
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_cmp expected actual.fuzzy
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
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(+)
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_cmp expected actual.fuzzy
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
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
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
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
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
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
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
199 test_done