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 'output to keep user entertained during multi-pick' '
48 cat <<-\EOF >expected &&
50 Author: A U Thor <author@example.com>
51 1 file changed, 1 insertion(+)
53 Author: A U Thor <author@example.com>
54 1 file changed, 1 insertion(+)
56 Author: A U Thor <author@example.com>
57 1 file changed, 1 insertion(+)
60 git checkout -f master &&
61 git reset --hard first &&
63 git cherry-pick first..fourth >actual &&
64 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
65 test_line_count -ge 3 actual.fuzzy &&
66 test_i18ncmp expected actual.fuzzy
69 test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
70 git checkout -f master &&
71 git reset --hard first &&
73 git cherry-pick --strategy resolve first..fourth &&
74 git diff --quiet other &&
75 git diff --quiet HEAD other &&
76 check_head_differs_from fourth
79 test_expect_success 'output during multi-pick indicates merge strategy' '
80 cat <<-\EOF >expected &&
83 Author: A U Thor <author@example.com>
84 1 file changed, 1 insertion(+)
87 Author: A U Thor <author@example.com>
88 1 file changed, 1 insertion(+)
91 Author: A U Thor <author@example.com>
92 1 file changed, 1 insertion(+)
95 git checkout -f master &&
96 git reset --hard first &&
98 git cherry-pick --strategy resolve first..fourth >actual &&
99 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
100 test_i18ncmp expected actual.fuzzy
103 test_expect_success 'cherry-pick --ff first..fourth works' '
104 git checkout -f master &&
105 git reset --hard first &&
107 git cherry-pick --ff first..fourth &&
108 git diff --quiet other &&
109 git diff --quiet HEAD other &&
110 check_head_equals fourth
113 test_expect_success 'cherry-pick -n first..fourth works' '
114 git checkout -f master &&
115 git reset --hard first &&
117 git cherry-pick -n first..fourth &&
118 git diff --quiet other &&
119 git diff --cached --quiet other &&
120 git diff --quiet HEAD first
123 test_expect_success 'revert first..fourth works' '
124 git checkout -f master &&
125 git reset --hard fourth &&
127 git revert first..fourth &&
128 git diff --quiet first &&
129 git diff --cached --quiet first &&
130 git diff --quiet HEAD first
133 test_expect_success 'revert ^first fourth works' '
134 git checkout -f master &&
135 git reset --hard fourth &&
137 git revert ^first fourth &&
138 git diff --quiet first &&
139 git diff --cached --quiet first &&
140 git diff --quiet HEAD first
143 test_expect_success 'revert fourth fourth~1 fourth~2 works' '
144 git checkout -f master &&
145 git reset --hard fourth &&
147 git revert fourth fourth~1 fourth~2 &&
148 git diff --quiet first &&
149 git diff --cached --quiet first &&
150 git diff --quiet HEAD first
153 test_expect_success 'cherry-pick -3 fourth works' '
154 git checkout -f master &&
155 git reset --hard first &&
157 git cherry-pick -3 fourth &&
158 git diff --quiet other &&
159 git diff --quiet HEAD other &&
160 check_head_differs_from fourth
163 test_expect_success 'cherry-pick --stdin works' '
164 git checkout -f master &&
165 git reset --hard first &&
167 git rev-list --reverse first..fourth | git cherry-pick --stdin &&
168 git diff --quiet other &&
169 git diff --quiet HEAD other &&
170 check_head_differs_from fourth