t / t1300-config.shon commit t/test-lib: add an SHA1 prerequisite (d16ab63)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Johannes Schindelin
   4#
   5
   6test_description='Test git config in different settings'
   7
   8. ./test-lib.sh
   9
  10test_expect_success 'clear default config' '
  11        rm -f .git/config
  12'
  13
  14cat > expect << EOF
  15[core]
  16        penguin = little blue
  17EOF
  18test_expect_success 'initial' '
  19        git config core.penguin "little blue" &&
  20        test_cmp expect .git/config
  21'
  22
  23cat > expect << EOF
  24[core]
  25        penguin = little blue
  26        Movie = BadPhysics
  27EOF
  28test_expect_success 'mixed case' '
  29        git config Core.Movie BadPhysics &&
  30        test_cmp expect .git/config
  31'
  32
  33cat > expect << EOF
  34[core]
  35        penguin = little blue
  36        Movie = BadPhysics
  37[Cores]
  38        WhatEver = Second
  39EOF
  40test_expect_success 'similar section' '
  41        git config Cores.WhatEver Second &&
  42        test_cmp expect .git/config
  43'
  44
  45cat > expect << EOF
  46[core]
  47        penguin = little blue
  48        Movie = BadPhysics
  49        UPPERCASE = true
  50[Cores]
  51        WhatEver = Second
  52EOF
  53test_expect_success 'uppercase section' '
  54        git config CORE.UPPERCASE true &&
  55        test_cmp expect .git/config
  56'
  57
  58test_expect_success 'replace with non-match' '
  59        git config core.penguin kingpin !blue
  60'
  61
  62test_expect_success 'replace with non-match (actually matching)' '
  63        git config core.penguin "very blue" !kingpin
  64'
  65
  66cat > expect << EOF
  67[core]
  68        penguin = very blue
  69        Movie = BadPhysics
  70        UPPERCASE = true
  71        penguin = kingpin
  72[Cores]
  73        WhatEver = Second
  74EOF
  75
  76test_expect_success 'non-match result' 'test_cmp expect .git/config'
  77
  78test_expect_success 'find mixed-case key by canonical name' '
  79        echo Second >expect &&
  80        git config cores.whatever >actual &&
  81        test_cmp expect actual
  82'
  83
  84test_expect_success 'find mixed-case key by non-canonical name' '
  85        echo Second >expect &&
  86        git config CoReS.WhAtEvEr >actual &&
  87        test_cmp expect actual
  88'
  89
  90test_expect_success 'subsections are not canonicalized by git-config' '
  91        cat >>.git/config <<-\EOF &&
  92        [section.SubSection]
  93        key = one
  94        [section "SubSection"]
  95        key = two
  96        EOF
  97        echo one >expect &&
  98        git config section.subsection.key >actual &&
  99        test_cmp expect actual &&
 100        echo two >expect &&
 101        git config section.SubSection.key >actual &&
 102        test_cmp expect actual
 103'
 104
 105cat > .git/config <<\EOF
 106[alpha]
 107bar = foo
 108[beta]
 109baz = multiple \
 110lines
 111foo = bar
 112EOF
 113
 114test_expect_success 'unset with cont. lines' '
 115        git config --unset beta.baz
 116'
 117
 118cat > expect <<\EOF
 119[alpha]
 120bar = foo
 121[beta]
 122foo = bar
 123EOF
 124
 125test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config'
 126
 127cat > .git/config << EOF
 128[beta] ; silly comment # another comment
 129noIndent= sillyValue ; 'nother silly comment
 130
 131# empty line
 132                ; comment
 133                haha   ="beta" # last silly comment
 134haha = hello
 135        haha = bello
 136[nextSection] noNewline = ouch
 137EOF
 138
 139cp .git/config .git/config2
 140
 141test_expect_success 'multiple unset' '
 142        git config --unset-all beta.haha
 143'
 144
 145cat > expect << EOF
 146[beta] ; silly comment # another comment
 147noIndent= sillyValue ; 'nother silly comment
 148
 149# empty line
 150                ; comment
 151[nextSection] noNewline = ouch
 152EOF
 153
 154test_expect_success 'multiple unset is correct' '
 155        test_cmp expect .git/config
 156'
 157
 158cp .git/config2 .git/config
 159
 160test_expect_success '--replace-all missing value' '
 161        test_must_fail git config --replace-all beta.haha &&
 162        test_cmp .git/config2 .git/config
 163'
 164
 165rm .git/config2
 166
 167test_expect_success '--replace-all' '
 168        git config --replace-all beta.haha gamma
 169'
 170
 171cat > expect << EOF
 172[beta] ; silly comment # another comment
 173noIndent= sillyValue ; 'nother silly comment
 174
 175# empty line
 176                ; comment
 177        haha = gamma
 178[nextSection] noNewline = ouch
 179EOF
 180
 181test_expect_success 'all replaced' '
 182        test_cmp expect .git/config
 183'
 184
 185cat > expect << EOF
 186[beta] ; silly comment # another comment
 187noIndent= sillyValue ; 'nother silly comment
 188
 189# empty line
 190                ; comment
 191        haha = alpha
 192[nextSection] noNewline = ouch
 193EOF
 194test_expect_success 'really mean test' '
 195        git config beta.haha alpha &&
 196        test_cmp expect .git/config
 197'
 198
 199cat > expect << EOF
 200[beta] ; silly comment # another comment
 201noIndent= sillyValue ; 'nother silly comment
 202
 203# empty line
 204                ; comment
 205        haha = alpha
 206[nextSection]
 207        nonewline = wow
 208EOF
 209test_expect_success 'really really mean test' '
 210        git config nextsection.nonewline wow &&
 211        test_cmp expect .git/config
 212'
 213
 214test_expect_success 'get value' '
 215        echo alpha >expect &&
 216        git config beta.haha >actual &&
 217        test_cmp expect actual
 218'
 219
 220cat > expect << EOF
 221[beta] ; silly comment # another comment
 222noIndent= sillyValue ; 'nother silly comment
 223
 224# empty line
 225                ; comment
 226[nextSection]
 227        nonewline = wow
 228EOF
 229test_expect_success 'unset' '
 230        git config --unset beta.haha &&
 231        test_cmp expect .git/config
 232'
 233
 234cat > expect << EOF
 235[beta] ; silly comment # another comment
 236noIndent= sillyValue ; 'nother silly comment
 237
 238# empty line
 239                ; comment
 240[nextSection]
 241        nonewline = wow
 242        NoNewLine = wow2 for me
 243EOF
 244test_expect_success 'multivar' '
 245        git config nextsection.NoNewLine "wow2 for me" "for me$" &&
 246        test_cmp expect .git/config
 247'
 248
 249test_expect_success 'non-match' '
 250        git config --get nextsection.nonewline !for
 251'
 252
 253test_expect_success 'non-match value' '
 254        echo wow >expect &&
 255        git config --get nextsection.nonewline !for >actual &&
 256        test_cmp expect actual
 257'
 258
 259test_expect_success 'multi-valued get returns final one' '
 260        echo "wow2 for me" >expect &&
 261        git config --get nextsection.nonewline >actual &&
 262        test_cmp expect actual
 263'
 264
 265test_expect_success 'multi-valued get-all returns all' '
 266        cat >expect <<-\EOF &&
 267        wow
 268        wow2 for me
 269        EOF
 270        git config --get-all nextsection.nonewline >actual &&
 271        test_cmp expect actual
 272'
 273
 274cat > expect << EOF
 275[beta] ; silly comment # another comment
 276noIndent= sillyValue ; 'nother silly comment
 277
 278# empty line
 279                ; comment
 280[nextSection]
 281        nonewline = wow3
 282        NoNewLine = wow2 for me
 283EOF
 284test_expect_success 'multivar replace' '
 285        git config nextsection.nonewline "wow3" "wow$" &&
 286        test_cmp expect .git/config
 287'
 288
 289test_expect_success 'ambiguous unset' '
 290        test_must_fail git config --unset nextsection.nonewline
 291'
 292
 293test_expect_success 'invalid unset' '
 294        test_must_fail git config --unset somesection.nonewline
 295'
 296
 297cat > expect << EOF
 298[beta] ; silly comment # another comment
 299noIndent= sillyValue ; 'nother silly comment
 300
 301# empty line
 302                ; comment
 303[nextSection]
 304        NoNewLine = wow2 for me
 305EOF
 306
 307test_expect_success 'multivar unset' '
 308        git config --unset nextsection.nonewline "wow3$" &&
 309        test_cmp expect .git/config
 310'
 311
 312test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
 313
 314test_expect_success 'correct key' 'git config 123456.a123 987'
 315
 316test_expect_success 'hierarchical section' '
 317        git config Version.1.2.3eX.Alpha beta
 318'
 319
 320cat > expect << EOF
 321[beta] ; silly comment # another comment
 322noIndent= sillyValue ; 'nother silly comment
 323
 324# empty line
 325                ; comment
 326[nextSection]
 327        NoNewLine = wow2 for me
 328[123456]
 329        a123 = 987
 330[Version "1.2.3eX"]
 331        Alpha = beta
 332EOF
 333
 334test_expect_success 'hierarchical section value' '
 335        test_cmp expect .git/config
 336'
 337
 338cat > expect << EOF
 339beta.noindent=sillyValue
 340nextsection.nonewline=wow2 for me
 341123456.a123=987
 342version.1.2.3eX.alpha=beta
 343EOF
 344
 345test_expect_success 'working --list' '
 346        git config --list > output &&
 347        test_cmp expect output
 348'
 349cat > expect << EOF
 350EOF
 351
 352test_expect_success '--list without repo produces empty output' '
 353        git --git-dir=nonexistent config --list >output &&
 354        test_cmp expect output
 355'
 356
 357cat > expect << EOF
 358beta.noindent
 359nextsection.nonewline
 360123456.a123
 361version.1.2.3eX.alpha
 362EOF
 363
 364test_expect_success '--name-only --list' '
 365        git config --name-only --list >output &&
 366        test_cmp expect output
 367'
 368
 369cat > expect << EOF
 370beta.noindent sillyValue
 371nextsection.nonewline wow2 for me
 372EOF
 373
 374test_expect_success '--get-regexp' '
 375        git config --get-regexp in >output &&
 376        test_cmp expect output
 377'
 378
 379cat > expect << EOF
 380beta.noindent
 381nextsection.nonewline
 382EOF
 383
 384test_expect_success '--name-only --get-regexp' '
 385        git config --name-only --get-regexp in >output &&
 386        test_cmp expect output
 387'
 388
 389cat > expect << EOF
 390wow2 for me
 391wow4 for you
 392EOF
 393
 394test_expect_success '--add' '
 395        git config --add nextsection.nonewline "wow4 for you" &&
 396        git config --get-all nextsection.nonewline > output &&
 397        test_cmp expect output
 398'
 399
 400cat > .git/config << EOF
 401[novalue]
 402        variable
 403[emptyvalue]
 404        variable =
 405EOF
 406
 407test_expect_success 'get variable with no value' '
 408        git config --get novalue.variable ^$
 409'
 410
 411test_expect_success 'get variable with empty value' '
 412        git config --get emptyvalue.variable ^$
 413'
 414
 415echo novalue.variable > expect
 416
 417test_expect_success 'get-regexp variable with no value' '
 418        git config --get-regexp novalue > output &&
 419        test_cmp expect output
 420'
 421
 422echo 'novalue.variable true' > expect
 423
 424test_expect_success 'get-regexp --bool variable with no value' '
 425        git config --bool --get-regexp novalue > output &&
 426        test_cmp expect output
 427'
 428
 429echo 'emptyvalue.variable ' > expect
 430
 431test_expect_success 'get-regexp variable with empty value' '
 432        git config --get-regexp emptyvalue > output &&
 433        test_cmp expect output
 434'
 435
 436echo true > expect
 437
 438test_expect_success 'get bool variable with no value' '
 439        git config --bool novalue.variable > output &&
 440        test_cmp expect output
 441'
 442
 443echo false > expect
 444
 445test_expect_success 'get bool variable with empty value' '
 446        git config --bool emptyvalue.variable > output &&
 447        test_cmp expect output
 448'
 449
 450test_expect_success 'no arguments, but no crash' '
 451        test_must_fail git config >output 2>&1 &&
 452        test_i18ngrep usage output
 453'
 454
 455cat > .git/config << EOF
 456[a.b]
 457        c = d
 458EOF
 459
 460cat > expect << EOF
 461[a.b]
 462        c = d
 463[a]
 464        x = y
 465EOF
 466
 467test_expect_success 'new section is partial match of another' '
 468        git config a.x y &&
 469        test_cmp expect .git/config
 470'
 471
 472cat > expect << EOF
 473[a.b]
 474        c = d
 475[a]
 476        x = y
 477        b = c
 478[b]
 479        x = y
 480EOF
 481
 482test_expect_success 'new variable inserts into proper section' '
 483        git config b.x y &&
 484        git config a.b c &&
 485        test_cmp expect .git/config
 486'
 487
 488test_expect_success 'alternative --file (non-existing file should fail)' '
 489        test_must_fail git config --file non-existing-config -l
 490'
 491
 492cat > other-config << EOF
 493[ein]
 494        bahn = strasse
 495EOF
 496
 497cat > expect << EOF
 498ein.bahn=strasse
 499EOF
 500
 501test_expect_success 'alternative GIT_CONFIG' '
 502        GIT_CONFIG=other-config git config --list >output &&
 503        test_cmp expect output
 504'
 505
 506test_expect_success 'alternative GIT_CONFIG (--file)' '
 507        git config --file other-config --list >output &&
 508        test_cmp expect output
 509'
 510
 511test_expect_success 'alternative GIT_CONFIG (--file=-)' '
 512        git config --file - --list <other-config >output &&
 513        test_cmp expect output
 514'
 515
 516test_expect_success 'setting a value in stdin is an error' '
 517        test_must_fail git config --file - some.value foo
 518'
 519
 520test_expect_success 'editing stdin is an error' '
 521        test_must_fail git config --file - --edit
 522'
 523
 524test_expect_success 'refer config from subdirectory' '
 525        mkdir x &&
 526        (
 527                cd x &&
 528                echo strasse >expect &&
 529                git config --get --file ../other-config ein.bahn >actual &&
 530                test_cmp expect actual
 531        )
 532
 533'
 534
 535test_expect_success 'refer config from subdirectory via --file' '
 536        (
 537                cd x &&
 538                git config --file=../other-config --get ein.bahn >actual &&
 539                test_cmp expect actual
 540        )
 541'
 542
 543cat > expect << EOF
 544[ein]
 545        bahn = strasse
 546[anwohner]
 547        park = ausweis
 548EOF
 549
 550test_expect_success '--set in alternative file' '
 551        git config --file=other-config anwohner.park ausweis &&
 552        test_cmp expect other-config
 553'
 554
 555cat > .git/config << EOF
 556# Hallo
 557        #Bello
 558[branch "eins"]
 559        x = 1
 560[branch.eins]
 561        y = 1
 562        [branch "1 234 blabl/a"]
 563weird
 564EOF
 565
 566test_expect_success 'rename section' '
 567        git config --rename-section branch.eins branch.zwei
 568'
 569
 570cat > expect << EOF
 571# Hallo
 572        #Bello
 573[branch "zwei"]
 574        x = 1
 575[branch "zwei"]
 576        y = 1
 577        [branch "1 234 blabl/a"]
 578weird
 579EOF
 580
 581test_expect_success 'rename succeeded' '
 582        test_cmp expect .git/config
 583'
 584
 585test_expect_success 'rename non-existing section' '
 586        test_must_fail git config --rename-section \
 587                branch."world domination" branch.drei
 588'
 589
 590test_expect_success 'rename succeeded' '
 591        test_cmp expect .git/config
 592'
 593
 594test_expect_success 'rename another section' '
 595        git config --rename-section branch."1 234 blabl/a" branch.drei
 596'
 597
 598cat > expect << EOF
 599# Hallo
 600        #Bello
 601[branch "zwei"]
 602        x = 1
 603[branch "zwei"]
 604        y = 1
 605[branch "drei"]
 606weird
 607EOF
 608
 609test_expect_success 'rename succeeded' '
 610        test_cmp expect .git/config
 611'
 612
 613cat >> .git/config << EOF
 614[branch "vier"] z = 1
 615EOF
 616
 617test_expect_success 'rename a section with a var on the same line' '
 618        git config --rename-section branch.vier branch.zwei
 619'
 620
 621cat > expect << EOF
 622# Hallo
 623        #Bello
 624[branch "zwei"]
 625        x = 1
 626[branch "zwei"]
 627        y = 1
 628[branch "drei"]
 629weird
 630[branch "zwei"]
 631        z = 1
 632EOF
 633
 634test_expect_success 'rename succeeded' '
 635        test_cmp expect .git/config
 636'
 637
 638test_expect_success 'renaming empty section name is rejected' '
 639        test_must_fail git config --rename-section branch.zwei ""
 640'
 641
 642test_expect_success 'renaming to bogus section is rejected' '
 643        test_must_fail git config --rename-section branch.zwei "bogus name"
 644'
 645
 646cat >> .git/config << EOF
 647  [branch "zwei"] a = 1 [branch "vier"]
 648EOF
 649
 650test_expect_success 'remove section' '
 651        git config --remove-section branch.zwei
 652'
 653
 654cat > expect << EOF
 655# Hallo
 656        #Bello
 657[branch "drei"]
 658weird
 659EOF
 660
 661test_expect_success 'section was removed properly' '
 662        test_cmp expect .git/config
 663'
 664
 665cat > expect << EOF
 666[gitcvs]
 667        enabled = true
 668        dbname = %Ggitcvs2.%a.%m.sqlite
 669[gitcvs "ext"]
 670        dbname = %Ggitcvs1.%a.%m.sqlite
 671EOF
 672
 673test_expect_success 'section ending' '
 674        rm -f .git/config &&
 675        git config gitcvs.enabled true &&
 676        git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
 677        git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
 678        test_cmp expect .git/config
 679
 680'
 681
 682test_expect_success numbers '
 683        git config kilo.gram 1k &&
 684        git config mega.ton 1m &&
 685        echo 1024 >expect &&
 686        echo 1048576 >>expect &&
 687        git config --int --get kilo.gram >actual &&
 688        git config --int --get mega.ton >>actual &&
 689        test_cmp expect actual
 690'
 691
 692test_expect_success '--int is at least 64 bits' '
 693        git config giga.watts 121g &&
 694        echo 129922760704 >expect &&
 695        git config --int --get giga.watts >actual &&
 696        test_cmp expect actual
 697'
 698
 699test_expect_success 'invalid unit' '
 700        git config aninvalid.unit "1auto" &&
 701        echo 1auto >expect &&
 702        git config aninvalid.unit >actual &&
 703        test_cmp expect actual &&
 704        test_must_fail git config --int --get aninvalid.unit 2>actual &&
 705        test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
 706'
 707
 708test_expect_success 'line number is reported correctly' '
 709        printf "[bool]\n\tvar\n" >invalid &&
 710        test_must_fail git config -f invalid --path bool.var 2>actual &&
 711        test_i18ngrep "line 2" actual
 712'
 713
 714test_expect_success 'invalid stdin config' '
 715        echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
 716        test_i18ngrep "bad config line 1 in standard input" output
 717'
 718
 719cat > expect << EOF
 720true
 721false
 722true
 723false
 724true
 725false
 726true
 727false
 728EOF
 729
 730test_expect_success bool '
 731
 732        git config bool.true1 01 &&
 733        git config bool.true2 -1 &&
 734        git config bool.true3 YeS &&
 735        git config bool.true4 true &&
 736        git config bool.false1 000 &&
 737        git config bool.false2 "" &&
 738        git config bool.false3 nO &&
 739        git config bool.false4 FALSE &&
 740        rm -f result &&
 741        for i in 1 2 3 4
 742        do
 743            git config --bool --get bool.true$i >>result
 744            git config --bool --get bool.false$i >>result
 745        done &&
 746        test_cmp expect result'
 747
 748test_expect_success 'invalid bool (--get)' '
 749
 750        git config bool.nobool foobar &&
 751        test_must_fail git config --bool --get bool.nobool'
 752
 753test_expect_success 'invalid bool (set)' '
 754
 755        test_must_fail git config --bool bool.nobool foobar'
 756
 757cat > expect <<\EOF
 758[bool]
 759        true1 = true
 760        true2 = true
 761        true3 = true
 762        true4 = true
 763        false1 = false
 764        false2 = false
 765        false3 = false
 766        false4 = false
 767EOF
 768
 769test_expect_success 'set --bool' '
 770
 771        rm -f .git/config &&
 772        git config --bool bool.true1 01 &&
 773        git config --bool bool.true2 -1 &&
 774        git config --bool bool.true3 YeS &&
 775        git config --bool bool.true4 true &&
 776        git config --bool bool.false1 000 &&
 777        git config --bool bool.false2 "" &&
 778        git config --bool bool.false3 nO &&
 779        git config --bool bool.false4 FALSE &&
 780        test_cmp expect .git/config'
 781
 782cat > expect <<\EOF
 783[int]
 784        val1 = 1
 785        val2 = -1
 786        val3 = 5242880
 787EOF
 788
 789test_expect_success 'set --int' '
 790
 791        rm -f .git/config &&
 792        git config --int int.val1 01 &&
 793        git config --int int.val2 -1 &&
 794        git config --int int.val3 5m &&
 795        test_cmp expect .git/config
 796'
 797
 798test_expect_success 'get --bool-or-int' '
 799        cat >.git/config <<-\EOF &&
 800        [bool]
 801        true1
 802        true2 = true
 803        false = false
 804        [int]
 805        int1 = 0
 806        int2 = 1
 807        int3 = -1
 808        EOF
 809        cat >expect <<-\EOF &&
 810        true
 811        true
 812        false
 813        0
 814        1
 815        -1
 816        EOF
 817        {
 818                git config --bool-or-int bool.true1 &&
 819                git config --bool-or-int bool.true2 &&
 820                git config --bool-or-int bool.false &&
 821                git config --bool-or-int int.int1 &&
 822                git config --bool-or-int int.int2 &&
 823                git config --bool-or-int int.int3
 824        } >actual &&
 825        test_cmp expect actual
 826'
 827
 828cat >expect <<\EOF
 829[bool]
 830        true1 = true
 831        false1 = false
 832        true2 = true
 833        false2 = false
 834[int]
 835        int1 = 0
 836        int2 = 1
 837        int3 = -1
 838EOF
 839
 840test_expect_success 'set --bool-or-int' '
 841        rm -f .git/config &&
 842        git config --bool-or-int bool.true1 true &&
 843        git config --bool-or-int bool.false1 false &&
 844        git config --bool-or-int bool.true2 yes &&
 845        git config --bool-or-int bool.false2 no &&
 846        git config --bool-or-int int.int1 0 &&
 847        git config --bool-or-int int.int2 1 &&
 848        git config --bool-or-int int.int3 -1 &&
 849        test_cmp expect .git/config
 850'
 851
 852cat >expect <<\EOF
 853[path]
 854        home = ~/
 855        normal = /dev/null
 856        trailingtilde = foo~
 857EOF
 858
 859test_expect_success !MINGW 'set --path' '
 860        rm -f .git/config &&
 861        git config --path path.home "~/" &&
 862        git config --path path.normal "/dev/null" &&
 863        git config --path path.trailingtilde "foo~" &&
 864        test_cmp expect .git/config'
 865
 866if test_have_prereq !MINGW && test "${HOME+set}"
 867then
 868        test_set_prereq HOMEVAR
 869fi
 870
 871cat >expect <<EOF
 872$HOME/
 873/dev/null
 874foo~
 875EOF
 876
 877test_expect_success HOMEVAR 'get --path' '
 878        git config --get --path path.home > result &&
 879        git config --get --path path.normal >> result &&
 880        git config --get --path path.trailingtilde >> result &&
 881        test_cmp expect result
 882'
 883
 884cat >expect <<\EOF
 885/dev/null
 886foo~
 887EOF
 888
 889test_expect_success !MINGW 'get --path copes with unset $HOME' '
 890        (
 891                unset HOME;
 892                test_must_fail git config --get --path path.home \
 893                        >result 2>msg &&
 894                git config --get --path path.normal >>result &&
 895                git config --get --path path.trailingtilde >>result
 896        ) &&
 897        test_i18ngrep "[Ff]ailed to expand.*~/" msg &&
 898        test_cmp expect result
 899'
 900
 901test_expect_success 'get --path barfs on boolean variable' '
 902        echo "[path]bool" >.git/config &&
 903        test_must_fail git config --get --path path.bool
 904'
 905
 906test_expect_success 'get --expiry-date' '
 907        rel="3.weeks.5.days.00:00" &&
 908        rel_out="$rel ->" &&
 909        cat >.git/config <<-\EOF &&
 910        [date]
 911        valid1 = "3.weeks.5.days 00:00"
 912        valid2 = "Fri Jun 4 15:46:55 2010"
 913        valid3 = "2017/11/11 11:11:11PM"
 914        valid4 = "2017/11/10 09:08:07 PM"
 915        valid5 = "never"
 916        invalid1 = "abc"
 917        EOF
 918        cat >expect <<-EOF &&
 919        $(test-tool date timestamp $rel)
 920        1275666415
 921        1510441871
 922        1510348087
 923        0
 924        EOF
 925        {
 926                echo "$rel_out $(git config --expiry-date date.valid1)"
 927                git config --expiry-date date.valid2 &&
 928                git config --expiry-date date.valid3 &&
 929                git config --expiry-date date.valid4 &&
 930                git config --expiry-date date.valid5
 931        } >actual &&
 932        test_cmp expect actual &&
 933        test_must_fail git config --expiry-date date.invalid1
 934'
 935
 936test_expect_success 'get --type=color' '
 937        rm .git/config &&
 938        git config foo.color "red" &&
 939        git config --get --type=color foo.color >actual.raw &&
 940        test_decode_color <actual.raw >actual &&
 941        echo "<RED>" >expect &&
 942        test_cmp expect actual
 943'
 944
 945cat >expect << EOF
 946[foo]
 947        color = red
 948EOF
 949
 950test_expect_success 'set --type=color' '
 951        rm .git/config &&
 952        git config --type=color foo.color "red" &&
 953        test_cmp expect .git/config
 954'
 955
 956test_expect_success 'get --type=color barfs on non-color' '
 957        echo "[foo]bar=not-a-color" >.git/config &&
 958        test_must_fail git config --get --type=color foo.bar
 959'
 960
 961test_expect_success 'set --type=color barfs on non-color' '
 962        test_must_fail git config --type=color foo.color "not-a-color" 2>error &&
 963        test_i18ngrep "cannot parse color" error
 964'
 965
 966cat > expect << EOF
 967[quote]
 968        leading = " test"
 969        ending = "test "
 970        semicolon = "test;test"
 971        hash = "test#test"
 972EOF
 973test_expect_success 'quoting' '
 974        rm -f .git/config &&
 975        git config quote.leading " test" &&
 976        git config quote.ending "test " &&
 977        git config quote.semicolon "test;test" &&
 978        git config quote.hash "test#test" &&
 979        test_cmp expect .git/config
 980'
 981
 982test_expect_success 'key with newline' '
 983        test_must_fail git config "key.with
 984newline" 123'
 985
 986test_expect_success 'value with newline' 'git config key.sub value.with\\\
 987newline'
 988
 989cat > .git/config <<\EOF
 990[section]
 991        ; comment \
 992        continued = cont\
 993inued
 994        noncont   = not continued ; \
 995        quotecont = "cont;\
 996inued"
 997EOF
 998
 999cat > expect <<\EOF
