tests: modernise style: more uses of test_line_count
[alt-git.git] / t / t3508-cherry-pick-many-commits.sh
blob1b3a344158aa8077c1e5b47f9ab8bd6394e153ed
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 cat <<-\EOF >expected &&
39 [master OBJID] second
40 Author: A U Thor <author@example.com>
41 1 file changed, 1 insertion(+)
42 [master OBJID] third
43 Author: A U Thor <author@example.com>
44 1 file changed, 1 insertion(+)
45 [master OBJID] fourth
46 Author: A U Thor <author@example.com>
47 1 file changed, 1 insertion(+)
48 EOF
50 git checkout -f master &&
51 git reset --hard first &&
52 test_tick &&
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 &&
64 Trying simple merge.
65 [master OBJID] second
66 Author: A U Thor <author@example.com>
67 1 file changed, 1 insertion(+)
68 Trying simple merge.
69 [master OBJID] third
70 Author: A U Thor <author@example.com>
71 1 file changed, 1 insertion(+)
72 Trying simple merge.
73 [master OBJID] fourth
74 Author: A U Thor <author@example.com>
75 1 file changed, 1 insertion(+)
76 EOF
78 git checkout -f master &&
79 git reset --hard first &&
80 test_tick &&
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 &&
92 test_tick &&
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 &&
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
109 test_expect_success 'revert first..fourth works' '
110 git checkout -f master &&
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
119 test_expect_success 'revert ^first fourth works' '
120 git checkout -f master &&
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
129 test_expect_success 'revert fourth fourth~1 fourth~2 works' '
130 git checkout -f master &&
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
139 test_expect_success 'cherry-pick -3 fourth works' '
140 git checkout -f master &&
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 &&
146 check_head_differs_from fourth
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 &&
156 check_head_differs_from fourth
159 test_done