Sync with maint
[git.git] / t / t3508-cherry-pick-many-commits.sh
blobb457333e1865de794e47fa6b601648fd67a02a7c
1 #!/bin/sh
3 test_description='test cherry-picking many commits'
5 . ./test-lib.sh
7 check_head_differs_from() {
8 ! test_cmp_rev HEAD "$1"
11 check_head_equals() {
12 test_cmp_rev HEAD "$1"
15 test_expect_success setup '
16 echo first > file1 &&
17 git add file1 &&
18 test_tick &&
19 git commit -m "first" &&
20 git tag first &&
22 git checkout -b other &&
23 for val in second third fourth
25 echo $val >> file1 &&
26 git add file1 &&
27 test_tick &&
28 git commit -m "$val" &&
29 git tag $val
30 done
33 test_expect_success 'cherry-pick first..fourth works' '
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
43 test_expect_success 'cherry-pick three one two works' '
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
54 one
55 two"
58 test_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:
64 test_expect_success 'output to keep user entertained during multi-pick' '
65 cat <<-\EOF >expected &&
66 [master OBJID] second
67 Author: A U Thor <author@example.com>
68 Date: Thu Apr 7 15:14:13 2005 -0700
69 1 file changed, 1 insertion(+)
70 [master OBJID] third
71 Author: A U Thor <author@example.com>
72 Date: Thu Apr 7 15:15:13 2005 -0700
73 1 file changed, 1 insertion(+)
74 [master OBJID] fourth
75 Author: A U Thor <author@example.com>
76 Date: Thu Apr 7 15:16:13 2005 -0700
77 1 file changed, 1 insertion(+)
78 EOF
80 git checkout -f master &&
81 git reset --hard first &&
82 test_tick &&
83 git cherry-pick first..fourth >actual &&
84 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
85 test_line_count -ge 3 actual.fuzzy &&
86 test_i18ncmp expected actual.fuzzy
89 test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
90 git checkout -f master &&
91 git reset --hard first &&
92 test_tick &&
93 git cherry-pick --strategy resolve first..fourth &&
94 git diff --quiet other &&
95 git diff --quiet HEAD other &&
96 check_head_differs_from fourth
99 test_expect_success 'output during multi-pick indicates merge strategy' '
100 cat <<-\EOF >expected &&
101 Trying simple merge.
102 [master OBJID] second
103 Author: A U Thor <author@example.com>
104 Date: Thu Apr 7 15:14:13 2005 -0700
105 1 file changed, 1 insertion(+)
106 Trying simple merge.
107 [master OBJID] third
108 Author: A U Thor <author@example.com>
109 Date: Thu Apr 7 15:15:13 2005 -0700
110 1 file changed, 1 insertion(+)
111 Trying simple merge.
112 [master OBJID] fourth
113 Author: A U Thor <author@example.com>
114 Date: Thu Apr 7 15:16:13 2005 -0700
115 1 file changed, 1 insertion(+)
118 git checkout -f master &&
119 git reset --hard first &&
120 test_tick &&
121 git cherry-pick --strategy resolve first..fourth >actual &&
122 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
123 test_i18ncmp expected actual.fuzzy
126 test_expect_success 'cherry-pick --ff first..fourth works' '
127 git checkout -f master &&
128 git reset --hard first &&
129 test_tick &&
130 git cherry-pick --ff first..fourth &&
131 git diff --quiet other &&
132 git diff --quiet HEAD other &&
133 check_head_equals fourth
136 test_expect_success 'cherry-pick -n first..fourth works' '
137 git checkout -f master &&
138 git reset --hard first &&
139 test_tick &&
140 git cherry-pick -n first..fourth &&
141 git diff --quiet other &&
142 git diff --cached --quiet other &&
143 git diff --quiet HEAD first
146 test_expect_success 'revert first..fourth works' '
147 git checkout -f master &&
148 git reset --hard fourth &&
149 test_tick &&
150 git revert first..fourth &&
151 git diff --quiet first &&
152 git diff --cached --quiet first &&
153 git diff --quiet HEAD first
156 test_expect_success 'revert ^first fourth works' '
157 git checkout -f master &&
158 git reset --hard fourth &&
159 test_tick &&
160 git revert ^first fourth &&
161 git diff --quiet first &&
162 git diff --cached --quiet first &&
163 git diff --quiet HEAD first
166 test_expect_success 'revert fourth fourth~1 fourth~2 works' '
167 git checkout -f master &&
168 git reset --hard fourth &&
169 test_tick &&
170 git revert fourth fourth~1 fourth~2 &&
171 git diff --quiet first &&
172 git diff --cached --quiet first &&
173 git diff --quiet HEAD first
176 test_expect_success 'cherry-pick -3 fourth works' '
177 git checkout -f master &&
178 git reset --hard first &&
179 test_tick &&
180 git cherry-pick -3 fourth &&
181 git diff --quiet other &&
182 git diff --quiet HEAD other &&
183 check_head_differs_from fourth
186 test_expect_success 'cherry-pick --stdin works' '
187 git checkout -f master &&
188 git reset --hard first &&
189 test_tick &&
190 git rev-list --reverse first..fourth | git cherry-pick --stdin &&
191 git diff --quiet other &&
192 git diff --quiet HEAD other &&
193 check_head_differs_from fourth
196 test_done