51dd5b58bf63a286a9b0d6832be27350a37d232c
   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
 111EOF
 112
 113test_expect_success 'unset with cont. lines' '
 114        git config --unset beta.baz
 115'
 116
 117cat > expect <<\EOF
 118[alpha]
 119bar = foo
 120[beta]
 121EOF
 122
 123test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config'
 124
 125cat > .git/config << EOF
 126[beta] ; silly comment # another comment
 127noIndent= sillyValue ; 'nother silly comment
 128
 129# empty line
 130                ; comment
 131                haha   ="beta" # last silly comment
 132haha = hello
 133        haha = bello
 134[nextSection] noNewline = ouch
 135EOF
 136
 137cp .git/config .git/config2
 138
 139test_expect_success 'multiple unset' '
 140        git config --unset-all beta.haha
 141'
 142
 143cat > expect << EOF
 144[beta] ; silly comment # another comment
 145noIndent= sillyValue ; 'nother silly comment
 146
 147# empty line
 148                ; comment
 149[nextSection] noNewline = ouch
 150EOF
 151
 152test_expect_success 'multiple unset is correct' '
 153        test_cmp expect .git/config
 154'
 155
 156cp .git/config2 .git/config
 157
 158test_expect_success '--replace-all missing value' '
 159        test_must_fail git config --replace-all beta.haha &&
 160        test_cmp .git/config2 .git/config
 161'
 162
 163rm .git/config2
 164
 165test_expect_success '--replace-all' '
 166        git config --replace-all beta.haha gamma
 167'
 168
 169cat > expect << EOF
 170[beta] ; silly comment # another comment
 171noIndent= sillyValue ; 'nother silly comment
 172
 173# empty line
 174                ; comment
 175        haha = gamma
 176[nextSection] noNewline = ouch
 177EOF
 178
 179test_expect_success 'all replaced' '
 180        test_cmp expect .git/config
 181'
 182
 183cat > expect << EOF
 184[beta] ; silly comment # another comment
 185noIndent= sillyValue ; 'nother silly comment
 186
 187# empty line
 188                ; comment
 189        haha = alpha
 190[nextSection] noNewline = ouch
 191EOF
 192test_expect_success 'really mean test' '
 193        git config beta.haha alpha &&
 194        test_cmp expect .git/config
 195'
 196
 197cat > expect << EOF
 198[beta] ; silly comment # another comment
 199noIndent= sillyValue ; 'nother silly comment
 200
 201# empty line
 202                ; comment
 203        haha = alpha
 204[nextSection]
 205        nonewline = wow
 206EOF
 207test_expect_success 'really really mean test' '
 208        git config nextsection.nonewline wow &&
 209        test_cmp expect .git/config
 210'
 211
 212test_expect_success 'get value' '
 213        echo alpha >expect &&
 214        git config beta.haha >actual &&
 215        test_cmp expect actual
 216'
 217
 218cat > expect << EOF
 219[beta] ; silly comment # another comment
 220noIndent= sillyValue ; 'nother silly comment
 221
 222# empty line
 223                ; comment
 224[nextSection]
 225        nonewline = wow
 226EOF
 227test_expect_success 'unset' '
 228        git config --unset beta.haha &&
 229        test_cmp expect .git/config
 230'
 231
 232cat > expect << EOF
 233[beta] ; silly comment # another comment
 234noIndent= sillyValue ; 'nother silly comment
 235
 236# empty line
 237                ; comment
 238[nextSection]
 239        nonewline = wow
 240        NoNewLine = wow2 for me
 241EOF
 242test_expect_success 'multivar' '
 243        git config nextsection.NoNewLine "wow2 for me" "for me$" &&
 244        test_cmp expect .git/config
 245'
 246
 247test_expect_success 'non-match' '
 248        git config --get nextsection.nonewline !for
 249'
 250
 251test_expect_success 'non-match value' '
 252        echo wow >expect &&
 253        git config --get nextsection.nonewline !for >actual &&
 254        test_cmp expect actual
 255'
 256
 257test_expect_success 'ambiguous get' '
 258        test_must_fail git config --get nextsection.nonewline
 259'
 260
 261test_expect_success 'multi-valued get-all returns all' '
 262        cat >expect <<-\EOF &&
 263        wow
 264        wow2 for me
 265        EOF
 266        git config --get-all nextsection.nonewline >actual &&
 267        test_cmp expect actual
 268'
 269
 270cat > expect << EOF
 271[beta] ; silly comment # another comment
 272noIndent= sillyValue ; 'nother silly comment
 273
 274# empty line
 275                ; comment
 276[nextSection]
 277        nonewline = wow3
 278        NoNewLine = wow2 for me
 279EOF
 280test_expect_success 'multivar replace' '
 281        git config nextsection.nonewline "wow3" "wow$" &&
 282        test_cmp expect .git/config
 283'
 284
 285test_expect_success 'ambiguous unset' '
 286        test_must_fail git config --unset nextsection.nonewline
 287'
 288
 289test_expect_success 'invalid unset' '
 290        test_must_fail git config --unset somesection.nonewline
 291'
 292
 293cat > expect << EOF
 294[beta] ; silly comment # another comment
 295noIndent= sillyValue ; 'nother silly comment
 296
 297# empty line
 298                ; comment
 299[nextSection]
 300        NoNewLine = wow2 for me
 301EOF
 302
 303test_expect_success 'multivar unset' '
 304        git config --unset nextsection.nonewline "wow3$" &&
 305        test_cmp expect .git/config
 306'
 307
 308test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
 309
 310test_expect_success 'correct key' 'git config 123456.a123 987'
 311
 312test_expect_success 'hierarchical section' '
 313        git config Version.1.2.3eX.Alpha beta
 314'
 315
 316cat > expect << EOF
 317[beta] ; silly comment # another comment
 318noIndent= sillyValue ; 'nother silly comment
 319
 320# empty line
 321                ; comment
 322[nextSection]
 323        NoNewLine = wow2 for me
 324[123456]
 325        a123 = 987
 326[Version "1.2.3eX"]
 327        Alpha = beta
 328EOF
 329
 330test_expect_success 'hierarchical section value' '
 331        test_cmp expect .git/config
 332'
 333
 334cat > expect << EOF
 335beta.noindent=sillyValue
 336nextsection.nonewline=wow2 for me
 337123456.a123=987
 338version.1.2.3eX.alpha=beta
 339EOF
 340
 341test_expect_success 'working --list' '
 342        git config --list > output &&
 343        test_cmp expect output
 344'
 345cat > expect << EOF
 346EOF
 347
 348test_expect_success '--list without repo produces empty output' '
 349        git --git-dir=nonexistent config --list >output &&
 350        test_cmp expect output
 351'
 352
 353cat > expect << EOF
 354beta.noindent sillyValue
 355nextsection.nonewline wow2 for me
 356EOF
 357
 358test_expect_success '--get-regexp' '
 359        git config --get-regexp in >output &&
 360        test_cmp expect output
 361'
 362
 363cat > expect << EOF
 364wow2 for me
 365wow4 for you
 366EOF
 367
 368test_expect_success '--add' '
 369        git config --add nextsection.nonewline "wow4 for you" &&
 370        git config --get-all nextsection.nonewline > output &&
 371        test_cmp expect output
 372'
 373
 374cat > .git/config << EOF
 375[novalue]
 376        variable
 377[emptyvalue]
 378        variable =
 379EOF
 380
 381test_expect_success 'get variable with no value' '
 382        git config --get novalue.variable ^$
 383'
 384
 385test_expect_success 'get variable with empty value' '
 386        git config --get emptyvalue.variable ^$
 387'
 388
 389echo novalue.variable > expect
 390
 391test_expect_success 'get-regexp variable with no value' '
 392        git config --get-regexp novalue > output &&
 393        test_cmp expect output
 394'
 395
 396echo 'novalue.variable true' > expect
 397
 398test_expect_success 'get-regexp --bool variable with no value' '
 399        git config --bool --get-regexp novalue > output &&
 400        test_cmp expect output
 401'
 402
 403echo 'emptyvalue.variable ' > expect
 404
 405test_expect_success 'get-regexp variable with empty value' '
 406        git config --get-regexp emptyvalue > output &&
 407        test_cmp expect output
 408'
 409
 410echo true > expect
 411
 412test_expect_success 'get bool variable with no value' '
 413        git config --bool novalue.variable > output &&
 414        test_cmp expect output
 415'
 416
 417echo false > expect
 418
 419test_expect_success 'get bool variable with empty value' '
 420        git config --bool emptyvalue.variable > output &&
 421        test_cmp expect output
 422'
 423
 424test_expect_success 'no arguments, but no crash' '
 425        test_must_fail git config >output 2>&1 &&
 426        test_i18ngrep usage output
 427'
 428
 429cat > .git/config << EOF
 430[a.b]
 431        c = d
 432EOF
 433
 434cat > expect << EOF
 435[a.b]
 436        c = d
 437[a]
 438        x = y
 439EOF
 440
 441test_expect_success 'new section is partial match of another' '
 442        git config a.x y &&
 443        test_cmp expect .git/config
 444'
 445
 446cat > expect << EOF
 447[a.b]
 448        c = d
 449[a]
 450        x = y
 451        b = c
 452[b]
 453        x = y
 454EOF
 455
 456test_expect_success 'new variable inserts into proper section' '
 457        git config b.x y &&
 458        git config a.b c &&
 459        test_cmp expect .git/config
 460'
 461
 462test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' '
 463        test_must_fail git config --file non-existing-config -l
 464'
 465
 466cat > other-config << EOF
 467[ein]
 468        bahn = strasse
 469EOF
 470
 471cat > expect << EOF
 472ein.bahn=strasse
 473EOF
 474
 475test_expect_success 'alternative GIT_CONFIG' '
 476        GIT_CONFIG=other-config git config -l >output &&
 477        test_cmp expect output
 478'
 479
 480test_expect_success 'alternative GIT_CONFIG (--file)' '
 481        git config --file other-config -l > output &&
 482        test_cmp expect output
 483'
 484
 485test_expect_success 'refer config from subdirectory' '
 486        mkdir x &&
 487        (
 488                cd x &&
 489                echo strasse >expect &&
 490                git config --get --file ../other-config ein.bahn >actual &&
 491                test_cmp expect actual
 492        )
 493
 494'
 495
 496test_expect_success 'refer config from subdirectory via GIT_CONFIG' '
 497        (
 498                cd x &&
 499                GIT_CONFIG=../other-config git config --get ein.bahn >actual &&
 500                test_cmp expect actual
 501        )
 502'
 503
 504cat > expect << EOF
 505[ein]
 506        bahn = strasse
 507[anwohner]
 508        park = ausweis
 509EOF
 510
 511test_expect_success '--set in alternative GIT_CONFIG' '
 512        GIT_CONFIG=other-config git config anwohner.park ausweis &&
 513        test_cmp expect other-config
 514'
 515
 516cat > .git/config << EOF
 517# Hallo
 518        #Bello
 519[branch "eins"]
 520        x = 1
 521[branch.eins]
 522        y = 1
 523        [branch "1 234 blabl/a"]
 524weird
 525EOF
 526
 527test_expect_success 'rename section' '
 528        git config --rename-section branch.eins branch.zwei
 529'
 530
 531cat > expect << EOF
 532# Hallo
 533        #Bello
 534[branch "zwei"]
 535        x = 1
 536[branch "zwei"]
 537        y = 1
 538        [branch "1 234 blabl/a"]
 539weird
 540EOF
 541
 542test_expect_success 'rename succeeded' '
 543        test_cmp expect .git/config
 544'
 545
 546test_expect_success 'rename non-existing section' '
 547        test_must_fail git config --rename-section \
 548                branch."world domination" branch.drei
 549'
 550
 551test_expect_success 'rename succeeded' '
 552        test_cmp expect .git/config
 553'
 554
 555test_expect_success 'rename another section' '
 556        git config --rename-section branch."1 234 blabl/a" branch.drei
 557'
 558
 559cat > expect << EOF
 560# Hallo
 561        #Bello
 562[branch "zwei"]
 563        x = 1
 564[branch "zwei"]
 565        y = 1
 566[branch "drei"]
 567weird
 568EOF
 569
 570test_expect_success 'rename succeeded' '
 571        test_cmp expect .git/config
 572'
 573
 574cat >> .git/config << EOF
 575[branch "vier"] z = 1
 576EOF
 577
 578test_expect_success 'rename a section with a var on the same line' '
 579        git config --rename-section branch.vier branch.zwei
 580'
 581
 582cat > expect << EOF
 583# Hallo
 584        #Bello
 585[branch "zwei"]
 586        x = 1
 587[branch "zwei"]
 588        y = 1
 589[branch "drei"]
 590weird
 591[branch "zwei"]
 592        z = 1
 593EOF
 594
 595test_expect_success 'rename succeeded' '
 596        test_cmp expect .git/config
 597'
 598
 599test_expect_success 'renaming empty section name is rejected' '
 600        test_must_fail git config --rename-section branch.zwei ""
 601'
 602
 603test_expect_success 'renaming to bogus section is rejected' '
 604        test_must_fail git config --rename-section branch.zwei "bogus name"
 605'
 606
 607cat >> .git/config << EOF
 608  [branch "zwei"] a = 1 [branch "vier"]
 609EOF
 610
 611test_expect_success 'remove section' '
 612        git config --remove-section branch.zwei
 613'
 614
 615cat > expect << EOF
 616# Hallo
 617        #Bello
 618[branch "drei"]
 619weird
 620EOF
 621
 622test_expect_success 'section was removed properly' '
 623        test_cmp expect .git/config
 624'
 625
 626cat > expect << EOF
 627[gitcvs]
 628        enabled = true
 629        dbname = %Ggitcvs2.%a.%m.sqlite
 630[gitcvs "ext"]
 631        dbname = %Ggitcvs1.%a.%m.sqlite
 632EOF
 633
 634test_expect_success 'section ending' '
 635        rm -f .git/config &&
 636        git config gitcvs.enabled true &&
 637        git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
 638        git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
 639        test_cmp expect .git/config
 640
 641'
 642
 643test_expect_success numbers '
 644        git config kilo.gram 1k &&
 645        git config mega.ton 1m &&
 646        echo 1024 >expect &&
 647        echo 1048576 >>expect &&
 648        git config --int --get kilo.gram >actual &&
 649        git config --int --get mega.ton >>actual &&
 650        test_cmp expect actual
 651'
 652
 653test_expect_success 'invalid unit' '
 654        git config aninvalid.unit "1auto" &&
 655        echo 1auto >expect &&
 656        git config aninvalid.unit >actual &&
 657        test_cmp expect actual &&
 658        cat > expect <<-\EOF
 659        fatal: bad config value for '\''aninvalid.unit'\'' in .git/config
 660        EOF
 661        test_must_fail git config --int --get aninvalid.unit 2>actual &&
 662        test_cmp actual expect
 663'
 664
 665cat > expect << EOF
 666true
 667false
 668true
 669false
 670true
 671false
 672true
 673false
 674EOF
 675
 676test_expect_success bool '
 677
 678        git config bool.true1 01 &&
 679        git config bool.true2 -1 &&
 680        git config bool.true3 YeS &&
 681        git config bool.true4 true &&
 682        git config bool.false1 000 &&
 683        git config bool.false2 "" &&
 684        git config bool.false3 nO &&
 685        git config bool.false4 FALSE &&
 686        rm -f result &&
 687        for i in 1 2 3 4
 688        do
 689            git config --bool --get bool.true$i >>result
 690            git config --bool --get bool.false$i >>result
 691        done &&
 692        test_cmp expect result'
 693
 694test_expect_success 'invalid bool (--get)' '
 695
 696        git config bool.nobool foobar &&
 697        test_must_fail git config --bool --get bool.nobool'
 698
 699test_expect_success 'invalid bool (set)' '
 700
 701        test_must_fail git config --bool bool.nobool foobar'
 702
 703cat > expect <<\EOF
 704[bool]
 705        true1 = true
 706        true2 = true
 707        true3 = true
 708        true4 = true
 709        false1 = false
 710        false2 = false
 711        false3 = false
 712        false4 = false
 713EOF
 714
 715test_expect_success 'set --bool' '
 716
 717        rm -f .git/config &&
 718        git config --bool bool.true1 01 &&
 719        git config --bool bool.true2 -1 &&
 720        git config --bool bool.true3 YeS &&
 721        git config --bool bool.true4 true &&
 722        git config --bool bool.false1 000 &&
 723        git config --bool bool.false2 "" &&
 724        git config --bool bool.false3 nO &&
 725        git config --bool bool.false4 FALSE &&
 726        test_cmp expect .git/config'
 727
 728cat > expect <<\EOF
 729[int]
 730        val1 = 1
 731        val2 = -1
 732        val3 = 5242880
 733EOF
 734
 735test_expect_success 'set --int' '
 736
 737        rm -f .git/config &&
 738        git config --int int.val1 01 &&
 739        git config --int int.val2 -1 &&
 740        git config --int int.val3 5m &&
 741        test_cmp expect .git/config
 742'
 743
 744test_expect_success 'get --bool-or-int' '
 745        cat >.git/config <<-\EOF &&
 746        [bool]
 747        true1
 748        true2 = true
 749        false = false
 750        [int]
 751        int1 = 0
 752        int2 = 1
 753        int3 = -1
 754        EOF
 755        cat >expect <<-\EOF &&
 756        true
 757        true
 758        false
 759        0
 760        1
 761        -1
 762        EOF
 763        {
 764                git config --bool-or-int bool.true1 &&
 765                git config --bool-or-int bool.true2 &&
 766                git config --bool-or-int bool.false &&
 767                git config --bool-or-int int.int1 &&
 768                git config --bool-or-int int.int2 &&
 769                git config --bool-or-int int.int3
 770        } >actual &&
 771        test_cmp expect actual
 772'
 773
 774cat >expect <<\EOF
 775[bool]
 776        true1 = true
 777        false1 = false
 778        true2 = true
 779        false2 = false
 780[int]
 781        int1 = 0
 782        int2 = 1
 783        int3 = -1
 784EOF
 785
 786test_expect_success 'set --bool-or-int' '
 787        rm -f .git/config &&
 788        git config --bool-or-int bool.true1 true &&
 789        git config --bool-or-int bool.false1 false &&
 790        git config --bool-or-int bool.true2 yes &&
 791        git config --bool-or-int bool.false2 no &&
 792        git config --bool-or-int int.int1 0 &&
 793        git config --bool-or-int int.int2 1 &&
 794        git config --bool-or-int int.int3 -1 &&
 795        test_cmp expect .git/config
 796'
 797
 798cat >expect <<\EOF
 799[path]
 800        home = ~/
 801        normal = /dev/null
 802        trailingtilde = foo~
 803EOF
 804
 805test_expect_success NOT_MINGW 'set --path' '
 806        rm -f .git/config &&
 807        git config --path path.home "~/" &&
 808        git config --path path.normal "/dev/null" &&
 809        git config --path path.trailingtilde "foo~" &&
 810        test_cmp expect .git/config'
 811
 812if test_have_prereq NOT_MINGW && test "${HOME+set}"
 813then
 814        test_set_prereq HOMEVAR
 815fi
 816
 817cat >expect <<EOF
 818$HOME/
 819/dev/null
 820foo~
 821EOF
 822
 823test_expect_success HOMEVAR 'get --path' '
 824        git config --get --path path.home > result &&
 825        git config --get --path path.normal >> result &&
 826        git config --get --path path.trailingtilde >> result &&
 827        test_cmp expect result
 828'
 829
 830cat >expect <<\EOF
 831/dev/null
 832foo~
 833EOF
 834
 835test_expect_success NOT_MINGW 'get --path copes with unset $HOME' '
 836        (
 837                unset HOME;
 838                test_must_fail git config --get --path path.home \
 839                        >result 2>msg &&
 840                git config --get --path path.normal >>result &&
 841                git config --get --path path.trailingtilde >>result
 842        ) &&
 843        grep "[Ff]ailed to expand.*~/" msg &&
 844        test_cmp expect result
 845'
 846
 847cat > expect << EOF
 848[quote]
 849        leading = " test"
 850        ending = "test "
 851        semicolon = "test;test"
 852        hash = "test#test"
 853EOF
 854test_expect_success 'quoting' '
 855        rm -f .git/config &&
 856        git config quote.leading " test" &&
 857        git config quote.ending "test " &&
 858        git config quote.semicolon "test;test" &&
 859        git config quote.hash "test#test" &&
 860        test_cmp expect .git/config
 861'
 862
 863test_expect_success 'key with newline' '
 864        test_must_fail git config "key.with
 865newline" 123'
 866
 867test_expect_success 'value with newline' 'git config key.sub value.with\\\
 868newline'
 869
 870cat > .git/config <<\EOF
 871[section]
 872        ; comment \
 873        continued = cont\
 874inued
 875        noncont   = not continued ; \
 876        quotecont = "cont;\
 877inued"
 878EOF
 879
 880cat > expect <<\EOF
 881section.continued=continued
 882section.noncont=not continued
 883section.quotecont=cont;inued
 884EOF
 885
 886test_expect_success 'value continued on next line' '
 887        git config --list > result &&
 888        test_cmp result expect
 889'
 890
 891cat > .git/config <<\EOF
 892[section "sub=section"]
 893        val1 = foo=bar
 894        val2 = foo\nbar
 895        val3 = \n\n
 896        val4 =
 897        val5
 898EOF
 899
 900cat > expect <<\EOF
 901section.sub=section.val1
 902foo=barQsection.sub=section.val2
 903foo
 904barQsection.sub=section.val3
 905
 906
 907Qsection.sub=section.val4
 908Qsection.sub=section.val5Q
 909EOF
 910test_expect_success '--null --list' '
 911        git config --null --list | nul_to_q >result &&
 912        echo >>result &&
 913        test_cmp expect result
 914'
 915
 916test_expect_success '--null --get-regexp' '
 917        git config --null --get-regexp "val[0-9]" | nul_to_q >result &&
 918        echo >>result &&
 919        test_cmp expect result
 920'
 921
 922test_expect_success 'inner whitespace kept verbatim' '
 923        git config section.val "foo       bar" &&
 924        echo "foo         bar" >expect &&
 925        git config section.val >actual &&
 926        test_cmp expect actual
 927'
 928
 929test_expect_success SYMLINKS 'symlinked configuration' '
 930        ln -s notyet myconfig &&
 931        GIT_CONFIG=myconfig git config test.frotz nitfol &&
 932        test -h myconfig &&
 933        test -f notyet &&
 934        test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
 935        GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
 936        test -h myconfig &&
 937        test -f notyet &&
 938        cat >expect <<-\EOF &&
 939        nitfol
 940        rezrov
 941        EOF
 942        {
 943                GIT_CONFIG=notyet git config test.frotz &&
 944                GIT_CONFIG=notyet git config test.xyzzy
 945        } >actual &&
 946        test_cmp expect actual
 947'
 948
 949test_expect_success 'nonexistent configuration' '
 950        (
 951                GIT_CONFIG=doesnotexist &&
 952                export GIT_CONFIG &&
 953                test_must_fail git config --list &&
 954                test_must_fail git config test.xyzzy
 955        )
 956'
 957
 958test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
 959        ln -s doesnotexist linktonada &&
 960        ln -s linktonada linktolinktonada &&
 961        (
 962                GIT_CONFIG=linktonada &&
 963                export GIT_CONFIG &&
 964                test_must_fail git config --list &&
 965                GIT_CONFIG=linktolinktonada &&
 966                test_must_fail git config --list
 967        )
 968'
 969
 970test_expect_success 'check split_cmdline return' "
 971        git config alias.split-cmdline-fix 'echo \"' &&
 972        test_must_fail git split-cmdline-fix &&
 973        echo foo > foo &&
 974        git add foo &&
 975        git commit -m 'initial commit' &&
 976        git config branch.master.mergeoptions 'echo \"' &&
 977        test_must_fail git merge master
 978"
 979
 980test_expect_success 'git -c "key=value" support' '
 981        cat >expect <<-\EOF &&
 982        value
 983        value
 984        true
 985        EOF
 986        {
 987                git -c core.name=value config core.name &&
 988                git -c foo.CamelCase=value config foo.camelcase &&
 989                git -c foo.flag config --bool foo.flag
 990        } >actual &&
 991        test_cmp expect actual &&
 992        test_must_fail git -c name=value config core.name
 993'
 994
 995test_expect_success 'key sanity-checking' '
 996        test_must_fail git config foo=bar &&
 997        test_must_fail git config foo=.bar &&
 998        test_must_fail git config foo.ba=r &&
 999        test_must_fail git config foo.1bar &&
