lib-log-graph: move check_graph function
check_graph is a function shared in the test files t4215 and t6016 used to format the output graph, but instead of being in a file called by both test, the function code is repeated in each file. Move check_graph to lib-log-graph.sh file which both tests already import graph functions from, renaming it to lib_test_check_graph. This function is needed for the following commit which includes graph tests in a new file and requires check_graph. Mentored-by: Karthik Nayak <karthik.188@gmail.com> Mentored-by: Chandra Pratap <chandrapratap3519@gmail.com> Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pablo Sabater committed
Jul 14, 2026 at 14:09 UTC
641588bbcd1e80e084881d547e10aca8b32c328e
3 files changed
+29
-34
t/lib-log-graph.sh
+5
@@ -26,3 +26,8 @@ lib_test_cmp_colored_graph () {
26
test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors &&
27
test_cmp expect.colors output.colors
28
}
29
+
30
+lib_test_check_graph () {
31
+ cat >expect &&
32
+ lib_test_cmp_graph --format=%s "$@"
33
+}
t/t4215-log-skewed-merges.sh
+14
-19
@@ -5,11 +5,6 @@ test_description='git log --graph of skewed merges'
5
. ./test-lib.sh
6
. "$TEST_DIRECTORY"/lib-log-graph.sh
7
8
-check_graph () {
9
- cat >expect &&
10
- lib_test_cmp_graph --format=%s "$@"
11
-}
12
-
8
test_expect_success 'log --graph with merge fusing with its left and right neighbors' '
9
git checkout --orphan _p &&
10
test_commit A &&
@@ -21,7 +16,7 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh
16
git checkout _p && git merge --no-ff _r -m G &&
17
git checkout @^^ && git merge --no-ff _p -m H &&
18
24
- check_graph <<-\EOF
19
+ lib_test_check_graph <<-\EOF
20
* H
21
|\
22
| * G
@@ -49,7 +44,7 @@ test_expect_success 'log --graph with left-skewed merge' '
44
git checkout 0_p && git merge --no-ff 0_s -m 0_G &&
45
git checkout @^ && git merge --no-ff 0_q 0_r 0_t 0_p -m 0_H &&
46
52
- check_graph <<-\EOF
47
+ lib_test_check_graph <<-\EOF
48
*-----. 0_H
49
|\ \ \ \
50
| | | | * 0_G
@@ -83,7 +78,7 @@ test_expect_success 'log --graph with nested left-skewed merge' '
78
git checkout 1_p && git merge --no-ff 1_r -m 1_G &&
79
git checkout @^^ && git merge --no-ff 1_p -m 1_H &&
80
86
- check_graph <<-\EOF
81
+ lib_test_check_graph <<-\EOF
82
* 1_H
83
|\
84
| * 1_G
@@ -115,7 +110,7 @@ test_expect_success 'log --graph with nested left-skewed merge following normal
110
git checkout -b 2_s @^^ && git merge --no-ff 2_q -m 2_J &&
111
git checkout 2_p && git merge --no-ff 2_s -m 2_K &&
112
118
- check_graph <<-\EOF
113
+ lib_test_check_graph <<-\EOF
114
* 2_K
115
|\
116
| * 2_J
@@ -151,7 +146,7 @@ test_expect_success 'log --graph with nested right-skewed merge following left-s
146
git checkout 3_p && git merge --no-ff 3_r -m 3_H &&
147
git checkout @^^ && git merge --no-ff 3_p -m 3_J &&
148
154
- check_graph <<-\EOF
149
+ lib_test_check_graph <<-\EOF
150
* 3_J
151
|\
152
| * 3_H
@@ -182,7 +177,7 @@ test_expect_success 'log --graph with right-skewed merge following a left-skewed
177
git merge --no-ff 4_p -m 4_G &&
178
git checkout @^^ && git merge --no-ff 4_s -m 4_H &&
179
185
- check_graph --date-order <<-\EOF
180
+ lib_test_check_graph --date-order <<-\EOF
181
* 4_H
182
|\
183
| * 4_G
@@ -218,7 +213,7 @@ test_expect_success 'log --graph with octopus merge with column joining its penu
213
git checkout 5_r &&
214
git merge --no-ff 5_s -m 5_H &&
215
221
- check_graph <<-\EOF
216
+ lib_test_check_graph <<-\EOF
217
* 5_H
218
|\
219
| *-. 5_G
@@ -257,7 +252,7 @@ test_expect_success 'log --graph with multiple tips' '
252
git checkout 6_1 &&
253
git merge --no-ff 6_2 -m 6_I &&
254
260
- check_graph 6_1 6_3 6_5 <<-\EOF
255
+ lib_test_check_graph 6_1 6_3 6_5 <<-\EOF
256
* 6_I
257
|\
258
| | * 6_H
@@ -334,7 +329,7 @@ test_expect_success 'log --graph with multiple tips' '
329
git checkout -b M_7 7_1 &&
330
git merge --no-ff 7_2 7_3 -m 7_M4 &&
331
337
- check_graph M_1 M_3 M_5 M_7 <<-\EOF
332
+ lib_test_check_graph M_1 M_3 M_5 M_7 <<-\EOF
333
* 7_M1
334
|\
335
| | * 7_M2
@@ -371,7 +366,7 @@ test_expect_success 'log --graph with multiple tips' '
366
'
367
368
test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' '
374
- check_graph --graph-lane-limit=2 M_7 <<-\EOF
369
+ lib_test_check_graph --graph-lane-limit=2 M_7 <<-\EOF
370
*-. 7_M4
371
|\ \
372
| | * 7_G
@@ -388,7 +383,7 @@ test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' '
383
'
384
385
test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge' '
391
- check_graph --graph-lane-limit=1 M_7 <<-\EOF
386
+ lib_test_check_graph --graph-lane-limit=1 M_7 <<-\EOF
387
*-~ 7_M4
388
|\~
389
| ~ 7_G
@@ -405,7 +400,7 @@ test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge
400
'
401
402
test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' '
408
- check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF
403
+ lib_test_check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF
404
* 7_M1
405
|\
406
| | * 7_M2
@@ -441,7 +436,7 @@ test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' '
436
'
437
438
test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows first of 3 parent merge' '
444
- check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF
439
+ lib_test_check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF
440
* 7_M1
441
|\
442
| | * 7_M2
@@ -478,7 +473,7 @@ test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows fir
473
'
474
475
test_expect_success 'log --graph --graph-lane-limit=7 check if it shows all 3 parent merge' '
481
- check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF
476
+ lib_test_check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF
477
* 7_M1
478
|\
479
| | * 7_M2
t/t6016-rev-list-graph-simplify-history.sh
+10
-15
@@ -13,11 +13,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
13
. ./test-lib.sh
14
. "$TEST_DIRECTORY"/lib-log-graph.sh
15
16
-check_graph () {
17
- cat >expect &&
18
- lib_test_cmp_graph --format=%s "$@"
19
-}
20
-
16
test_expect_success 'set up rev-list --graph test' '
17
# 3 commits on branch A
18
test_commit A1 foo.txt &&
@@ -54,7 +49,7 @@ test_expect_success 'set up rev-list --graph test' '
49
'
50
51
test_expect_success '--graph --all' '
57
- check_graph --all <<-\EOF
52
+ lib_test_check_graph --all <<-\EOF
53
* A7
54
* A6
55
|\
@@ -82,7 +77,7 @@ test_expect_success '--graph --all' '
77
# that undecorated merges are interesting, even with --simplify-by-decoration
78
test_expect_success '--graph --simplify-by-decoration' '
79
git tag -d A4 &&
85
- check_graph --all --simplify-by-decoration <<-\EOF
80
+ lib_test_check_graph --all --simplify-by-decoration <<-\EOF
81
* A7
82
* A6
83
|\
@@ -114,7 +109,7 @@ test_expect_success 'setup: get rid of decorations on B' '
109
110
# Graph with branch B simplified away
111
test_expect_success '--graph --simplify-by-decoration prune branch B' '
117
- check_graph --simplify-by-decoration --all <<-\EOF
112
+ lib_test_check_graph --simplify-by-decoration --all <<-\EOF
113
* A7
114
* A6
115
|\
@@ -133,7 +128,7 @@ test_expect_success '--graph --simplify-by-decoration prune branch B' '
128
'
129
130
test_expect_success '--graph --full-history -- bar.txt' '
136
- check_graph --full-history --all -- bar.txt <<-\EOF
131
+ lib_test_check_graph --full-history --all -- bar.txt <<-\EOF
132
* A7
133
* A6
134
|\
@@ -148,7 +143,7 @@ test_expect_success '--graph --full-history -- bar.txt' '
143
'
144
145
test_expect_success '--graph --full-history --simplify-merges -- bar.txt' '
151
- check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF
146
+ lib_test_check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF
147
* A7
148
* A6
149
|\
@@ -161,7 +156,7 @@ test_expect_success '--graph --full-history --simplify-merges -- bar.txt' '
156
'
157
158
test_expect_success '--graph -- bar.txt' '
164
- check_graph --all -- bar.txt <<-\EOF
159
+ lib_test_check_graph --all -- bar.txt <<-\EOF
160
* A7
161
* A5
162
* A3
@@ -172,7 +167,7 @@ test_expect_success '--graph -- bar.txt' '
167
'
168
169
test_expect_success '--graph --sparse -- bar.txt' '
175
- check_graph --sparse --all -- bar.txt <<-\EOF
170
+ lib_test_check_graph --sparse --all -- bar.txt <<-\EOF
171
* A7
172
* A6
173
* A5
@@ -189,7 +184,7 @@ test_expect_success '--graph --sparse -- bar.txt' '
184
'
185
186
test_expect_success '--graph ^C4' '
192
- check_graph --all ^C4 <<-\EOF
187
+ lib_test_check_graph --all ^C4 <<-\EOF
188
* A7
189
* A6
190
* A5
@@ -202,7 +197,7 @@ test_expect_success '--graph ^C4' '
197
'
198
199
test_expect_success '--graph ^C3' '
205
- check_graph --all ^C3 <<-\EOF
200
+ lib_test_check_graph --all ^C3 <<-\EOF
201
* A7
202
* A6
203
|\
@@ -220,7 +215,7 @@ test_expect_success '--graph ^C3' '
215
# that important, but this test depends on it. If the ordering ever changes
216
# in the code, we'll need to update this test.
217
test_expect_success '--graph --boundary ^C3' '
223
- check_graph --boundary --all ^C3 <<-\EOF
218
+ lib_test_check_graph --boundary --all ^C3 <<-\EOF
219
* A7
220
* A6
221
|\