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 &&
39 Finished cherry-pick of commit $(git rev-parse --short second).
40 Finished cherry-pick of commit $(git rev-parse --short third).
41 Finished cherry-pick of commit $(git rev-parse --short fourth).
44 git checkout -f master &&
45 git reset --hard first &&
47 git cherry-pick first..fourth 2>actual &&
48 git diff --quiet other &&
49 git diff --quiet HEAD other &&
50 test_cmp expected actual &&
51 check_head_differs_from fourth
54 test_expect_success
'cherry-pick --strategy resolve first..fourth works' '
55 cat <<-EOF >expected &&
56 Finished cherry-pick of commit $(git rev-parse --short second) with strategy resolve.
57 Finished cherry-pick of commit $(git rev-parse --short third) with strategy resolve.
58 Finished cherry-pick of commit $(git rev-parse --short fourth) with strategy resolve.
61 git checkout -f master &&
62 git reset --hard first &&
64 git cherry-pick --strategy resolve first..fourth 2>actual &&
65 git diff --quiet other &&
66 git diff --quiet HEAD other &&
67 test_cmp expected actual &&
68 check_head_differs_from fourth
71 test_expect_success
'cherry-pick --ff first..fourth works' '
72 git checkout -f master &&
73 git reset --hard first &&
75 git cherry-pick --ff first..fourth &&
76 git diff --quiet other &&
77 git diff --quiet HEAD other &&
78 check_head_equals fourth
81 test_expect_success
'cherry-pick -n first..fourth works' '
82 git checkout -f master &&
83 git reset --hard first &&
85 git cherry-pick -n first..fourth &&
86 git diff --quiet other &&
87 git diff --cached --quiet other &&
88 git diff --quiet HEAD first
91 test_expect_success
'revert first..fourth works' '
92 git checkout -f master &&
93 git reset --hard fourth &&
95 git revert first..fourth &&
96 git diff --quiet first &&
97 git diff --cached --quiet first &&
98 git diff --quiet HEAD first
101 test_expect_success
'revert ^first fourth works' '
102 git checkout -f master &&
103 git reset --hard fourth &&
105 git revert ^first fourth &&
106 git diff --quiet first &&
107 git diff --cached --quiet first &&
108 git diff --quiet HEAD first
111 test_expect_success
'revert fourth fourth~1 fourth~2 works' '
112 git checkout -f master &&
113 git reset --hard fourth &&
115 git revert fourth fourth~1 fourth~2 &&
116 git diff --quiet first &&
117 git diff --cached --quiet first &&
118 git diff --quiet HEAD first
121 test_expect_success
'cherry-pick -3 fourth works' '
122 git checkout -f master &&
123 git reset --hard first &&
125 git cherry-pick -3 fourth &&
126 git diff --quiet other &&
127 git diff --quiet HEAD other &&
128 check_head_differs_from fourth
131 test_expect_success
'cherry-pick --stdin works' '
132 git checkout -f master &&
133 git reset --hard first &&
135 git rev-list --reverse first..fourth | git cherry-pick --stdin &&
136 git diff --quiet other &&
137 git diff --quiet HEAD other &&
138 check_head_differs_from fourth