1000        test_must_fail git config foo."ba
1001                                z".bar &&
1002        test_must_fail git config . false &&
1003        test_must_fail git config .foo false &&
1004        test_must_fail git config foo. false &&
1005        test_must_fail git config .foo. false &&
1006        git config foo.bar true &&
1007        git config foo."ba =z".bar false
1008'
1009
1010test_expect_success 'git -c works with aliases of builtins' '
1011        git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1012        echo bar >expect &&
1013        git checkconfig >actual &&
1014        test_cmp expect actual
1015'
1016
1017test_expect_success 'git -c does not split values on equals' '
1018        echo "value with = in it" >expect &&
1019        git -c core.foo="value with = in it" config core.foo >actual &&
1020        test_cmp expect actual
1021'
1022
1023test_expect_success 'git -c dies on bogus config' '
1024        test_must_fail git -c core.bare=foo rev-parse
1025'
1026
1027test_expect_success 'git -c complains about empty key' '
1028        test_must_fail git -c "=foo" rev-parse
1029'
1030
1031test_expect_success 'git -c complains about empty key and value' '
1032        test_must_fail git -c "" rev-parse
1033'
1034
1035test_expect_success 'git config --edit works' '
1036        git config -f tmp test.value no &&
1037        echo test.value=yes >expect &&
1038        GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1039        git config -f tmp --list >actual &&
1040        test_cmp expect actual
1041'
1042
1043test_expect_success 'git config --edit respects core.editor' '
1044        git config -f tmp test.value no &&
1045        echo test.value=yes >expect &&
1046        test_config core.editor "echo [test]value=yes >" &&
1047        git config -f tmp --edit &&
1048        git config -f tmp --list >actual &&
1049        test_cmp expect actual
1050'
1051
1052# malformed configuration files
1053test_expect_success 'barf on syntax error' '
1054        cat >.git/config <<-\EOF &&
1055        # broken section line
1056        [section]
1057        key garbage
1058        EOF
1059        test_must_fail git config --get section.key >actual 2>error &&
1060        grep " line 3 " error
1061'
1062
1063test_expect_success 'barf on incomplete section header' '
1064        cat >.git/config <<-\EOF &&
1065        # broken section line
1066        [section
1067        key = value
1068        EOF
1069        test_must_fail git config --get section.key >actual 2>error &&
1070        grep " line 2 " error
1071'
1072
1073test_expect_success 'barf on incomplete string' '
1074        cat >.git/config <<-\EOF &&
1075        # broken section line
1076        [section]
1077        key = "value string
1078        EOF
1079        test_must_fail git config --get section.key >actual 2>error &&
1080        grep " line 3 " error
1081'
1082
1083test_done