Merge branch 'hv/submodule-path-unmatch'
[git/mingw.git] / t / t3508-cherry-pick-many-commits.sh
blob75f7ff4f2fe21e86e0a26fe5a6c2119bef38404c
1 #!/bin/sh
3 test_description='test cherry-picking many commits'
5 . ./test-lib.sh
7 check_head_differs_from() {
8 head=$(git rev-parse --verify HEAD) &&
9 arg=$(git rev-parse --verify "$1") &&
10 test "$head" != "$arg"
13 check_head_equals() {
14 head=$(git rev-parse --verify HEAD) &&
15 arg=$(git rev-parse --verify "$1") &&
16 test "$head" = "$arg"
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 &&
26 git checkout -b other &&
27 for val in second third fourth
29 echo $val >> file1 &&
30 git add file1 &&
31 test_tick &&
32 git commit -m "$val" &&
33 git tag $val
34 done
37 test_expect_success 'cherry-pick first..fourth works' '
38 git checkout -f master &&
39 git reset --hard first &&
40 test_tick &&
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 &&
49 [master OBJID] second
50 Author: A U Thor <author@example.com>
51 1 file changed, 1 insertion(+)
52 [master OBJID] third
53 Author: A U Thor <author@example.com>
54 1 file changed, 1 insertion(+)
55 [master OBJID] fourth
56 Author: A U Thor <author@example.com>
57 1 file changed, 1 insertion(+)
58 EOF
60 git checkout -f master &&
61 git reset --hard first &&
62 test_tick &&
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 &&
72 test_tick &&
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 &&
81 Trying simple merge.
82 [master OBJID] second
83 Author: A U Thor <author@example.com>
84 1 file changed, 1 insertion(+)
85 Trying simple merge.
86 [master OBJID] third
87 Author: A U Thor <author@example.com>
88 1 file changed, 1 insertion(+)
89 Trying simple merge.
90 [master OBJID] fourth
91 Author: A U Thor <author@example.com>
92 1 file changed, 1 insertion(+)
93 EOF
95 git checkout -f master &&
96 git reset --hard first &&
97 test_tick &&
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 &&
106 test_tick &&
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 &&
116 test_tick &&
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 &&
126 test_tick &&
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 &&
136 test_tick &&
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 &&
146 test_tick &&
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 &&
156 test_tick &&
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 &&
166 test_tick &&
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
173 test_done