1 #!/bin/sh
2 #
3 # Copyright (c) 2025 Google LLC
4 #
5
6 test_description=':(optional) paths'
7
8 . ./test-lib.sh
9
10 test_expect_success 'var=:(optional)path-exists' '
11 test_config a.path ":(optional)path-exists" &&
12 >path-exists &&
13 echo path-exists >expect &&
14
15 git config get --path a.path >actual &&
16 test_cmp expect actual
17 '
18
19 test_expect_success 'missing optional value is ignored' '
20 test_config a.path ":(optional)no-such-path" &&
21 # Using --show-scope ensures we skip writing not only the value
22 # but also any meta-information about the ignored key.
23 test_must_fail git config get --show-scope --path a.path >actual &&
24 test_line_count = 0 actual
25 '
26
27 test_expect_success 'missing optional value is ignored in multi-value config' '
28 test_when_finished "git config unset --all a.path" &&
29 git config set --append a.path ":(optional)path-exists" &&
30 git config set --append a.path ":(optional)no-such-path" &&
31 >path-exists &&
32 echo path-exists >expect &&
33
34 git config --get --path a.path >actual &&
35 test_cmp expect actual
36 '
37
38 test_done