]>
Commit | Line | Data |
---|---|---|
aa29ccf4 CC |
1 | #!/bin/sh |
2 | ||
3 | test_description='test cherry-picking many commits' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
6bc83cdd CC |
7 | check_head_differs_from() { |
8 | head=$(git rev-parse --verify HEAD) && | |
9 | arg=$(git rev-parse --verify "$1") && | |
10 | test "$head" != "$arg" | |
11 | } | |
12 | ||
13 | check_head_equals() { | |
14 | head=$(git rev-parse --verify HEAD) && | |
15 | arg=$(git rev-parse --verify "$1") && | |
16 | test "$head" = "$arg" | |
17 | } | |
18 | ||
aa29ccf4 CC |
19 | test_expect_success setup ' |
20 | echo first > file1 && | |
21 | git add file1 && | |
22 | test_tick && | |
23 | git commit -m "first" && | |
24 | git tag first && | |
25 | ||
26 | git checkout -b other && | |
27 | for val in second third fourth | |
28 | do | |
29 | echo $val >> file1 && | |
30 | git add file1 && | |
31 | test_tick && | |
32 | git commit -m "$val" && | |
33 | git tag $val | |
34 | done | |
35 | ' | |
36 | ||
37 | test_expect_success 'cherry-pick first..fourth works' ' | |
130ab8ab JN |
38 | cat <<-\EOF >expected && |
39 | [master OBJID] second | |
40 | Author: A U Thor <author@example.com> | |
41 | 1 files changed, 1 insertions(+), 0 deletions(-) | |
42 | [master OBJID] third | |
43 | Author: A U Thor <author@example.com> | |
44 | 1 files changed, 1 insertions(+), 0 deletions(-) | |
45 | [master OBJID] fourth | |
46 | Author: A U Thor <author@example.com> | |
47 | 1 files changed, 1 insertions(+), 0 deletions(-) | |
7b53b92f CC |
48 | EOF |
49 | ||
50 | git checkout -f master && | |
51 | git reset --hard first && | |
52 | test_tick && | |
130ab8ab | 53 | git cherry-pick first..fourth >actual && |
7b53b92f CC |
54 | git diff --quiet other && |
55 | git diff --quiet HEAD other && | |
130ab8ab JN |
56 | |
57 | sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy && | |
58 | test_cmp expected actual.fuzzy && | |
6bc83cdd | 59 | check_head_differs_from fourth |
7b53b92f CC |
60 | ' |
61 | ||
62 | test_expect_success 'cherry-pick --strategy resolve first..fourth works' ' | |
130ab8ab JN |
63 | cat <<-\EOF >expected && |
64 | Trying simple merge. | |
65 | [master OBJID] second | |
66 | Author: A U Thor <author@example.com> | |
67 | 1 files changed, 1 insertions(+), 0 deletions(-) | |
68 | Trying simple merge. | |
69 | [master OBJID] third | |
70 | Author: A U Thor <author@example.com> | |
71 | 1 files changed, 1 insertions(+), 0 deletions(-) | |
72 | Trying simple merge. | |
73 | [master OBJID] fourth | |
74 | Author: A U Thor <author@example.com> | |
75 | 1 files changed, 1 insertions(+), 0 deletions(-) | |
7b53b92f CC |
76 | EOF |
77 | ||
18c8ff46 | 78 | git checkout -f master && |
aa29ccf4 CC |
79 | git reset --hard first && |
80 | test_tick && | |
130ab8ab | 81 | git cherry-pick --strategy resolve first..fourth >actual && |
aa29ccf4 CC |
82 | git diff --quiet other && |
83 | git diff --quiet HEAD other && | |
130ab8ab JN |
84 | sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy && |
85 | test_cmp expected actual.fuzzy && | |
6bc83cdd | 86 | check_head_differs_from fourth |
aa29ccf4 CC |
87 | ' |
88 | ||
89 | test_expect_success 'cherry-pick --ff first..fourth works' ' | |
18c8ff46 | 90 | git checkout -f master && |
aa29ccf4 CC |
91 | git reset --hard first && |
92 | test_tick && | |
93 | git cherry-pick --ff first..fourth && | |
94 | git diff --quiet other && | |
95 | git diff --quiet HEAD other && | |
6bc83cdd | 96 | check_head_equals fourth |
aa29ccf4 CC |
97 | ' |
98 | ||
99 | test_expect_success 'cherry-pick -n first..fourth works' ' | |
18c8ff46 | 100 | git checkout -f master && |
aa29ccf4 CC |
101 | git reset --hard first && |
102 | test_tick && | |
103 | git cherry-pick -n first..fourth && | |
104 | git diff --quiet other && | |
105 | git diff --cached --quiet other && | |
106 | git diff --quiet HEAD first | |
107 | ' | |
108 | ||
109 | test_expect_success 'revert first..fourth works' ' | |
18c8ff46 | 110 | git checkout -f master && |
aa29ccf4 CC |
111 | git reset --hard fourth && |
112 | test_tick && | |
113 | git revert first..fourth && | |
114 | git diff --quiet first && | |
115 | git diff --cached --quiet first && | |
116 | git diff --quiet HEAD first | |
117 | ' | |
118 | ||
119 | test_expect_success 'revert ^first fourth works' ' | |
18c8ff46 | 120 | git checkout -f master && |
aa29ccf4 CC |
121 | git reset --hard fourth && |
122 | test_tick && | |
123 | git revert ^first fourth && | |
124 | git diff --quiet first && | |
125 | git diff --cached --quiet first && | |
126 | git diff --quiet HEAD first | |
127 | ' | |
128 | ||
129 | test_expect_success 'revert fourth fourth~1 fourth~2 works' ' | |
18c8ff46 | 130 | git checkout -f master && |
aa29ccf4 CC |
131 | git reset --hard fourth && |
132 | test_tick && | |
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 | |
137 | ' | |
138 | ||
65281b70 | 139 | test_expect_success 'cherry-pick -3 fourth works' ' |
18c8ff46 | 140 | git checkout -f master && |
aa29ccf4 CC |
141 | git reset --hard first && |
142 | test_tick && | |
143 | git cherry-pick -3 fourth && | |
144 | git diff --quiet other && | |
145 | git diff --quiet HEAD other && | |
6bc83cdd | 146 | check_head_differs_from fourth |
aa29ccf4 CC |
147 | ' |
148 | ||
f873a273 CC |
149 | test_expect_success 'cherry-pick --stdin works' ' |
150 | git checkout -f master && | |
151 | git reset --hard first && | |
152 | test_tick && | |
153 | git rev-list --reverse first..fourth | git cherry-pick --stdin && | |
154 | git diff --quiet other && | |
155 | git diff --quiet HEAD other && | |
6bc83cdd | 156 | check_head_differs_from fourth |
f873a273 CC |
157 | ' |
158 | ||
aa29ccf4 | 159 | test_done |