11
TEST_PASSES_SANITIZE_LEAK=true
12
. ./test-lib.sh
13
14
+for mode in legacy subcommands
15
+do
16
+
17
+case "$mode" in
18
+legacy)
19
+ mode_prefix="--"
20
+ ;;
21
+subcommands)
22
+ mode_prefix=""
23
+ ;;
24
+*)
25
+ BUG "unknown mode $mode";;
26
+esac
27
+
28
test_expect_success 'setup whitespace config' '
29
sed -e "s/^|//" \
30
-e "s/[$]$//" \
474
EOF
475
476
test_expect_success 'working --list' '
463
- git config --list > output &&
477
+ git config ${mode_prefix}list > output &&
478
test_cmp expect output
479
'
480
test_expect_success '--list without repo produces empty output' '
467
- git --git-dir=nonexistent config --list >output &&
481
+ git --git-dir=nonexistent config ${mode_prefix}list >output &&
482
test_must_be_empty output
483
'
484
490
EOF
491
492
test_expect_success '--name-only --list' '
479
- git config --name-only --list >output &&
493
+ git config ${mode_prefix}list --name-only >output &&
494
test_cmp expect output
495
'
496
628
EOF
629
630
test_expect_success 'alternative GIT_CONFIG' '
617
- GIT_CONFIG=other-config git config --list >output &&
631
+ GIT_CONFIG=other-config git config ${mode_prefix}list >output &&
632
test_cmp expect output
633
'
634
635
test_expect_success 'alternative GIT_CONFIG (--file)' '
622
- git config --file other-config --list >output &&
636
+ git config ${mode_prefix}list --file other-config >output &&
637
test_cmp expect output
638
'
639
640
test_expect_success 'alternative GIT_CONFIG (--file=-)' '
627
- git config --file - --list <other-config >output &&
641
+ git config ${mode_prefix}list --file - <other-config >output &&
642
test_cmp expect output
643
'
644
651
'
652
653
test_expect_success 'refer config from subdirectory' '
654
+ test_when_finished "rm -r x" &&
655
mkdir x &&
656
test_cmp_config -C x strasse --file=../other-config --get ein.bahn
657
'
862
'
863
864
test_expect_success 'invalid stdin config' '
850
- echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
865
+ echo "[broken" | test_must_fail git config ${mode_prefix}list --file - >output 2>&1 &&
866
test_grep "bad config line 1 in standard input" output
867
'
868
1154
EOF
1155
1156
test_expect_success 'value continued on next line' '
1142
- git config --list > result &&
1157
+ git config ${mode_prefix}list > result &&
1158
test_cmp expect result
1159
'
1160
1178
Qsection.sub=section.val5Q
1179
EOF
1180
test_expect_success '--null --list' '
1166
- git config --null --list >result.raw &&
1181
+ git config ${mode_prefix}list --null >result.raw &&
1182
nul_to_q <result.raw >result &&
1183
echo >>result &&
1184
test_cmp expect result
1213
'
1214
1215
test_expect_success SYMLINKS 'symlinked configuration' '
1216
+ test_when_finished "rm myconfig" &&
1217
ln -s notyet myconfig &&
1218
git config --file=myconfig test.frotz nitfol &&
1219
test -h myconfig &&
1234
'
1235
1236
test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
1237
+ test_when_finished "rm linktonada linktolinktonada" &&
1238
ln -s doesnotexist linktonada &&
1239
ln -s linktonada linktolinktonada &&
1223
- test_must_fail git config --file=linktonada --list &&
1224
- test_must_fail git config --file=linktolinktonada --list
1240
+ test_must_fail git config ${mode_prefix}list --file=linktonada &&
1241
+ test_must_fail git config ${mode_prefix}list --file=linktolinktonada
1242
'
1243
1244
test_expect_success 'check split_cmdline return' '
1495
done
1496
1497
test_expect_success 'git -c is not confused by empty environment' '
1481
- GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
1498
+ GIT_CONFIG_PARAMETERS="" git -c x.one=1 config ${mode_prefix}list
1499
'
1500
1501
test_expect_success 'GIT_CONFIG_PARAMETERS handles old-style entries' '
1686
'
1687
1688
test_expect_success 'git config fails with invalid count' '
1672
- test_must_fail env GIT_CONFIG_COUNT=10a git config --list 2>error &&
1689
+ test_must_fail env GIT_CONFIG_COUNT=10a git config ${mode_prefix}list 2>error &&
1690
test_grep "bogus count" error &&
1674
- test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config --list 2>error &&
1691
+ test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config ${mode_prefix}list 2>error &&
1692
test_grep "too many entries" error
1693
'
1694
1695
test_expect_success 'git config fails with missing config key' '
1696
test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \
1680
- git config --list 2>error &&
1697
+ git config ${mode_prefix}list 2>error &&
1698
test_grep "missing config key" error
1699
'
1700
1701
test_expect_success 'git config fails with missing config value' '
1702
test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \
1686
- git config --list 2>error &&
1703
+ git config ${mode_prefix}list 2>error &&
1704
test_grep "missing config value" error
1705
'
1706
1707
test_expect_success 'git config fails with invalid config pair key' '
1708
test_must_fail env GIT_CONFIG_COUNT=1 \
1709
GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \
1693
- git config --list &&
1710
+ git config ${mode_prefix}list &&
1711
test_must_fail env GIT_CONFIG_COUNT=1 \
1712
GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \
1696
- git config --list
1713
+ git config ${mode_prefix}list
1714
'
1715
1716
test_expect_success 'environment overrides config file' '
1750
git config -f tmp test.value no &&
1751
echo test.value=yes >expect &&
1752
GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1736
- git config -f tmp --list >actual &&
1753
+ git config ${mode_prefix}list -f tmp >actual &&
1754
test_cmp expect actual
1755
'
1756
1759
echo test.value=yes >expect &&
1760
test_config core.editor "echo [test]value=yes >" &&
1761
git config -f tmp --edit &&
1745
- git config -f tmp --list >actual &&
1762
+ git config ${mode_prefix}list -f tmp >actual &&
1763
test_cmp expect actual
1764
'
1765
2110
command line: user.cmdline=true
2111
EOF
2112
GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\
2096
- git -c user.cmdline=true config --list --show-origin >output &&
2113
+ git -c user.cmdline=true config ${mode_prefix}list --show-origin >output &&
2114
test_cmp expect output
2115
'
2116
2127
includeQcommand line:Quser.cmdline
2128
trueQ
2129
EOF
2113
- git -c user.cmdline=true config --null --list --show-origin >output.raw &&
2130
+ git -c user.cmdline=true config ${mode_prefix}list --null --show-origin >output.raw &&
2131
nul_to_q <output.raw >output &&
2132
# The here-doc above adds a newline that the --null output would not
2133
# include. Add it here to make the two comparable.
2141
file:.git/config user.override=local
2142
file:.git/config include.path=../include/relative.include
2143
EOF
2127
- git config --local --list --show-origin >output &&
2144
+ git config ${mode_prefix}list --local --show-origin >output &&
2145
test_cmp expect output
2146
'
2147
2179
cat >expect <<-\EOF &&
2180
file:"file\" (dq) and spaces.conf" user.custom=true
2181
EOF
2165
- git config --file "$WEIRDLY_NAMED_FILE" --show-origin --list >output &&
2182
+ git config ${mode_prefix}list --file "$WEIRDLY_NAMED_FILE" --show-origin >output &&
2183
test_cmp expect output
2184
'
2185
2187
cat >expect <<-\EOF &&
2188
standard input: user.custom=true
2189
EOF
2173
- git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
2190
+ git config ${mode_prefix}list --file - --show-origin <"$CUSTOM_CONFIG_FILE" >output &&
2191
test_cmp expect output
2192
'
2193
2214
cat >expect <<-EOF &&
2215
blob:$blob user.custom=true
2216
EOF
2200
- git config --blob=$blob --show-origin --list >output &&
2217
+ git config ${mode_prefix}list --blob=$blob --show-origin >output &&
2218
test_cmp expect output
2219
)
2220
'
2230
cp "$CUSTOM_CONFIG_FILE" custom.conf &&
2231
git add custom.conf &&
2232
git commit -m "new config file" &&
2216
- git config --blob=main:custom.conf --show-origin --list >output &&
2233
+ git config ${mode_prefix}list --blob=main:custom.conf --show-origin >output &&
2234
test_cmp expect output
2235
)
2236
'
2256
worktree user.worktree=true
2257
command user.cmdline=true
2258
EOF
2259
+ test_when_finished "git worktree remove wt1" &&
2260
git worktree add wt1 &&
2261
# We need these to test for worktree scope, but outside of this
2262
# test, this is just noise
2263
test_config core.repositoryformatversion 1 &&
2264
test_config extensions.worktreeConfig true &&
2265
git config --worktree user.worktree true &&
2248
- git -c user.cmdline=true config --list --show-scope >output &&
2266
+ git -c user.cmdline=true config ${mode_prefix}list --show-scope >output &&
2267
test_cmp expect output
2268
'
2269
2272
cat >expect <<-EOF &&
2273
command user.custom=true
2274
EOF
2257
- git config --blob=$blob --show-scope --list >output &&
2275
+ git config ${mode_prefix}list --blob=$blob --show-scope >output &&
2276
test_cmp expect output
2277
'
2278
2282
local user.override=local
2283
local include.path=../include/relative.include
2284
EOF
2267
- git config --local --list --show-scope >output &&
2285
+ git config ${mode_prefix}list --local --show-scope >output &&
2286
test_cmp expect output
2287
'
2288
2306
local file:.git/../include/relative.include user.relative=include
2307
command command line: user.cmdline=true
2308
EOF
2291
- git -c user.cmdline=true config --list --show-origin --show-scope >output &&
2309
+ git -c user.cmdline=true config ${mode_prefix}list --show-origin --show-scope >output &&
2310
test_cmp expect output
2311
'
2312
2347
global home.config=true
2348
local local.config=true
2349
EOF
2332
- git config --show-scope --list >output &&
2350
+ git config ${mode_prefix}list --show-scope >output &&
2351
test_cmp expect output &&
2352
2353
cat >expect <<-EOF &&
2356
local local.config=true
2357
EOF
2358
GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=custom-system-config GIT_CONFIG_GLOBAL=custom-global-config \
2341
- git config --show-scope --list >output &&
2359
+ git config ${mode_prefix}list --show-scope >output &&
2360
test_cmp expect output &&
2361
2362
cat >expect <<-EOF &&
2363
local local.config=true
2364
EOF
2365
GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null \
2348
- git config --show-scope --list >output &&
2366
+ git config ${mode_prefix}list --show-scope >output &&
2367
test_cmp expect output
2368
'
2369
2370
test_expect_success 'override global and system config with missing file' '
2353
- test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config --global --list &&
2354
- test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config --system --list &&
2371
+ test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config ${mode_prefix}list --global &&
2372
+ test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config ${mode_prefix}list --system &&
2373
GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=does-not-exist git version
2374
'
2375
2496
# no match => add new entry
2497
cp initial config &&
2498
git config --file=config abc.key two a+ &&
2481
- git config --file=config --list >actual &&
2499
+ git config ${mode_prefix}list --file=config >actual &&
2500
cat >expect <<-\EOF &&
2501
abc.key=one
2502
abc.key=two
2509
2510
# multiple values, no match => add
2511
git config --file=config abc.key three a+ &&
2494
- git config --file=config --list >actual &&
2512
+ git config ${mode_prefix}list --file=config >actual &&
2513
cat >expect <<-\EOF &&
2514
abc.key=one
2515
abc.key=two
2519
2520
# single match => replace
2521
git config --file=config abc.key four h+ &&
2504
- git config --file=config --list >actual &&
2522
+ git config ${mode_prefix}list --file=config >actual &&
2523
cat >expect <<-\EOF &&
2524
abc.key=one
2525
abc.key=two
2534
git config --file=config --add abc.key two &&
2535
git config --file=config --add abc.key three &&
2536
git config --file=config --replace-all abc.key four "o+" &&
2519
- git config --file=config --list >actual &&
2537
+ git config ${mode_prefix}list --file=config >actual &&
2538
cat >expect <<-\EOF &&
2539
abc.key=four
2540
abc.key=three
2552
test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2553
test_must_fail git config --file=config --fixed-value --rename-section dev null &&
2554
test_must_fail git config --file=config --fixed-value --remove-section dev &&
2537
- test_must_fail git config --file=config --fixed-value --list &&
2555
+ test_must_fail git config ${mode_prefix}list --file=config --fixed-value &&
2556
test_must_fail git config --file=config --fixed-value --get-color dev.null &&
2557
test_must_fail git config --file=config --fixed-value --get-colorbool dev.null &&
2558
2573
2574
cp initial config &&
2575
git config --file=config fixed.test bogus "$META" &&
2558
- git config --file=config --list >actual &&
2576
+ git config ${mode_prefix}list --file=config >actual &&
2577
cat >expect <<-EOF &&
2578
fixed.test=$META
2579
fixed.test=bogus
2582
2583
cp initial config &&
2584
git config --file=config --fixed-value fixed.test bogus "$META" &&
2567
- git config --file=config --list >actual &&
2585
+ git config ${mode_prefix}list --file=config >actual &&
2586
cat >expect <<-\EOF &&
2587
fixed.test=bogus
2588
EOF
2600
2601
cp initial config &&
2602
git config --file=config --replace-all fixed.test bogus "$META" &&
2585
- git config --file=config --list >actual &&
2603
+ git config ${mode_prefix}list --file=config >actual &&
2604
cat >expect <<-EOF &&
2605
fixed.test=$META
2606
fixed.test=bogus
2608
test_cmp expect actual &&
2609
2610
git config --file=config --fixed-value --replace-all fixed.test bogus "$META" &&
2593
- git config --file=config --list >actual &&
2611
+ git config ${mode_prefix}list --file=config >actual &&
2612
cat >expect <<-EOF &&
2613
fixed.test=bogus
2614
fixed.test=bogus
2769
test_cmp expect err
2770
'
2771
2772
+done
2773
+
2774
test_done