1000section.continued=continued
1001section.noncont=not continued
1002section.quotecont=cont;inued
1003EOF
1004
1005test_expect_success 'value continued on next line' '
1006        git config --list > result &&
1007        test_cmp result expect
1008'
1009
1010cat > .git/config <<\EOF
1011[section "sub=section"]
1012        val1 = foo=bar
1013        val2 = foo\nbar
1014        val3 = \n\n
1015        val4 =
1016        val5
1017EOF
1018
1019cat > expect <<\EOF
1020section.sub=section.val1
1021foo=barQsection.sub=section.val2
1022foo
1023barQsection.sub=section.val3
1024
1025
1026Qsection.sub=section.val4
1027Qsection.sub=section.val5Q
1028EOF
1029test_expect_success '--null --list' '
1030        git config --null --list >result.raw &&
1031        nul_to_q <result.raw >result &&
1032        echo >>result &&
1033        test_cmp expect result
1034'
1035
1036test_expect_success '--null --get-regexp' '
1037        git config --null --get-regexp "val[0-9]" >result.raw &&
1038        nul_to_q <result.raw >result &&
1039        echo >>result &&
1040        test_cmp expect result
1041'
1042
1043test_expect_success 'inner whitespace kept verbatim' '
1044        git config section.val "foo       bar" &&
1045        echo "foo         bar" >expect &&
1046        git config section.val >actual &&
1047        test_cmp expect actual
1048'
1049
1050test_expect_success SYMLINKS 'symlinked configuration' '
1051        ln -s notyet myconfig &&
1052        git config --file=myconfig test.frotz nitfol &&
1053        test -h myconfig &&
1054        test -f notyet &&
1055        test "z$(git config --file=notyet test.frotz)" = znitfol &&
1056        git config --file=myconfig test.xyzzy rezrov &&
1057        test -h myconfig &&
1058        test -f notyet &&
1059        cat >expect <<-\EOF &&
1060        nitfol
1061        rezrov
1062        EOF
1063        {
1064                git config --file=notyet test.frotz &&
1065                git config --file=notyet test.xyzzy
1066        } >actual &&
1067        test_cmp expect actual
1068'
1069
1070test_expect_success 'nonexistent configuration' '
1071        test_must_fail git config --file=doesnotexist --list &&
1072        test_must_fail git config --file=doesnotexist test.xyzzy
1073'
1074
1075test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
1076        ln -s doesnotexist linktonada &&
1077        ln -s linktonada linktolinktonada &&
1078        test_must_fail git config --file=linktonada --list &&
1079        test_must_fail git config --file=linktolinktonada --list
1080'
1081
1082test_expect_success 'check split_cmdline return' "
1083        git config alias.split-cmdline-fix 'echo \"' &&
1084        test_must_fail git split-cmdline-fix &&
1085        echo foo > foo &&
1086        git add foo &&
1087        git commit -m 'initial commit' &&
1088        git config branch.master.mergeoptions 'echo \"' &&
1089        test_must_fail git merge master
1090"
1091
1092test_expect_success 'git -c "key=value" support' '
1093        cat >expect <<-\EOF &&
1094        value
1095        value
1096        true
1097        EOF
1098        {
1099                git -c core.name=value config core.name &&
1100                git -c foo.CamelCase=value config foo.camelcase &&
1101                git -c foo.flag config --bool foo.flag
1102        } >actual &&
1103        test_cmp expect actual &&
1104        test_must_fail git -c name=value config core.name
1105'
1106
1107# We just need a type-specifier here that cares about the
1108# distinction internally between a NULL boolean and a real
1109# string (because most of git's internal parsers do care).
1110# Using "--path" works, but we do not otherwise care about
1111# its semantics.
1112test_expect_success 'git -c can represent empty string' '
1113        echo >expect &&
1114        git -c foo.empty= config --path foo.empty >actual &&
1115        test_cmp expect actual
1116'
1117
1118test_expect_success 'key sanity-checking' '
1119        test_must_fail git config foo=bar &&
1120        test_must_fail git config foo=.bar &&
1121        test_must_fail git config foo.ba=r &&
1122        test_must_fail git config foo.1bar &&
1123        test_must_fail git config foo."ba
1124                                z".bar &&
1125        test_must_fail git config . false &&
1126        test_must_fail git config .foo false &&
1127        test_must_fail git config foo. false &&
1128        test_must_fail git config .foo. false &&
1129        git config foo.bar true &&
1130        git config foo."ba =z".bar false
1131'
1132
1133test_expect_success 'git -c works with aliases of builtins' '
1134        git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1135        echo bar >expect &&
1136        git checkconfig >actual &&
1137        test_cmp expect actual
1138'
1139
1140test_expect_success 'aliases can be CamelCased' '
1141        test_config alias.CamelCased "rev-parse HEAD" &&
1142        git CamelCased >out &&
1143        git rev-parse HEAD >expect &&
1144        test_cmp expect out
1145'
1146
1147test_expect_success 'git -c does not split values on equals' '
1148        echo "value with = in it" >expect &&
1149        git -c core.foo="value with = in it" config core.foo >actual &&
1150        test_cmp expect actual
1151'
1152
1153test_expect_success 'git -c dies on bogus config' '
1154        test_must_fail git -c core.bare=foo rev-parse
1155'
1156
1157test_expect_success 'git -c complains about empty key' '
1158        test_must_fail git -c "=foo" rev-parse
1159'
1160
1161test_expect_success 'git -c complains about empty key and value' '
1162        test_must_fail git -c "" rev-parse
1163'
1164
1165test_expect_success 'multiple git -c appends config' '
1166        test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" &&
1167        cat >expect <<-\EOF &&
1168        x.one 1
1169        x.two 2
1170        EOF
1171        git -c x.one=1 x >actual &&
1172        test_cmp expect actual
1173'
1174
1175test_expect_success 'last one wins: two level vars' '
1176
1177        # sec.var and sec.VAR are the same variable, as the first
1178        # and the last level of a configuration variable name is
1179        # case insensitive.
1180
1181        echo VAL >expect &&
1182
1183        git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual &&
1184        test_cmp expect actual &&
1185        git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual &&
1186        test_cmp expect actual &&
1187
1188        git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual &&
1189        test_cmp expect actual &&
1190        git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual &&
1191        test_cmp expect actual
1192'
1193
1194test_expect_success 'last one wins: three level vars' '
1195
1196        # v.a.r and v.A.r are not the same variable, as the middle
1197        # level of a three-level configuration variable name is
1198        # case sensitive.
1199
1200        echo val >expect &&
1201        git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual &&
1202        test_cmp expect actual &&
1203        git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual &&
1204        test_cmp expect actual &&
1205
1206        # v.a.r and V.a.R are the same variable, as the first
1207        # and the last level of a configuration variable name is
1208        # case insensitive.
1209
1210        echo VAL >expect &&
1211        git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual &&
1212        test_cmp expect actual &&
1213        git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual &&
1214        test_cmp expect actual &&
1215        git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual &&
1216        test_cmp expect actual &&
1217        git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual &&
1218        test_cmp expect actual
1219'
1220
1221for VAR in a .a a. a.0b a."b c". a."b c".0d
1222do
1223        test_expect_success "git -c $VAR=VAL rejects invalid '$VAR'" '
1224                test_must_fail git -c "$VAR=VAL" config -l
1225        '
1226done
1227
1228for VAR in a.b a."b c".d
1229do
1230        test_expect_success "git -c $VAR=VAL works with valid '$VAR'" '
1231                echo VAL >expect &&
1232                git -c "$VAR=VAL" config --get "$VAR" >actual &&
1233                test_cmp expect actual
1234        '
1235done
1236
1237test_expect_success 'git -c is not confused by empty environment' '
1238        GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
1239'
1240
1241sq="'"
1242test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' '
1243        cat >expect <<-\EOF &&
1244        env.one one
1245        env.two two
1246        EOF
1247        GIT_CONFIG_PARAMETERS="${sq}env.one=one${sq} ${sq}env.two=two${sq}" \
1248                git config --get-regexp "env.*" >actual &&
1249        test_cmp expect actual &&
1250
1251        cat >expect <<-EOF &&
1252        env.one one${sq}
1253        env.two two
1254        EOF
1255        GIT_CONFIG_PARAMETERS="${sq}env.one=one${sq}\\$sq$sq$sq ${sq}env.two=two${sq}" \
1256                git config --get-regexp "env.*" >actual &&
1257        test_cmp expect actual &&
1258
1259        test_must_fail env \
1260                GIT_CONFIG_PARAMETERS="${sq}env.one=one${sq}\\$sq ${sq}env.two=two${sq}" \
1261                git config --get-regexp "env.*"
1262'
1263
1264test_expect_success 'git config --edit works' '
1265        git config -f tmp test.value no &&
1266        echo test.value=yes >expect &&
1267        GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1268        git config -f tmp --list >actual &&
1269        test_cmp expect actual
1270'
1271
1272test_expect_success 'git config --edit respects core.editor' '
1273        git config -f tmp test.value no &&
1274        echo test.value=yes >expect &&
1275        test_config core.editor "echo [test]value=yes >" &&
1276        git config -f tmp --edit &&
1277        git config -f tmp --list >actual &&
1278        test_cmp expect actual
1279'
1280
1281# malformed configuration files
1282test_expect_success 'barf on syntax error' '
1283        cat >.git/config <<-\EOF &&
1284        # broken section line
1285        [section]
1286        key garbage
1287        EOF
1288        test_must_fail git config --get section.key >actual 2>error &&
1289        test_i18ngrep " line 3 " error
1290'
1291
1292test_expect_success 'barf on incomplete section header' '
1293        cat >.git/config <<-\EOF &&
1294        # broken section line
1295        [section
1296        key = value
1297        EOF
1298        test_must_fail git config --get section.key >actual 2>error &&
1299        test_i18ngrep " line 2 " error
1300'
1301
1302test_expect_success 'barf on incomplete string' '
1303        cat >.git/config <<-\EOF &&
1304        # broken section line
1305        [section]
1306        key = "value string
1307        EOF
1308        test_must_fail git config --get section.key >actual 2>error &&
1309        test_i18ngrep " line 3 " error
1310'
1311
1312test_expect_success 'urlmatch' '
1313        cat >.git/config <<-\EOF &&
1314        [http]
1315                sslVerify
1316        [http "https://weak.example.com"]
1317                sslVerify = false
1318                cookieFile = /tmp/cookie.txt
1319        EOF
1320
1321        test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1322        test_must_be_empty actual &&
1323
1324        echo true >expect &&
1325        git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1326        test_cmp expect actual &&
1327
1328        echo false >expect &&
1329        git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1330        test_cmp expect actual &&
1331
1332        {
1333                echo http.cookiefile /tmp/cookie.txt &&
1334                echo http.sslverify false
1335        } >expect &&
1336        git config --get-urlmatch HTTP https://weak.example.com >actual &&
1337        test_cmp expect actual
1338'
1339
1340test_expect_success 'urlmatch favors more specific URLs' '
1341        cat >.git/config <<-\EOF &&
1342        [http "https://example.com/"]
1343                cookieFile = /tmp/root.txt
1344        [http "https://example.com/subdirectory"]
1345                cookieFile = /tmp/subdirectory.txt
1346        [http "https://user@example.com/"]
1347                cookieFile = /tmp/user.txt
1348        [http "https://averylonguser@example.com/"]
1349                cookieFile = /tmp/averylonguser.txt
1350        [http "https://preceding.example.com"]
1351                cookieFile = /tmp/preceding.txt
1352        [http "https://*.example.com"]
1353                cookieFile = /tmp/wildcard.txt
1354        [http "https://*.example.com/wildcardwithsubdomain"]
1355                cookieFile = /tmp/wildcardwithsubdomain.txt
1356        [http "https://trailing.example.com"]
1357                cookieFile = /tmp/trailing.txt
1358        [http "https://user@*.example.com/"]
1359                cookieFile = /tmp/wildcardwithuser.txt
1360        [http "https://sub.example.com/"]
1361                cookieFile = /tmp/sub.txt
1362        EOF
1363
1364        echo http.cookiefile /tmp/root.txt >expect &&
1365        git config --get-urlmatch HTTP https://example.com >actual &&
1366        test_cmp expect actual &&
1367
1368        echo http.cookiefile /tmp/subdirectory.txt >expect &&
1369        git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
1370        test_cmp expect actual &&
1371
1372        echo http.cookiefile /tmp/subdirectory.txt >expect &&
1373        git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
1374        test_cmp expect actual &&
1375
1376        echo http.cookiefile /tmp/user.txt >expect &&
1377        git config --get-urlmatch HTTP https://user@example.com/ >actual &&
1378        test_cmp expect actual &&
1379
1380        echo http.cookiefile /tmp/subdirectory.txt >expect &&
1381        git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual &&
1382        test_cmp expect actual &&
1383
1384        echo http.cookiefile /tmp/preceding.txt >expect &&
1385        git config --get-urlmatch HTTP https://preceding.example.com >actual &&
1386        test_cmp expect actual &&
1387
1388        echo http.cookiefile /tmp/wildcard.txt >expect &&
1389        git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
1390        test_cmp expect actual &&
1391
1392        echo http.cookiefile /tmp/sub.txt >expect &&
1393        git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
1394        test_cmp expect actual &&
1395
1396        echo http.cookiefile /tmp/trailing.txt >expect &&
1397        git config --get-urlmatch HTTP https://trailing.example.com >actual &&
1398        test_cmp expect actual &&
1399
1400        echo http.cookiefile /tmp/sub.txt >expect &&
1401        git config --get-urlmatch HTTP https://user@sub.example.com >actual &&
1402        test_cmp expect actual
1403'
1404
1405test_expect_success 'urlmatch with wildcard' '
1406        cat >.git/config <<-\EOF &&
1407        [http]
1408                sslVerify
1409        [http "https://*.example.com"]
1410                sslVerify = false
1411                cookieFile = /tmp/cookie.txt
1412        EOF
1413
1414        test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1415        test_must_be_empty actual &&
1416
1417        echo true >expect &&
1418        git config --bool --get-urlmatch http.SSLverify https://example.com >actual &&
1419        test_cmp expect actual &&
1420
1421        echo true >expect &&
1422        git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual &&
1423        test_cmp expect actual &&
1424
1425        echo true >expect &&
1426        git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual &&
1427        test_cmp expect actual &&
1428
1429        echo false >expect &&
1430        git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
1431        test_cmp expect actual &&
1432
1433        {
1434                echo http.cookiefile /tmp/cookie.txt &&
1435                echo http.sslverify false
1436        } >expect &&
1437        git config --get-urlmatch HTTP https://good.example.com >actual &&
1438        test_cmp expect actual &&
1439
1440        echo http.sslverify >expect &&
1441        git config --get-urlmatch HTTP https://more.example.com.au >actual &&
1442        test_cmp expect actual
1443'
1444
1445# good section hygiene
1446test_expect_success '--unset last key removes section (except if commented)' '
1447        cat >.git/config <<-\EOF &&
1448        # some generic comment on the configuration file itself
1449        # a comment specific to this "section" section.
1450        [section]
1451        # some intervening lines
1452        # that should also be dropped
1453
1454        key = value
1455        # please be careful when you update the above variable
1456        EOF
1457
1458        cat >expect <<-\EOF &&
1459        # some generic comment on the configuration file itself
1460        # a comment specific to this "section" section.
1461        [section]
1462        # some intervening lines
1463        # that should also be dropped
1464
1465        # please be careful when you update the above variable
1466        EOF
1467
1468        git config --unset section.key &&
1469        test_cmp expect .git/config &&
1470
1471        cat >.git/config <<-\EOF &&
1472        [section]
1473        key = value
1474        [next-section]
1475        EOF
1476
1477        cat >expect <<-\EOF &&
1478        [next-section]
1479        EOF
1480
1481        git config --unset section.key &&
1482        test_cmp expect .git/config &&
1483
1484        q_to_tab >.git/config <<-\EOF &&
1485        [one]
1486        Qkey = "multiline \
1487        QQ# with comment"
1488        [two]
1489        key = true
1490        EOF
1491        git config --unset two.key &&
1492        ! grep two .git/config &&
1493
1494        q_to_tab >.git/config <<-\EOF &&
1495        [one]
1496        Qkey = "multiline \
1497        QQ# with comment"
1498        [one]
1499        key = true
1500        EOF
1501        git config --unset-all one.key &&
1502        test_line_count = 0 .git/config &&
1503
1504        q_to_tab >.git/config <<-\EOF &&
1505        [one]
1506        Qkey = true
1507        Q# a comment not at the start
1508        [two]
1509        Qkey = true
1510        EOF
1511        git config --unset two.key &&
1512        grep two .git/config &&
1513
1514        q_to_tab >.git/config <<-\EOF &&
1515        [one]
1516        Qkey = not [two "subsection"]
1517        [two "subsection"]
1518        [two "subsection"]
1519        Qkey = true
1520        [TWO "subsection"]
1521        [one]
1522        EOF
1523        git config --unset two.subsection.key &&
1524        test "not [two subsection]" = "$(git config one.key)" &&
1525        test_line_count = 3 .git/config
1526'
1527
1528test_expect_success '--unset-all removes section if empty & uncommented' '
1529        cat >.git/config <<-\EOF &&
1530        [section]
1531        key = value1
1532        key = value2
1533        EOF
1534
1535        git config --unset-all section.key &&
1536        test_line_count = 0 .git/config
1537'
1538
1539test_expect_success 'adding a key into an empty section reuses header' '
1540        cat >.git/config <<-\EOF &&
1541        [section]
1542        EOF
1543
1544        q_to_tab >expect <<-\EOF &&
1545        [section]
1546        Qkey = value
1547        EOF
1548
1549        git config section.key value &&
1550        test_cmp expect .git/config
1551'
1552
1553test_expect_success POSIXPERM,PERL 'preserves existing permissions' '
1554        chmod 0600 .git/config &&
1555        git config imap.pass Hunter2 &&
1556        perl -e \
1557          "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
1558        git config --rename-section imap pop &&
1559        perl -e \
1560          "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
1561'
1562
1563! test_have_prereq MINGW ||
1564HOME="$(pwd)" # convert to Windows path
1565
1566test_expect_success 'set up --show-origin tests' '
1567        INCLUDE_DIR="$HOME/include" &&
1568        mkdir -p "$INCLUDE_DIR" &&
1569        cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
1570                [user]
1571                        absolute = include
1572        EOF
1573        cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
1574                [user]
1575                        relative = include
1576        EOF
1577        cat >"$HOME"/.gitconfig <<-EOF &&
1578                [user]
1579                        global = true
1580                        override = global
1581                [include]
1582                        path = "$INCLUDE_DIR/absolute.include"
1583        EOF
1584        cat >.git/config <<-\EOF
1585                [user]
1586                        local = true
1587                        override = local
1588                [include]
1589                        path = ../include/relative.include
1590        EOF
1591'
1592
1593test_expect_success '--show-origin with --list' '
1594        cat >expect <<-EOF &&
1595                file:$HOME/.gitconfig   user.global=true
1596                file:$HOME/.gitconfig   user.override=global
1597                file:$HOME/.gitconfig   include.path=$INCLUDE_DIR/absolute.include
1598                file:$INCLUDE_DIR/absolute.include      user.absolute=include
1599                file:.git/config        user.local=true
1600                file:.git/config        user.override=local
1601                file:.git/config        include.path=../include/relative.include
1602                file:.git/../include/relative.include   user.relative=include
1603                command line:   user.cmdline=true
1604        EOF
1605        git -c user.cmdline=true config --list --show-origin >output &&
1606        test_cmp expect output
1607'
1608
1609test_expect_success '--show-origin with --list --null' '
1610        cat >expect <<-EOF &&
1611                file:$HOME/.gitconfigQuser.global
1612                trueQfile:$HOME/.gitconfigQuser.override
1613                globalQfile:$HOME/.gitconfigQinclude.path
1614                $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
1615                includeQfile:.git/configQuser.local
1616                trueQfile:.git/configQuser.override
1617                localQfile:.git/configQinclude.path
1618                ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
1619                includeQcommand line:Quser.cmdline
1620                trueQ
1621        EOF
1622        git -c user.cmdline=true config --null --list --show-origin >output.raw &&
1623        nul_to_q <output.raw >output &&
1624        # The here-doc above adds a newline that the --null output would not
1625        # include. Add it here to make the two comparable.
1626        echo >>output &&
1627        test_cmp expect output
1628'
1629
1630test_expect_success '--show-origin with single file' '
1631        cat >expect <<-\EOF &&
1632                file:.git/config        user.local=true
1633                file:.git/config        user.override=local
1634                file:.git/config        include.path=../include/relative.include
1635        EOF
1636        git config --local --list --show-origin >output &&
1637        test_cmp expect output
1638'
1639
1640test_expect_success '--show-origin with --get-regexp' '
1641        cat >expect <<-EOF &&
1642                file:$HOME/.gitconfig   user.global true
1643                file:.git/config        user.local true
1644        EOF
1645        git config --show-origin --get-regexp "user\.[g|l].*" >output &&
1646        test_cmp expect output
1647'
1648
1649test_expect_success '--show-origin getting a single key' '
1650        cat >expect <<-\EOF &&
1651                file:.git/config        local
1652        EOF
1653        git config --show-origin user.override >output &&
1654        test_cmp expect output
1655'
1656
1657test_expect_success 'set up custom config file' '
1658        CUSTOM_CONFIG_FILE="file\" (dq) and spaces.conf" &&
1659        cat >"$CUSTOM_CONFIG_FILE" <<-\EOF
1660                [user]
1661                        custom = true
1662        EOF
1663'
1664
1665test_expect_success !MINGW '--show-origin escape special file name characters' '
1666        cat >expect <<-\EOF &&
1667                file:"file\" (dq) and spaces.conf"      user.custom=true
1668        EOF
1669        git config --file "$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
1670        test_cmp expect output
1671'
1672
1673test_expect_success '--show-origin stdin' '
1674        cat >expect <<-\EOF &&
1675                standard input: user.custom=true
1676        EOF
1677        git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
1678        test_cmp expect output
1679'
1680
1681test_expect_success '--show-origin stdin with file include' '
1682        cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
1683                [user]
1684                        stdin = include
1685        EOF
1686        cat >expect <<-EOF &&
1687                file:$INCLUDE_DIR/stdin.include include
1688        EOF
1689        echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" \
1690                | git config --show-origin --includes --file - user.stdin >output &&
1691        test_cmp expect output
1692'
1693
1694test_expect_success !MINGW '--show-origin blob' '
1695        blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
1696        cat >expect <<-EOF &&
1697                blob:$blob      user.custom=true
1698        EOF
1699        git config --blob=$blob --show-origin --list >output &&
1700        test_cmp expect output
1701'
1702
1703test_expect_success !MINGW '--show-origin blob ref' '
1704        cat >expect <<-\EOF &&
1705                blob:"master:file\" (dq) and spaces.conf"       user.custom=true
1706        EOF
1707        git add "$CUSTOM_CONFIG_FILE" &&
1708        git commit -m "new config file" &&
1709        git config --blob=master:"$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
1710        test_cmp expect output
1711'
1712
1713test_expect_success '--local requires a repo' '
1714        # we expect 128 to ensure that we do not simply
1715        # fail to find anything and return code "1"
1716        test_expect_code 128 nongit git config --local foo.bar
1717'
1718
1719cat >.git/config <<-\EOF &&
1720[core]
1721foo = true
1722number = 10
1723big = 1M
1724EOF
1725
1726test_expect_success 'identical modern --type specifiers are allowed' '
1727        git config --type=int --type=int core.big >actual &&
1728        echo 1048576 >expect &&
1729        test_cmp expect actual
1730'
1731
1732test_expect_success 'identical legacy --type specifiers are allowed' '
1733        git config --int --int core.big >actual &&
1734        echo 1048576 >expect &&
1735        test_cmp expect actual
1736'
1737
1738test_expect_success 'identical mixed --type specifiers are allowed' '
1739        git config --int --type=int core.big >actual &&
1740        echo 1048576 >expect &&
1741        test_cmp expect actual
1742'
1743
1744test_expect_success 'non-identical modern --type specifiers are not allowed' '
1745        test_must_fail git config --type=int --type=bool core.big 2>error &&
1746        test_i18ngrep "only one type at a time" error
1747'
1748
1749test_expect_success 'non-identical legacy --type specifiers are not allowed' '
1750        test_must_fail git config --int --bool core.big 2>error &&
1751        test_i18ngrep "only one type at a time" error
1752'
1753
1754test_expect_success 'non-identical mixed --type specifiers are not allowed' '
1755        test_must_fail git config --type=int --bool core.big 2>error &&
1756        test_i18ngrep "only one type at a time" error
1757'
1758
1759test_expect_success '--type allows valid type specifiers' '
1760        echo "true" >expect &&
1761        git config --type=bool core.foo >actual &&
1762        test_cmp expect actual
1763'
1764
1765test_expect_success '--no-type unsets type specifiers' '
1766        echo "10" >expect &&
1767        git config --type=bool --no-type core.number >actual &&
1768        test_cmp expect actual
1769'
1770
1771test_expect_success 'unset type specifiers may be reset to conflicting ones' '
1772        echo 1048576 >expect &&
1773        git config --type=bool --no-type --type=int core.big >actual &&
1774        test_cmp expect actual
1775'
1776
1777test_expect_success '--type rejects unknown specifiers' '
1778        test_must_fail git config --type=nonsense core.foo 2>error &&
1779        test_i18ngrep "unrecognized --type argument" error
1780'
1781
1782test_expect_success '--replace-all does not invent newlines' '
1783        q_to_tab >.git/config <<-\EOF &&
1784        [abc]key
1785        QkeepSection
1786        [xyz]
1787        Qkey = 1
1788        [abc]
1789        Qkey = a
1790        EOF
1791        q_to_tab >expect <<-\EOF &&
1792        [abc]
1793        QkeepSection
1794        [xyz]
1795        Qkey = 1
1796        [abc]
1797        Qkey = b
1798        EOF
1799        git config --replace-all abc.key b &&
1800        test_cmp .git/config expect
1801'
1802
1803test_done