1424
test_cmp expect actual
1425
'
1426
1427
+test_expect_success 'git config handles environment config pairs' '
1428
+ GIT_CONFIG_COUNT=2 \
1429
+ GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \
1430
+ GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \
1431
+ git config --get-regexp "pair.*" >actual &&
1432
+ cat >expect <<-EOF &&
1433
+ pair.one foo
1434
+ pair.two bar
1435
+ EOF
1436
+ test_cmp expect actual
1437
+'
1438
+
1439
+test_expect_success 'git config ignores pairs without count' '
1440
+ test_must_fail env GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1441
+ git config pair.one 2>error &&
1442
+ test_must_be_empty error
1443
+'
1444
+
1445
+test_expect_success 'git config ignores pairs with zero count' '
1446
+ test_must_fail env \
1447
+ GIT_CONFIG_COUNT=0 \
1448
+ GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1449
+ git config pair.one
1450
+'
1451
+
1452
+test_expect_success 'git config ignores pairs exceeding count' '
1453
+ GIT_CONFIG_COUNT=1 \
1454
+ GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1455
+ GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \
1456
+ git config --get-regexp "pair.*" >actual &&
1457
+ cat >expect <<-EOF &&
1458
+ pair.one value
1459
+ EOF
1460
+ test_cmp expect actual
1461
+'
1462
+
1463
+test_expect_success 'git config ignores pairs with zero count' '
1464
+ test_must_fail env \
1465
+ GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1466
+ git config pair.one >error &&
1467
+ test_must_be_empty error
1468
+'
1469
+
1470
+test_expect_success 'git config ignores pairs with empty count' '
1471
+ test_must_fail env \
1472
+ GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1473
+ git config pair.one >error &&
1474
+ test_must_be_empty error
1475
+'
1476
+
1477
+test_expect_success 'git config fails with invalid count' '
1478
+ test_must_fail env GIT_CONFIG_COUNT=10a git config --list 2>error &&
1479
+ test_i18ngrep "bogus count" error &&
1480
+ test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config --list 2>error &&
1481
+ test_i18ngrep "too many entries" error
1482
+'
1483
+
1484
+test_expect_success 'git config fails with missing config key' '
1485
+ test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \
1486
+ git config --list 2>error &&
1487
+ test_i18ngrep "missing config key" error
1488
+'
1489
+
1490
+test_expect_success 'git config fails with missing config value' '
1491
+ test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \
1492
+ git config --list 2>error &&
1493
+ test_i18ngrep "missing config value" error
1494
+'
1495
+
1496
+test_expect_success 'git config fails with invalid config pair key' '
1497
+ test_must_fail env GIT_CONFIG_COUNT=1 \
1498
+ GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \
1499
+ git config --list &&
1500
+ test_must_fail env GIT_CONFIG_COUNT=1 \
1501
+ GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \
1502
+ git config --list
1503
+'
1504
+
1505
+test_expect_success 'environment overrides config file' '
1506
+ test_when_finished "rm -f .git/config" &&
1507
+ cat >.git/config <<-EOF &&
1508
+ [pair]
1509
+ one = value
1510
+ EOF
1511
+ GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \
1512
+ git config pair.one >actual &&
1513
+ cat >expect <<-EOF &&
1514
+ override
1515
+ EOF
1516
+ test_cmp expect actual
1517
+'
1518
+
1519
+test_expect_success 'GIT_CONFIG_PARAMETERS overrides environment config' '
1520
+ GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1521
+ GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \
1522
+ git config pair.one >actual &&
1523
+ cat >expect <<-EOF &&
1524
+ override
1525
+ EOF
1526
+ test_cmp expect actual
1527
+'
1528
+
1529
+test_expect_success 'command line overrides environment config' '
1530
+ GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1531
+ git -c pair.one=override config pair.one >actual &&
1532
+ cat >expect <<-EOF &&
1533
+ override
1534
+ EOF
1535
+ test_cmp expect actual
1536
+'
1537
+
1538
test_expect_success 'git config --edit works' '
1539
git config -f tmp test.value no &&
1540
echo test.value=yes >expect &&
1880
file:.git/config user.override=local
1881
file:.git/config include.path=../include/relative.include
1882
file:.git/../include/relative.include user.relative=include
1883
+ command line: user.environ=true
1884
command line: user.cmdline=true
1885
EOF
1774
- git -c user.cmdline=true config --list --show-origin >output &&
1886
+ GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\
1887
+ git -c user.cmdline=true config --list --show-origin >output &&
1888
test_cmp expect output
1889
'
1890