2459
2460
cat >.git/config <<-\EOF &&
2461
[section]
2462
-foo = true
2462
+foo = True
2463
number = 10
2464
big = 1M
2465
+path = ~/dir
2466
+red = red
2467
+blue = Blue
2468
+date = Fri Jun 4 15:46:55 2010
2469
+missing=:(optional)no-such-path
2470
+exists=:(optional)expect
2471
EOF
2472
2473
test_expect_success 'identical modern --type specifiers are allowed' '
2509
test_cmp_config 1048576 --type=bool --no-type --type=int section.big
2510
'
2511
2512
+test_expect_success 'list --type=int shows only canonicalizable int values' '
2513
+ cat >expect <<-EOF &&
2514
+ section.number=10
2515
+ section.big=1048576
2516
+ EOF
2517
+
2518
+ test_must_fail git config ${mode_prefix}list --type=int
2519
+'
2520
+
2521
+test_expect_success 'list --type=bool shows only canonicalizable bool values' '
2522
+ cat >expect <<-EOF &&
2523
+ section.foo=true
2524
+ section.number=true
2525
+ section.big=true
2526
+ EOF
2527
+
2528
+ test_must_fail git config ${mode_prefix}list --type=bool
2529
+'
2530
+
2531
+test_expect_success 'list --type=bool-or-int shows only canonicalizable values' '
2532
+ cat >expect <<-EOF &&
2533
+ section.foo=true
2534
+ section.number=10
2535
+ section.big=1048576
2536
+ EOF
2537
+
2538
+ test_must_fail git config ${mode_prefix}list --type=bool-or-int
2539
+'
2540
+
2541
+test_expect_success 'list --type=path shows only canonicalizable path values' '
2542
+ # TODO: handling of missing path is incorrect here.
2543
+ cat >expect <<-EOF &&
2544
+ section.foo=True
2545
+ section.number=10
2546
+ section.big=1M
2547
+ section.path=$HOME/dir
2548
+ section.red=red
2549
+ section.blue=Blue
2550
+ section.date=Fri Jun 4 15:46:55 2010
2551
+ section.missing=section.exists=expect
2552
+ EOF
2553
+
2554
+ git config ${mode_prefix}list --type=path >actual 2>err &&
2555
+ test_cmp expect actual &&
2556
+ test_must_be_empty err
2557
+'
2558
+
2559
+test_expect_success 'list --type=expiry-date shows only canonicalizable dates' '
2560
+ cat >expecterr <<-EOF &&
2561
+ error: '\''True'\'' for '\''section.foo'\'' is not a valid timestamp
2562
+ error: '\''~/dir'\'' for '\''section.path'\'' is not a valid timestamp
2563
+ error: '\''red'\'' for '\''section.red'\'' is not a valid timestamp
2564
+ error: '\''Blue'\'' for '\''section.blue'\'' is not a valid timestamp
2565
+ error: '\'':(optional)no-such-path'\'' for '\''section.missing'\'' is not a valid timestamp
2566
+ error: '\'':(optional)expect'\'' for '\''section.exists'\'' is not a valid timestamp
2567
+ EOF
2568
+
2569
+ git config ${mode_prefix}list --type=expiry-date >actual 2>err &&
2570
+
2571
+ # section.number and section.big parse as relative dates that could
2572
+ # have clock skew in their results.
2573
+ test_grep section.big actual &&
2574
+ test_grep section.number actual &&
2575
+ test_grep "section.date=$(git config --type=expiry-date section.$key)" actual &&
2576
+ test_cmp expecterr err
2577
+'
2578
+
2579
+test_expect_success 'list --type=color shows only canonicalizable color values' '
2580
+ cat >expect <<-EOF &&
2581
+ section.number=<>
2582
+ section.red=<RED>
2583
+ section.blue=<BLUE>
2584
+ EOF
2585
+
2586
+ cat >expecterr <<-EOF &&
2587
+ error: invalid color value: True
2588
+ error: invalid color value: 1M
2589
+ error: invalid color value: ~/dir
2590
+ error: invalid color value: Fri Jun 4 15:46:55 2010
2591
+ error: invalid color value: :(optional)no-such-path
2592
+ error: invalid color value: :(optional)expect
2593
+ EOF
2594
+
2595
+ git config ${mode_prefix}list --type=color >actual.raw 2>err &&
2596
+ test_decode_color <actual.raw >actual &&
2597
+ test_cmp expect actual &&
2598
+ test_cmp expecterr err
2599
+'
2600
+
2601
test_expect_success '--type rejects unknown specifiers' '
2602
test_must_fail git config --type=nonsense section.foo 2>error &&
2603
test_grep "unrecognized --type argument" error