t / t1300-repo-config.shon commit Sync with 1.6.2.2 (8130949)
   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 -f .git/config && rm .git/config
  11
  12git config core.penguin "little blue"
  13
  14cat > expect << EOF
  15[core]
  16        penguin = little blue
  17EOF
  18
  19test_expect_success 'initial' 'cmp .git/config expect'
  20
  21git config Core.Movie BadPhysics
  22
  23cat > expect << EOF
  24[core]
  25        penguin = little blue
  26        Movie = BadPhysics
  27EOF
  28
  29test_expect_success 'mixed case' 'cmp .git/config expect'
  30
  31git config Cores.WhatEver Second
  32
  33cat > expect << EOF
  34[core]
  35        penguin = little blue
  36        Movie = BadPhysics
  37[Cores]
  38        WhatEver = Second
  39EOF
  40
  41test_expect_success 'similar section' 'cmp .git/config expect'
  42
  43git config CORE.UPPERCASE true
  44
  45cat > expect << EOF
  46[core]
  47        penguin = little blue
  48        Movie = BadPhysics
  49        UPPERCASE = true
  50[Cores]
  51        WhatEver = Second
  52EOF
  53
  54test_expect_success 'similar section' 'cmp .git/config expect'
  55
  56test_expect_success 'replace with non-match' \
  57        'git config core.penguin kingpin !blue'
  58
  59test_expect_success 'replace with non-match (actually matching)' \
  60        'git config core.penguin "very blue" !kingpin'
  61
  62cat > expect << EOF
  63[core]
  64        penguin = very blue
  65        Movie = BadPhysics
  66        UPPERCASE = true
  67        penguin = kingpin
  68[Cores]
  69        WhatEver = Second
  70EOF
  71
  72test_expect_success 'non-match result' 'cmp .git/config expect'
  73
  74cat > .git/config <<\EOF
  75[alpha]
  76bar = foo
  77[beta]
  78baz = multiple \
  79lines
  80EOF
  81
  82test_expect_success 'unset with cont. lines' \
  83        'git config --unset beta.baz'
  84
  85cat > expect <<\EOF
  86[alpha]
  87bar = foo
  88[beta]
  89EOF
  90
  91test_expect_success 'unset with cont. lines is correct' 'cmp .git/config expect'
  92
  93cat > .git/config << EOF
  94[beta] ; silly comment # another comment
  95noIndent= sillyValue ; 'nother silly comment
  96
  97# empty line
  98                ; comment
  99                haha   ="beta" # last silly comment
 100haha = hello
 101        haha = bello
 102[nextSection] noNewline = ouch
 103EOF
 104
 105cp .git/config .git/config2
 106
 107test_expect_success 'multiple unset' \
 108        'git config --unset-all beta.haha'
 109
 110cat > expect << EOF
 111[beta] ; silly comment # another comment
 112noIndent= sillyValue ; 'nother silly comment
 113
 114# empty line
 115                ; comment
 116[nextSection] noNewline = ouch
 117EOF
 118
 119test_expect_success 'multiple unset is correct' 'cmp .git/config expect'
 120
 121cp .git/config2 .git/config
 122
 123test_expect_success '--replace-all missing value' '
 124        test_must_fail git config --replace-all beta.haha &&
 125        test_cmp .git/config2 .git/config
 126'
 127
 128rm .git/config2
 129
 130test_expect_success '--replace-all' \
 131        'git config --replace-all beta.haha gamma'
 132
 133cat > expect << EOF
 134[beta] ; silly comment # another comment
 135noIndent= sillyValue ; 'nother silly comment
 136
 137# empty line
 138                ; comment
 139        haha = gamma
 140[nextSection] noNewline = ouch
 141EOF
 142
 143test_expect_success 'all replaced' 'cmp .git/config expect'
 144
 145git config beta.haha alpha
 146
 147cat > expect << EOF
 148[beta] ; silly comment # another comment
 149noIndent= sillyValue ; 'nother silly comment
 150
 151# empty line
 152                ; comment
 153        haha = alpha
 154[nextSection] noNewline = ouch
 155EOF
 156
 157test_expect_success 'really mean test' 'cmp .git/config expect'
 158
 159git config nextsection.nonewline wow
 160
 161cat > expect << EOF
 162[beta] ; silly comment # another comment
 163noIndent= sillyValue ; 'nother silly comment
 164
 165# empty line
 166                ; comment
 167        haha = alpha
 168[nextSection]
 169        nonewline = wow
 170EOF
 171
 172test_expect_success 'really really mean test' 'cmp .git/config expect'
 173
 174test_expect_success 'get value' 'test alpha = $(git config beta.haha)'
 175git config --unset beta.haha
 176
 177cat > expect << EOF
 178[beta] ; silly comment # another comment
 179noIndent= sillyValue ; 'nother silly comment
 180
 181# empty line
 182                ; comment
 183[nextSection]
 184        nonewline = wow
 185EOF
 186
 187test_expect_success 'unset' 'cmp .git/config expect'
 188
 189git config nextsection.NoNewLine "wow2 for me" "for me$"
 190
 191cat > expect << EOF
 192[beta] ; silly comment # another comment
 193noIndent= sillyValue ; 'nother silly comment
 194
 195# empty line
 196                ; comment
 197[nextSection]
 198        nonewline = wow
 199        NoNewLine = wow2 for me
 200EOF
 201
 202test_expect_success 'multivar' 'cmp .git/config expect'
 203
 204test_expect_success 'non-match' \
 205        'git config --get nextsection.nonewline !for'
 206
 207test_expect_success 'non-match value' \
 208        'test wow = $(git config --get nextsection.nonewline !for)'
 209
 210test_expect_success 'ambiguous get' '
 211        test_must_fail git config --get nextsection.nonewline
 212'
 213
 214test_expect_success 'get multivar' \
 215        'git config --get-all nextsection.nonewline'
 216
 217git config nextsection.nonewline "wow3" "wow$"
 218
 219cat > expect << EOF
 220[beta] ; silly comment # another comment
 221noIndent= sillyValue ; 'nother silly comment
 222
 223# empty line
 224                ; comment
 225[nextSection]
 226        nonewline = wow3
 227        NoNewLine = wow2 for me
 228EOF
 229
 230test_expect_success 'multivar replace' 'cmp .git/config expect'
 231
 232test_expect_success 'ambiguous value' '
 233        test_must_fail git config nextsection.nonewline
 234'
 235
 236test_expect_success 'ambiguous unset' '
 237        test_must_fail git config --unset nextsection.nonewline
 238'
 239
 240test_expect_success 'invalid unset' '
 241        test_must_fail git config --unset somesection.nonewline
 242'
 243
 244git config --unset nextsection.nonewline "wow3$"
 245
 246cat > expect << EOF
 247[beta] ; silly comment # another comment
 248noIndent= sillyValue ; 'nother silly comment
 249
 250# empty line
 251                ; comment
 252[nextSection]
 253        NoNewLine = wow2 for me
 254EOF
 255
 256test_expect_success 'multivar unset' 'cmp .git/config expect'
 257
 258test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
 259
 260test_expect_success 'correct key' 'git config 123456.a123 987'
 261
 262test_expect_success 'hierarchical section' \
 263        'git config Version.1.2.3eX.Alpha beta'
 264
 265cat > expect << EOF
 266[beta] ; silly comment # another comment
 267noIndent= sillyValue ; 'nother silly comment
 268
 269# empty line
 270                ; comment
 271[nextSection]
 272        NoNewLine = wow2 for me
 273[123456]
 274        a123 = 987
 275[Version "1.2.3eX"]
 276        Alpha = beta
 277EOF
 278
 279test_expect_success 'hierarchical section value' 'cmp .git/config expect'
 280
 281cat > expect << EOF
 282beta.noindent=sillyValue
 283nextsection.nonewline=wow2 for me
 284123456.a123=987
 285version.1.2.3eX.alpha=beta
 286EOF
 287
 288test_expect_success 'working --list' \
 289        'git config --list > output && cmp output expect'
 290
 291cat > expect << EOF
 292beta.noindent sillyValue
 293nextsection.nonewline wow2 for me
 294EOF
 295
 296test_expect_success '--get-regexp' \
 297        'git config --get-regexp in > output && cmp output expect'
 298
 299git config --add nextsection.nonewline "wow4 for you"
 300
 301cat > expect << EOF
 302wow2 for me
 303wow4 for you
 304EOF
 305
 306test_expect_success '--add' \
 307        'git config --get-all nextsection.nonewline > output && cmp output expect'
 308
 309cat > .git/config << EOF
 310[novalue]
 311        variable
 312[emptyvalue]
 313        variable =
 314EOF
 315
 316test_expect_success 'get variable with no value' \
 317        'git config --get novalue.variable ^$'
 318
 319test_expect_success 'get variable with empty value' \
 320        'git config --get emptyvalue.variable ^$'
 321
 322echo novalue.variable > expect
 323
 324test_expect_success 'get-regexp variable with no value' \
 325        'git config --get-regexp novalue > output &&
 326         cmp output expect'
 327
 328echo 'emptyvalue.variable ' > expect
 329
 330test_expect_success 'get-regexp variable with empty value' \
 331        'git config --get-regexp emptyvalue > output &&
 332         cmp output expect'
 333
 334echo true > expect
 335
 336test_expect_success 'get bool variable with no value' \
 337        'git config --bool novalue.variable > output &&
 338         cmp output expect'
 339
 340echo false > expect
 341
 342test_expect_success 'get bool variable with empty value' \
 343        'git config --bool emptyvalue.variable > output &&
 344         cmp output expect'
 345
 346test_expect_success 'no arguments, but no crash' '
 347        test_must_fail git config >output 2>&1 &&
 348        grep usage output
 349'
 350
 351cat > .git/config << EOF
 352[a.b]
 353        c = d
 354EOF
 355
 356git config a.x y
 357
 358cat > expect << EOF
 359[a.b]
 360        c = d
 361[a]
 362        x = y
 363EOF
 364
 365test_expect_success 'new section is partial match of another' 'cmp .git/config expect'
 366
 367git config b.x y
 368git config a.b c
 369
 370cat > expect << EOF
 371[a.b]
 372        c = d
 373[a]
 374        x = y
 375        b = c
 376[b]
 377        x = y
 378EOF
 379
 380test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect'
 381
 382test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \
 383        'test_must_fail git config --file non-existing-config -l'
 384
 385cat > other-config << EOF
 386[ein]
 387        bahn = strasse
 388EOF
 389
 390cat > expect << EOF
 391ein.bahn=strasse
 392EOF
 393
 394GIT_CONFIG=other-config git config -l > output
 395
 396test_expect_success 'alternative GIT_CONFIG' 'cmp output expect'
 397
 398test_expect_success 'alternative GIT_CONFIG (--file)' \
 399        'git config --file other-config -l > output && cmp output expect'
 400
 401GIT_CONFIG=other-config git config anwohner.park ausweis
 402
 403cat > expect << EOF
 404[ein]
 405        bahn = strasse
 406[anwohner]
 407        park = ausweis
 408EOF
 409
 410test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect'
 411
 412cat > .git/config << EOF
 413# Hallo
 414        #Bello
 415[branch "eins"]
 416        x = 1
 417[branch.eins]
 418        y = 1
 419        [branch "1 234 blabl/a"]
 420weird
 421EOF
 422
 423test_expect_success "rename section" \
 424        "git config --rename-section branch.eins branch.zwei"
 425
 426cat > expect << EOF
 427# Hallo
 428        #Bello
 429[branch "zwei"]
 430        x = 1
 431[branch "zwei"]
 432        y = 1
 433        [branch "1 234 blabl/a"]
 434weird
 435EOF
 436
 437test_expect_success "rename succeeded" "test_cmp expect .git/config"
 438
 439test_expect_success "rename non-existing section" '
 440        test_must_fail git config --rename-section \
 441                branch."world domination" branch.drei
 442'
 443
 444test_expect_success "rename succeeded" "test_cmp expect .git/config"
 445
 446test_expect_success "rename another section" \
 447        'git config --rename-section branch."1 234 blabl/a" branch.drei'
 448
 449cat > expect << EOF
 450# Hallo
 451        #Bello
 452[branch "zwei"]
 453        x = 1
 454[branch "zwei"]
 455        y = 1
 456[branch "drei"]
 457weird
 458EOF
 459
 460test_expect_success "rename succeeded" "test_cmp expect .git/config"
 461
 462cat >> .git/config << EOF
 463  [branch "zwei"] a = 1 [branch "vier"]
 464EOF
 465
 466test_expect_success "remove section" "git config --remove-section branch.zwei"
 467
 468cat > expect << EOF
 469# Hallo
 470        #Bello
 471[branch "drei"]
 472weird
 473EOF
 474
 475test_expect_success "section was removed properly" \
 476        "test_cmp expect .git/config"
 477
 478rm .git/config
 479
 480cat > expect << EOF
 481[gitcvs]
 482        enabled = true
 483        dbname = %Ggitcvs2.%a.%m.sqlite
 484[gitcvs "ext"]
 485        dbname = %Ggitcvs1.%a.%m.sqlite
 486EOF
 487
 488test_expect_success 'section ending' '
 489
 490        git config gitcvs.enabled true &&
 491        git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
 492        git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
 493        cmp .git/config expect
 494
 495'
 496
 497test_expect_success numbers '
 498
 499        git config kilo.gram 1k &&
 500        git config mega.ton 1m &&
 501        k=$(git config --int --get kilo.gram) &&
 502        test z1024 = "z$k" &&
 503        m=$(git config --int --get mega.ton) &&
 504        test z1048576 = "z$m"
 505'
 506
 507cat > expect <<EOF
 508fatal: bad config value for 'aninvalid.unit' in .git/config
 509EOF
 510
 511test_expect_success 'invalid unit' '
 512
 513        git config aninvalid.unit "1auto" &&
 514        s=$(git config aninvalid.unit) &&
 515        test "z1auto" = "z$s" &&
 516        if git config --int --get aninvalid.unit 2>actual
 517        then
 518                echo config should have failed
 519                false
 520        fi &&
 521        cmp actual expect
 522'
 523
 524cat > expect << EOF
 525true
 526false
 527true
 528false
 529true
 530false
 531true
 532false
 533EOF
 534
 535test_expect_success bool '
 536
 537        git config bool.true1 01 &&
 538        git config bool.true2 -1 &&
 539        git config bool.true3 YeS &&
 540        git config bool.true4 true &&
 541        git config bool.false1 000 &&
 542        git config bool.false2 "" &&
 543        git config bool.false3 nO &&
 544        git config bool.false4 FALSE &&
 545        rm -f result &&
 546        for i in 1 2 3 4
 547        do
 548            git config --bool --get bool.true$i >>result
 549            git config --bool --get bool.false$i >>result
 550        done &&
 551        cmp expect result'
 552
 553test_expect_success 'invalid bool (--get)' '
 554
 555        git config bool.nobool foobar &&
 556        test_must_fail git config --bool --get bool.nobool'
 557
 558test_expect_success 'invalid bool (set)' '
 559
 560        test_must_fail git config --bool bool.nobool foobar'
 561
 562rm .git/config
 563
 564cat > expect <<\EOF
 565[bool]
 566        true1 = true
 567        true2 = true
 568        true3 = true
 569        true4 = true
 570        false1 = false
 571        false2 = false
 572        false3 = false
 573        false4 = false
 574EOF
 575
 576test_expect_success 'set --bool' '
 577
 578        git config --bool bool.true1 01 &&
 579        git config --bool bool.true2 -1 &&
 580        git config --bool bool.true3 YeS &&
 581        git config --bool bool.true4 true &&
 582        git config --bool bool.false1 000 &&
 583        git config --bool bool.false2 "" &&
 584        git config --bool bool.false3 nO &&
 585        git config --bool bool.false4 FALSE &&
 586        cmp expect .git/config'
 587
 588rm .git/config
 589
 590cat > expect <<\EOF
 591[int]
 592        val1 = 1
 593        val2 = -1
 594        val3 = 5242880
 595EOF
 596
 597test_expect_success 'set --int' '
 598
 599        git config --int int.val1 01 &&
 600        git config --int int.val2 -1 &&
 601        git config --int int.val3 5m &&
 602        cmp expect .git/config'
 603
 604rm .git/config
 605
 606cat >expect <<\EOF
 607[bool]
 608        true1 = true
 609        true2 = true
 610        false1 = false
 611        false2 = false
 612[int]
 613        int1 = 0
 614        int2 = 1
 615        int3 = -1
 616EOF
 617
 618test_expect_success 'get --bool-or-int' '
 619        (
 620                echo "[bool]"
 621                echo true1
 622                echo true2 = true
 623                echo false = false
 624                echo "[int]"
 625                echo int1 = 0
 626                echo int2 = 1
 627                echo int3 = -1
 628        ) >>.git/config &&
 629        test $(git config --bool-or-int bool.true1) = true &&
 630        test $(git config --bool-or-int bool.true2) = true &&
 631        test $(git config --bool-or-int bool.false) = false &&
 632        test $(git config --bool-or-int int.int1) = 0 &&
 633        test $(git config --bool-or-int int.int2) = 1 &&
 634        test $(git config --bool-or-int int.int3) = -1
 635
 636'
 637
 638rm .git/config
 639cat >expect <<\EOF
 640[bool]
 641        true1 = true
 642        false1 = false
 643        true2 = true
 644        false2 = false
 645[int]
 646        int1 = 0
 647        int2 = 1
 648        int3 = -1
 649EOF
 650
 651test_expect_success 'set --bool-or-int' '
 652        git config --bool-or-int bool.true1 true &&
 653        git config --bool-or-int bool.false1 false &&
 654        git config --bool-or-int bool.true2 yes &&
 655        git config --bool-or-int bool.false2 no &&
 656        git config --bool-or-int int.int1 0 &&
 657        git config --bool-or-int int.int2 1 &&
 658        git config --bool-or-int int.int3 -1 &&
 659        test_cmp expect .git/config
 660'
 661
 662rm .git/config
 663
 664git config quote.leading " test"
 665git config quote.ending "test "
 666git config quote.semicolon "test;test"
 667git config quote.hash "test#test"
 668
 669cat > expect << EOF
 670[quote]
 671        leading = " test"
 672        ending = "test "
 673        semicolon = "test;test"
 674        hash = "test#test"
 675EOF
 676
 677test_expect_success 'quoting' 'cmp .git/config expect'
 678
 679test_expect_success 'key with newline' '
 680        test_must_fail git config "key.with
 681newline" 123'
 682
 683test_expect_success 'value with newline' 'git config key.sub value.with\\\
 684newline'
 685
 686cat > .git/config <<\EOF
 687[section]
 688        ; comment \
 689        continued = cont\
 690inued
 691        noncont   = not continued ; \
 692        quotecont = "cont;\
 693inued"
 694EOF
 695
 696cat > expect <<\EOF
 697section.continued=continued
 698section.noncont=not continued
 699section.quotecont=cont;inued
 700EOF
 701
 702git config --list > result
 703
 704test_expect_success 'value continued on next line' 'cmp result expect'
 705
 706cat > .git/config <<\EOF
 707[section "sub=section"]
 708        val1 = foo=bar
 709        val2 = foo\nbar
 710        val3 = \n\n
 711        val4 =
 712        val5
 713EOF
 714
 715cat > expect <<\EOF
 716section.sub=section.val1
 717foo=barQsection.sub=section.val2
 718foo
 719barQsection.sub=section.val3
 720
 721
 722Qsection.sub=section.val4
 723Qsection.sub=section.val5Q
 724EOF
 725
 726git config --null --list | perl -pe 'y/\000/Q/' > result
 727echo >>result
 728
 729test_expect_success '--null --list' 'cmp result expect'
 730
 731git config --null --get-regexp 'val[0-9]' | perl -pe 'y/\000/Q/' > result
 732echo >>result
 733
 734test_expect_success '--null --get-regexp' 'cmp result expect'
 735
 736test_expect_success SYMLINKS 'symlinked configuration' '
 737
 738        ln -s notyet myconfig &&
 739        GIT_CONFIG=myconfig git config test.frotz nitfol &&
 740        test -h myconfig &&
 741        test -f notyet &&
 742        test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
 743        GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
 744        test -h myconfig &&
 745        test -f notyet &&
 746        test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
 747        test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov
 748
 749'
 750
 751test_expect_success 'check split_cmdline return' "
 752        git config alias.split-cmdline-fix 'echo \"' &&
 753        test_must_fail git split-cmdline-fix &&
 754        echo foo > foo &&
 755        git add foo &&
 756        git commit -m 'initial commit' &&
 757        git config branch.master.mergeoptions 'echo \"' &&
 758        test_must_fail git merge master
 759        "
 760
 761test_done