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 cat <<-\EOF >expected &&
40 Author: A U Thor <author@example.com>
41 1 file changed, 1 insertion(+)
43 Author: A U Thor <author@example.com>
44 1 file changed, 1 insertion(+)
46 Author: A U Thor <author@example.com>
47 1 file changed, 1 insertion(+)
50 git checkout -f master &&
51 git reset --hard first &&
53 git cherry-pick first..fourth >actual &&
54 git diff --quiet other &&
55 git diff --quiet HEAD other &&
57 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
58 test_cmp expected actual.fuzzy &&
59 check_head_differs_from fourth
62 test_expect_success
'cherry-pick --strategy resolve first..fourth works' '
63 cat <<-\EOF >expected &&
66 Author: A U Thor <author@example.com>
67 1 file changed, 1 insertion(+)
70 Author: A U Thor <author@example.com>
71 1 file changed, 1 insertion(+)
74 Author: A U Thor <author@example.com>
75 1 file changed, 1 insertion(+)
78 git checkout -f master &&
79 git reset --hard first &&
81 git cherry-pick --strategy resolve first..fourth >actual &&
82 git diff --quiet other &&
83 git diff --quiet HEAD other &&
84 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
85 test_cmp expected actual.fuzzy &&
86 check_head_differs_from fourth
89 test_expect_success
'cherry-pick --ff first..fourth works' '
90 git checkout -f master &&
91 git reset --hard first &&
93 git cherry-pick --ff first..fourth &&
94 git diff --quiet other &&
95 git diff --quiet HEAD other &&
96 check_head_equals fourth
99 test_expect_success
'cherry-pick -n first..fourth works' '
100 git checkout -f master &&
101 git reset --hard first &&
103 git cherry-pick -n first..fourth &&
104 git diff --quiet other &&
105 git diff --cached --quiet other &&
106 git diff --quiet HEAD first
109 test_expect_success
'revert first..fourth works' '
110 git checkout -f master &&
111 git reset --hard fourth &&
113 git revert first..fourth &&
114 git diff --quiet first &&
115 git diff --cached --quiet first &&
116 git diff --quiet HEAD first
119 test_expect_success
'revert ^first fourth works' '
120 git checkout -f master &&
121 git reset --hard fourth &&
123 git revert ^first fourth &&
124 git diff --quiet first &&
125 git diff --cached --quiet first &&
126 git diff --quiet HEAD first
129 test_expect_success
'revert fourth fourth~1 fourth~2 works' '
130 git checkout -f master &&
131 git reset --hard fourth &&
133 git revert fourth fourth~1 fourth~2 &&
134 git diff --quiet first &&
135 git diff --cached --quiet first &&
136 git diff --quiet HEAD first
139 test_expect_success
'cherry-pick -3 fourth works' '
140 git checkout -f master &&
141 git reset --hard first &&
143 git cherry-pick -3 fourth &&
144 git diff --quiet other &&
145 git diff --quiet HEAD other &&
146 check_head_differs_from fourth
149 test_expect_success
'cherry-pick --stdin works' '
150 git checkout -f master &&
151 git reset --hard first &&
153 git rev-list --reverse first..fourth | git cherry-pick --stdin &&
154 git diff --quiet other &&
155 git diff --quiet HEAD other &&
156 check_head_differs_from fourth