3 test_description='test cherry-picking many commits'
7 check_head_differs_from() {
8 head=$(git rev-parse --verify HEAD) &&
9 arg=$(git rev-parse --verify "$1") &&
10 test "$head" != "$arg"
14 head=$(git rev-parse --verify HEAD) &&
15 arg=$(git rev-parse --verify "$1") &&
19 test_expect_success setup '
23 git commit -m "first" &&
26 git checkout -b other &&
27 for val in second third fourth
32 git commit -m "$val" &&
37 test_expect_success 'cherry-pick first..fourth works' '
38 git checkout -f master &&
39 git reset --hard first &&
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 &&
52 git checkout -f master &&
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
62 test_expect_success 'output to keep user entertained during multi-pick' '
63 cat <<-\EOF >expected &&
65 Author: A U Thor <author@example.com>
66 1 file changed, 1 insertion(+)
68 Author: A U Thor <author@example.com>
69 1 file changed, 1 insertion(+)
71 Author: A U Thor <author@example.com>
72 1 file changed, 1 insertion(+)
75 git checkout -f master &&
76 git reset --hard first &&
78 git cherry-pick first..fourth >actual &&
79 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
80 test_line_count -ge 3 actual.fuzzy &&
81 test_i18ncmp expected actual.fuzzy
84 test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
85 git checkout -f master &&
86 git reset --hard first &&
88 git cherry-pick --strategy resolve first..fourth &&
89 git diff --quiet other &&
90 git diff --quiet HEAD other &&
91 check_head_differs_from fourth
94 test_expect_success 'output during multi-pick indicates merge strategy' '
95 cat <<-\EOF >expected &&
98 Author: A U Thor <author@example.com>
99 1 file changed, 1 insertion(+)
102 Author: A U Thor <author@example.com>
103 1 file changed, 1 insertion(+)
105 [master OBJID] fourth
106 Author: A U Thor <author@example.com>
107 1 file changed, 1 insertion(+)
110 git checkout -f master &&
111 git reset --hard first &&
113 git cherry-pick --strategy resolve first..fourth >actual &&
114 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
115 test_i18ncmp expected actual.fuzzy
118 test_expect_success 'cherry-pick --ff first..fourth works' '
119 git checkout -f master &&
120 git reset --hard first &&
122 git cherry-pick --ff first..fourth &&
123 git diff --quiet other &&
124 git diff --quiet HEAD other &&
125 check_head_equals fourth
128 test_expect_success 'cherry-pick -n first..fourth works' '
129 git checkout -f master &&
130 git reset --hard first &&
132 git cherry-pick -n first..fourth &&
133 git diff --quiet other &&
134 git diff --cached --quiet other &&
135 git diff --quiet HEAD first
138 test_expect_success 'revert first..fourth works' '
139 git checkout -f master &&
140 git reset --hard fourth &&
142 git revert first..fourth &&
143 git diff --quiet first &&
144 git diff --cached --quiet first &&
145 git diff --quiet HEAD first
148 test_expect_success 'revert ^first fourth works' '
149 git checkout -f master &&
150 git reset --hard fourth &&
152 git revert ^first fourth &&
153 git diff --quiet first &&
154 git diff --cached --quiet first &&
155 git diff --quiet HEAD first
158 test_expect_success 'revert fourth fourth~1 fourth~2 works' '
159 git checkout -f master &&
160 git reset --hard fourth &&
162 git revert fourth fourth~1 fourth~2 &&
163 git diff --quiet first &&
164 git diff --cached --quiet first &&
165 git diff --quiet HEAD first
168 test_expect_success 'cherry-pick -3 fourth works' '
169 git checkout -f master &&
170 git reset --hard first &&
172 git cherry-pick -3 fourth &&
173 git diff --quiet other &&
174 git diff --quiet HEAD other &&
175 check_head_differs_from fourth
178 test_expect_success 'cherry-pick --stdin works' '
179 git checkout -f master &&
180 git reset --hard first &&
182 git rev-list --reverse first..fourth | git cherry-pick --stdin &&
183 git diff --quiet other &&
184 git diff --quiet HEAD other &&
185 check_head_differs_from fourth