lib-log-graph: consolidate test_cmp_graph logic
[git] / t / t4214-log-graph-octopus.sh
1 #!/bin/sh
2
3 test_description='git log --graph of skewed left octopus merge.'
4
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/lib-log-graph.sh
7
8 test_cmp_graph () {
9         cat >expect &&
10         lib_test_cmp_graph --color=never --date-order --format=%s "$@"
11 }
12
13 test_expect_success 'set up merge history' '
14         test_commit initial &&
15         for i in 1 2 3 4 ; do
16                 git checkout master -b $i || return $?
17                 # Make tag name different from branch name, to avoid
18                 # ambiguity error when calling checkout.
19                 test_commit $i $i $i tag$i || return $?
20         done &&
21         git checkout 1 -b merge &&
22         test_merge octopus-merge 1 2 3 4 &&
23         test_commit after-merge &&
24         git checkout 1 -b L &&
25         test_commit left &&
26         git checkout 4 -b crossover &&
27         test_commit after-4 &&
28         git checkout initial -b more-L &&
29         test_commit after-initial
30 '
31
32 test_expect_success 'log --graph with tricky octopus merge, no color' '
33         test_cmp_graph left octopus-merge <<-\EOF
34         * left
35         | *-.   octopus-merge
36         |/|\ \
37         | | | * 4
38         | | * | 3
39         | | |/
40         | * / 2
41         | |/
42         * / 1
43         |/
44         * initial
45         EOF
46 '
47
48 test_expect_success 'log --graph with tricky octopus merge with colors' '
49         test_config log.graphColors red,green,yellow,blue,magenta,cyan &&
50         cat >expect.colors <<-\EOF &&
51         * left
52         <RED>|<RESET> *<MAGENTA>-<RESET><MAGENTA>.<RESET>   octopus-merge
53         <RED>|<RESET><RED>/<RESET><YELLOW>|<RESET><BLUE>\<RESET> <MAGENTA>\<RESET>
54         <RED>|<RESET> <YELLOW>|<RESET> <BLUE>|<RESET> * 4
55         <RED>|<RESET> <YELLOW>|<RESET> * <MAGENTA>|<RESET> 3
56         <RED>|<RESET> <YELLOW>|<RESET> <MAGENTA>|<RESET><MAGENTA>/<RESET>
57         <RED>|<RESET> * <MAGENTA>/<RESET> 2
58         <RED>|<RESET> <MAGENTA>|<RESET><MAGENTA>/<RESET>
59         * <MAGENTA>/<RESET> 1
60         <MAGENTA>|<RESET><MAGENTA>/<RESET>
61         * initial
62         EOF
63         git log --color=always --graph --date-order --pretty=tformat:%s left octopus-merge >actual.colors.raw &&
64         test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors &&
65         test_cmp expect.colors actual.colors
66 '
67
68 # Repeat the previous two tests with "normal" octopus merge (i.e.,
69 # without the first parent skewing to the "left" branch column).
70
71 test_expect_success 'log --graph with normal octopus merge, no color' '
72         test_cmp_graph octopus-merge <<-\EOF
73         *---.   octopus-merge
74         |\ \ \
75         | | | * 4
76         | | * | 3
77         | | |/
78         | * / 2
79         | |/
80         * / 1
81         |/
82         * initial
83         EOF
84 '
85
86 test_expect_success 'log --graph with normal octopus merge with colors' '
87         cat >expect.colors <<-\EOF &&
88         *<YELLOW>-<RESET><YELLOW>-<RESET><BLUE>-<RESET><BLUE>.<RESET>   octopus-merge
89         <RED>|<RESET><GREEN>\<RESET> <YELLOW>\<RESET> <BLUE>\<RESET>
90         <RED>|<RESET> <GREEN>|<RESET> <YELLOW>|<RESET> * 4
91         <RED>|<RESET> <GREEN>|<RESET> * <BLUE>|<RESET> 3
92         <RED>|<RESET> <GREEN>|<RESET> <BLUE>|<RESET><BLUE>/<RESET>
93         <RED>|<RESET> * <BLUE>/<RESET> 2
94         <RED>|<RESET> <BLUE>|<RESET><BLUE>/<RESET>
95         * <BLUE>/<RESET> 1
96         <BLUE>|<RESET><BLUE>/<RESET>
97         * initial
98         EOF
99         test_config log.graphColors red,green,yellow,blue,magenta,cyan &&
100         git log --color=always --graph --date-order --pretty=tformat:%s octopus-merge >actual.colors.raw &&
101         test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors &&
102         test_cmp expect.colors actual.colors
103 '
104
105 test_expect_success 'log --graph with normal octopus merge and child, no color' '
106         test_cmp_graph after-merge <<-\EOF
107         * after-merge
108         *---.   octopus-merge
109         |\ \ \
110         | | | * 4
111         | | * | 3
112         | | |/
113         | * / 2
114         | |/
115         * / 1
116         |/
117         * initial
118         EOF
119 '
120
121 test_expect_success 'log --graph with normal octopus and child merge with colors' '
122         cat >expect.colors <<-\EOF &&
123         * after-merge
124         *<BLUE>-<RESET><BLUE>-<RESET><MAGENTA>-<RESET><MAGENTA>.<RESET>   octopus-merge
125         <GREEN>|<RESET><YELLOW>\<RESET> <BLUE>\<RESET> <MAGENTA>\<RESET>
126         <GREEN>|<RESET> <YELLOW>|<RESET> <BLUE>|<RESET> * 4
127         <GREEN>|<RESET> <YELLOW>|<RESET> * <MAGENTA>|<RESET> 3
128         <GREEN>|<RESET> <YELLOW>|<RESET> <MAGENTA>|<RESET><MAGENTA>/<RESET>
129         <GREEN>|<RESET> * <MAGENTA>/<RESET> 2
130         <GREEN>|<RESET> <MAGENTA>|<RESET><MAGENTA>/<RESET>
131         * <MAGENTA>/<RESET> 1
132         <MAGENTA>|<RESET><MAGENTA>/<RESET>
133         * initial
134         EOF
135         test_config log.graphColors red,green,yellow,blue,magenta,cyan &&
136         git log --color=always --graph --date-order --pretty=tformat:%s after-merge >actual.colors.raw &&
137         test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors &&
138         test_cmp expect.colors actual.colors
139 '
140
141 test_expect_success 'log --graph with tricky octopus merge and its child, no color' '
142         test_cmp_graph left after-merge <<-\EOF
143         * left
144         | * after-merge
145         | *-.   octopus-merge
146         |/|\ \
147         | | | * 4
148         | | * | 3
149         | | |/
150         | * / 2
151         | |/
152         * / 1
153         |/
154         * initial
155         EOF
156 '
157
158 test_expect_success 'log --graph with tricky octopus merge and its child with colors' '
159         test_config log.graphColors red,green,yellow,blue,magenta,cyan &&
160         cat >expect.colors <<-\EOF &&
161         * left
162         <RED>|<RESET> * after-merge
163         <RED>|<RESET> *<CYAN>-<RESET><CYAN>.<RESET>   octopus-merge
164         <RED>|<RESET><RED>/<RESET><BLUE>|<RESET><MAGENTA>\<RESET> <CYAN>\<RESET>
165         <RED>|<RESET> <BLUE>|<RESET> <MAGENTA>|<RESET> * 4
166         <RED>|<RESET> <BLUE>|<RESET> * <CYAN>|<RESET> 3
167         <RED>|<RESET> <BLUE>|<RESET> <CYAN>|<RESET><CYAN>/<RESET>
168         <RED>|<RESET> * <CYAN>/<RESET> 2
169         <RED>|<RESET> <CYAN>|<RESET><CYAN>/<RESET>
170         * <CYAN>/<RESET> 1
171         <CYAN>|<RESET><CYAN>/<RESET>
172         * initial
173         EOF
174         git log --color=always --graph --date-order --pretty=tformat:%s left after-merge >actual.colors.raw &&
175         test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors &&
176         test_cmp expect.colors actual.colors
177 '
178
179 test_expect_success 'log --graph with crossover in octopus merge, no color' '
180         test_cmp_graph after-4 octopus-merge <<-\EOF
181         * after-4
182         | *---.   octopus-merge
183         | |\ \ \
184         | |_|_|/
185         |/| | |
186         * | | | 4
187         | | | * 3
188         | |_|/
189         |/| |
190         | | * 2
191         | |/
192         |/|
193         | * 1
194         |/
195         * initial
196         EOF
197 '
198
199 test_expect_success 'log --graph with crossover in octopus merge with colors' '
200         test_config log.graphColors red,green,yellow,blue,magenta,cyan &&
201         cat >expect.colors <<-\EOF &&
202         * after-4
203         <RED>|<RESET> *<BLUE>-<RESET><BLUE>-<RESET><RED>-<RESET><RED>.<RESET>   octopus-merge
204         <RED>|<RESET> <GREEN>|<RESET><YELLOW>\<RESET> <BLUE>\<RESET> <RED>\<RESET>
205         <RED>|<RESET> <GREEN>|<RESET><RED>_<RESET><YELLOW>|<RESET><RED>_<RESET><BLUE>|<RESET><RED>/<RESET>
206         <RED>|<RESET><RED>/<RESET><GREEN>|<RESET> <YELLOW>|<RESET> <BLUE>|<RESET>
207         * <GREEN>|<RESET> <YELLOW>|<RESET> <BLUE>|<RESET> 4
208         <MAGENTA>|<RESET> <GREEN>|<RESET> <YELLOW>|<RESET> * 3
209         <MAGENTA>|<RESET> <GREEN>|<RESET><MAGENTA>_<RESET><YELLOW>|<RESET><MAGENTA>/<RESET>
210         <MAGENTA>|<RESET><MAGENTA>/<RESET><GREEN>|<RESET> <YELLOW>|<RESET>
211         <MAGENTA>|<RESET> <GREEN>|<RESET> * 2
212         <MAGENTA>|<RESET> <GREEN>|<RESET><MAGENTA>/<RESET>
213         <MAGENTA>|<RESET><MAGENTA>/<RESET><GREEN>|<RESET>
214         <MAGENTA>|<RESET> * 1
215         <MAGENTA>|<RESET><MAGENTA>/<RESET>
216         * initial
217         EOF
218         git log --color=always --graph --date-order --pretty=tformat:%s after-4 octopus-merge >actual.colors.raw &&
219         test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors &&
220         test_cmp expect.colors actual.colors
221 '
222
223 test_expect_success 'log --graph with crossover in octopus merge and its child, no color' '
224         test_cmp_graph after-4 after-merge <<-\EOF
225         * after-4
226         | * after-merge
227         | *---.   octopus-merge
228         | |\ \ \
229         | |_|_|/
230         |/| | |
231         * | | | 4
232         | | | * 3
233         | |_|/
234         |/| |
235         | | * 2
236         | |/
237         |/|
238         | * 1
239         |/
240         * initial
241         EOF
242 '
243
244 test_expect_success 'log --graph with crossover in octopus merge and its child with colors' '
245         test_config log.graphColors red,green,yellow,blue,magenta,cyan &&
246         cat >expect.colors <<-\EOF &&
247         * after-4
248         <RED>|<RESET> * after-merge
249         <RED>|<RESET> *<MAGENTA>-<RESET><MAGENTA>-<RESET><RED>-<RESET><RED>.<RESET>   octopus-merge
250         <RED>|<RESET> <YELLOW>|<RESET><BLUE>\<RESET> <MAGENTA>\<RESET> <RED>\<RESET>
251         <RED>|<RESET> <YELLOW>|<RESET><RED>_<RESET><BLUE>|<RESET><RED>_<RESET><MAGENTA>|<RESET><RED>/<RESET>
252         <RED>|<RESET><RED>/<RESET><YELLOW>|<RESET> <BLUE>|<RESET> <MAGENTA>|<RESET>
253         * <YELLOW>|<RESET> <BLUE>|<RESET> <MAGENTA>|<RESET> 4
254         <CYAN>|<RESET> <YELLOW>|<RESET> <BLUE>|<RESET> * 3
255         <CYAN>|<RESET> <YELLOW>|<RESET><CYAN>_<RESET><BLUE>|<RESET><CYAN>/<RESET>
256         <CYAN>|<RESET><CYAN>/<RESET><YELLOW>|<RESET> <BLUE>|<RESET>
257         <CYAN>|<RESET> <YELLOW>|<RESET> * 2
258         <CYAN>|<RESET> <YELLOW>|<RESET><CYAN>/<RESET>
259         <CYAN>|<RESET><CYAN>/<RESET><YELLOW>|<RESET>
260         <CYAN>|<RESET> * 1
261         <CYAN>|<RESET><CYAN>/<RESET>
262         * initial
263         EOF
264         git log --color=always --graph --date-order --pretty=tformat:%s after-4 after-merge >actual.colors.raw &&
265         test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors &&
266         test_cmp expect.colors actual.colors
267 '
268
269 test_expect_success 'log --graph with unrelated commit and octopus tip, no color' '
270         test_cmp_graph after-initial octopus-merge <<-\EOF
271         * after-initial
272         | *---.   octopus-merge
273         | |\ \ \
274         | | | | * 4
275         | |_|_|/
276         |/| | |
277         | | | * 3
278         | |_|/
279         |/| |
280         | | * 2
281         | |/
282         |/|
283         | * 1
284         |/
285         * initial
286         EOF
287 '
288
289 test_expect_success 'log --graph with unrelated commit and octopus tip with colors' '
290         test_config log.graphColors red,green,yellow,blue,magenta,cyan &&
291         cat >expect.colors <<-\EOF &&
292         * after-initial
293         <RED>|<RESET> *<BLUE>-<RESET><BLUE>-<RESET><MAGENTA>-<RESET><MAGENTA>.<RESET>   octopus-merge
294         <RED>|<RESET> <GREEN>|<RESET><YELLOW>\<RESET> <BLUE>\<RESET> <MAGENTA>\<RESET>
295         <RED>|<RESET> <GREEN>|<RESET> <YELLOW>|<RESET> <BLUE>|<RESET> * 4
296         <RED>|<RESET> <GREEN>|<RESET><RED>_<RESET><YELLOW>|<RESET><RED>_<RESET><BLUE>|<RESET><RED>/<RESET>
297         <RED>|<RESET><RED>/<RESET><GREEN>|<RESET> <YELLOW>|<RESET> <BLUE>|<RESET>
298         <RED>|<RESET> <GREEN>|<RESET> <YELLOW>|<RESET> * 3
299         <RED>|<RESET> <GREEN>|<RESET><RED>_<RESET><YELLOW>|<RESET><RED>/<RESET>
300         <RED>|<RESET><RED>/<RESET><GREEN>|<RESET> <YELLOW>|<RESET>
301         <RED>|<RESET> <GREEN>|<RESET> * 2
302         <RED>|<RESET> <GREEN>|<RESET><RED>/<RESET>
303         <RED>|<RESET><RED>/<RESET><GREEN>|<RESET>
304         <RED>|<RESET> * 1
305         <RED>|<RESET><RED>/<RESET>
306         * initial
307         EOF
308         git log --color=always --graph --date-order --pretty=tformat:%s after-initial octopus-merge >actual.colors.raw &&
309         test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors &&
310         test_cmp expect.colors actual.colors
311 '
312
313 test_expect_success 'log --graph with unrelated commit and octopus child, no color' '
314         test_cmp_graph after-initial after-merge <<-\EOF
315         * after-initial
316         | * after-merge
317         | *---.   octopus-merge
318         | |\ \ \
319         | | | | * 4
320         | |_|_|/
321         |/| | |
322         | | | * 3
323         | |_|/
324         |/| |
325         | | * 2
326         | |/
327         |/|
328         | * 1
329         |/
330         * initial
331         EOF
332 '
333
334 test_expect_success 'log --graph with unrelated commit and octopus child with colors' '
335         test_config log.graphColors red,green,yellow,blue,magenta,cyan &&
336         cat >expect.colors <<-\EOF &&
337         * after-initial
338         <RED>|<RESET> * after-merge
339         <RED>|<RESET> *<MAGENTA>-<RESET><MAGENTA>-<RESET><CYAN>-<RESET><CYAN>.<RESET>   octopus-merge
340         <RED>|<RESET> <YELLOW>|<RESET><BLUE>\<RESET> <MAGENTA>\<RESET> <CYAN>\<RESET>
341         <RED>|<RESET> <YELLOW>|<RESET> <BLUE>|<RESET> <MAGENTA>|<RESET> * 4
342         <RED>|<RESET> <YELLOW>|<RESET><RED>_<RESET><BLUE>|<RESET><RED>_<RESET><MAGENTA>|<RESET><RED>/<RESET>
343         <RED>|<RESET><RED>/<RESET><YELLOW>|<RESET> <BLUE>|<RESET> <MAGENTA>|<RESET>
344         <RED>|<RESET> <YELLOW>|<RESET> <BLUE>|<RESET> * 3
345         <RED>|<RESET> <YELLOW>|<RESET><RED>_<RESET><BLUE>|<RESET><RED>/<RESET>
346         <RED>|<RESET><RED>/<RESET><YELLOW>|<RESET> <BLUE>|<RESET>
347         <RED>|<RESET> <YELLOW>|<RESET> * 2
348         <RED>|<RESET> <YELLOW>|<RESET><RED>/<RESET>
349         <RED>|<RESET><RED>/<RESET><YELLOW>|<RESET>
350         <RED>|<RESET> * 1
351         <RED>|<RESET><RED>/<RESET>
352         * initial
353         EOF
354         git log --color=always --graph --date-order --pretty=tformat:%s after-initial after-merge >actual.colors.raw &&
355         test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors &&
356         test_cmp expect.colors actual.colors
357 '
358
359 test_done