t / t1300-repo-config.shon commit Merge branch 'maint' (a4cfcb0)
   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[beta] ; silly comment # another comment
  76noIndent= sillyValue ; 'nother silly comment
  77
  78# empty line
  79                ; comment
  80                haha   ="beta" # last silly comment
  81haha = hello
  82        haha = bello
  83[nextSection] noNewline = ouch
  84EOF
  85
  86cp .git/config .git/config2
  87
  88test_expect_success 'multiple unset' \
  89        'git config --unset-all beta.haha'
  90
  91cat > expect << EOF
  92[beta] ; silly comment # another comment
  93noIndent= sillyValue ; 'nother silly comment
  94
  95# empty line
  96                ; comment
  97[nextSection] noNewline = ouch
  98EOF
  99
 100test_expect_success 'multiple unset is correct' 'cmp .git/config expect'
 101
 102mv .git/config2 .git/config
 103
 104test_expect_success '--replace-all' \
 105        'git config --replace-all beta.haha gamma'
 106
 107cat > expect << EOF
 108[beta] ; silly comment # another comment
 109noIndent= sillyValue ; 'nother silly comment
 110
 111# empty line
 112                ; comment
 113        haha = gamma
 114[nextSection] noNewline = ouch
 115EOF
 116
 117test_expect_success 'all replaced' 'cmp .git/config expect'
 118
 119git config beta.haha alpha
 120
 121cat > expect << EOF
 122[beta] ; silly comment # another comment
 123noIndent= sillyValue ; 'nother silly comment
 124
 125# empty line
 126                ; comment
 127        haha = alpha
 128[nextSection] noNewline = ouch
 129EOF
 130
 131test_expect_success 'really mean test' 'cmp .git/config expect'
 132
 133git config nextsection.nonewline wow
 134
 135cat > expect << EOF
 136[beta] ; silly comment # another comment
 137noIndent= sillyValue ; 'nother silly comment
 138
 139# empty line
 140                ; comment
 141        haha = alpha
 142[nextSection]
 143        nonewline = wow
 144EOF
 145
 146test_expect_success 'really really mean test' 'cmp .git/config expect'
 147
 148test_expect_success 'get value' 'test alpha = $(git config beta.haha)'
 149git config --unset beta.haha
 150
 151cat > expect << EOF
 152[beta] ; silly comment # another comment
 153noIndent= sillyValue ; 'nother silly comment
 154
 155# empty line
 156                ; comment
 157[nextSection]
 158        nonewline = wow
 159EOF
 160
 161test_expect_success 'unset' 'cmp .git/config expect'
 162
 163git config nextsection.NoNewLine "wow2 for me" "for me$"
 164
 165cat > expect << EOF
 166[beta] ; silly comment # another comment
 167noIndent= sillyValue ; 'nother silly comment
 168
 169# empty line
 170                ; comment
 171[nextSection]
 172        nonewline = wow
 173        NoNewLine = wow2 for me
 174EOF
 175
 176test_expect_success 'multivar' 'cmp .git/config expect'
 177
 178test_expect_success 'non-match' \
 179        'git config --get nextsection.nonewline !for'
 180
 181test_expect_success 'non-match value' \
 182        'test wow = $(git config --get nextsection.nonewline !for)'
 183
 184test_expect_success 'ambiguous get' '
 185        ! git config --get nextsection.nonewline
 186'
 187
 188test_expect_success 'get multivar' \
 189        'git config --get-all nextsection.nonewline'
 190
 191git config nextsection.nonewline "wow3" "wow$"
 192
 193cat > expect << EOF
 194[beta] ; silly comment # another comment
 195noIndent= sillyValue ; 'nother silly comment
 196
 197# empty line
 198                ; comment
 199[nextSection]
 200        nonewline = wow3
 201        NoNewLine = wow2 for me
 202EOF
 203
 204test_expect_success 'multivar replace' 'cmp .git/config expect'
 205
 206test_expect_success 'ambiguous value' '
 207        ! git config nextsection.nonewline
 208'
 209
 210test_expect_success 'ambiguous unset' '
 211        ! git config --unset nextsection.nonewline
 212'
 213
 214test_expect_success 'invalid unset' '
 215        ! git config --unset somesection.nonewline
 216'
 217
 218git config --unset nextsection.nonewline "wow3$"
 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 = wow2 for me
 228EOF
 229
 230test_expect_success 'multivar unset' 'cmp .git/config expect'
 231
 232test_expect_success 'invalid key' '! git config inval.2key blabla'
 233
 234test_expect_success 'correct key' 'git config 123456.a123 987'
 235
 236test_expect_success 'hierarchical section' \
 237        'git config Version.1.2.3eX.Alpha beta'
 238
 239cat > expect << EOF
 240[beta] ; silly comment # another comment
 241noIndent= sillyValue ; 'nother silly comment
 242
 243# empty line
 244                ; comment
 245[nextSection]
 246        NoNewLine = wow2 for me
 247[123456]
 248        a123 = 987
 249[Version "1.2.3eX"]
 250        Alpha = beta
 251EOF
 252
 253test_expect_success 'hierarchical section value' 'cmp .git/config expect'
 254
 255cat > expect << EOF
 256beta.noindent=sillyValue
 257nextsection.nonewline=wow2 for me
 258123456.a123=987
 259version.1.2.3eX.alpha=beta
 260EOF
 261
 262test_expect_success 'working --list' \
 263        'git config --list > output && cmp output expect'
 264
 265cat > expect << EOF
 266beta.noindent sillyValue
 267nextsection.nonewline wow2 for me
 268EOF
 269
 270test_expect_success '--get-regexp' \
 271        'git config --get-regexp in > output && cmp output expect'
 272
 273git config --add nextsection.nonewline "wow4 for you"
 274
 275cat > expect << EOF
 276wow2 for me
 277wow4 for you
 278EOF
 279
 280test_expect_success '--add' \
 281        'git config --get-all nextsection.nonewline > output && cmp output expect'
 282
 283cat > .git/config << EOF
 284[novalue]
 285        variable
 286[emptyvalue]
 287        variable =
 288EOF
 289
 290test_expect_success 'get variable with no value' \
 291        'git config --get novalue.variable ^$'
 292
 293test_expect_success 'get variable with empty value' \
 294        'git config --get emptyvalue.variable ^$'
 295
 296echo novalue.variable > expect
 297
 298test_expect_success 'get-regexp variable with no value' \
 299        'git config --get-regexp novalue > output &&
 300         cmp output expect'
 301
 302echo 'emptyvalue.variable ' > expect
 303
 304test_expect_success 'get-regexp variable with empty value' \
 305        'git config --get-regexp emptyvalue > output &&
 306         cmp output expect'
 307
 308echo true > expect
 309
 310test_expect_success 'get bool variable with no value' \
 311        'git config --bool novalue.variable > output &&
 312         cmp output expect'
 313
 314echo false > expect
 315
 316test_expect_success 'get bool variable with empty value' \
 317        'git config --bool emptyvalue.variable > output &&
 318         cmp output expect'
 319
 320git config > output 2>&1
 321
 322test_expect_success 'no arguments, but no crash' \
 323        "test $? = 129 && grep usage output"
 324
 325cat > .git/config << EOF
 326[a.b]
 327        c = d
 328EOF
 329
 330git config a.x y
 331
 332cat > expect << EOF
 333[a.b]
 334        c = d
 335[a]
 336        x = y
 337EOF
 338
 339test_expect_success 'new section is partial match of another' 'cmp .git/config expect'
 340
 341git config b.x y
 342git config a.b c
 343
 344cat > expect << EOF
 345[a.b]
 346        c = d
 347[a]
 348        x = y
 349        b = c
 350[b]
 351        x = y
 352EOF
 353
 354test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect'
 355
 356test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \
 357        'git config --file non-existing-config -l; test $? != 0'
 358
 359cat > other-config << EOF
 360[ein]
 361        bahn = strasse
 362EOF
 363
 364cat > expect << EOF
 365ein.bahn=strasse
 366EOF
 367
 368GIT_CONFIG=other-config git config -l > output
 369
 370test_expect_success 'alternative GIT_CONFIG' 'cmp output expect'
 371
 372test_expect_success 'alternative GIT_CONFIG (--file)' \
 373        'git config --file other-config -l > output && cmp output expect'
 374
 375GIT_CONFIG=other-config git config anwohner.park ausweis
 376
 377cat > expect << EOF
 378[ein]
 379        bahn = strasse
 380[anwohner]
 381        park = ausweis
 382EOF
 383
 384test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect'
 385
 386cat > .git/config << EOF
 387# Hallo
 388        #Bello
 389[branch "eins"]
 390        x = 1
 391[branch.eins]
 392        y = 1
 393        [branch "1 234 blabl/a"]
 394weird
 395EOF
 396
 397test_expect_success "rename section" \
 398        "git config --rename-section branch.eins branch.zwei"
 399
 400cat > expect << EOF
 401# Hallo
 402        #Bello
 403[branch "zwei"]
 404        x = 1
 405[branch "zwei"]
 406        y = 1
 407        [branch "1 234 blabl/a"]
 408weird
 409EOF
 410
 411test_expect_success "rename succeeded" "git diff expect .git/config"
 412
 413test_expect_success "rename non-existing section" '
 414        ! git config --rename-section branch."world domination" branch.drei
 415'
 416
 417test_expect_success "rename succeeded" "git diff expect .git/config"
 418
 419test_expect_success "rename another section" \
 420        'git config --rename-section branch."1 234 blabl/a" branch.drei'
 421
 422cat > expect << EOF
 423# Hallo
 424        #Bello
 425[branch "zwei"]
 426        x = 1
 427[branch "zwei"]
 428        y = 1
 429[branch "drei"]
 430weird
 431EOF
 432
 433test_expect_success "rename succeeded" "git diff expect .git/config"
 434
 435cat >> .git/config << EOF
 436  [branch "zwei"] a = 1 [branch "vier"]
 437EOF
 438
 439test_expect_success "remove section" "git config --remove-section branch.zwei"
 440
 441cat > expect << EOF
 442# Hallo
 443        #Bello
 444[branch "drei"]
 445weird
 446EOF
 447
 448test_expect_success "section was removed properly" \
 449        "git diff -u expect .git/config"
 450
 451rm .git/config
 452
 453cat > expect << EOF
 454[gitcvs]
 455        enabled = true
 456        dbname = %Ggitcvs2.%a.%m.sqlite
 457[gitcvs "ext"]
 458        dbname = %Ggitcvs1.%a.%m.sqlite
 459EOF
 460
 461test_expect_success 'section ending' '
 462
 463        git config gitcvs.enabled true &&
 464        git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
 465        git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
 466        cmp .git/config expect
 467
 468'
 469
 470test_expect_success numbers '
 471
 472        git config kilo.gram 1k &&
 473        git config mega.ton 1m &&
 474        k=$(git config --int --get kilo.gram) &&
 475        test z1024 = "z$k" &&
 476        m=$(git config --int --get mega.ton) &&
 477        test z1048576 = "z$m"
 478'
 479
 480cat > expect <<EOF
 481fatal: bad config value for 'aninvalid.unit' in .git/config
 482EOF
 483
 484test_expect_success 'invalid unit' '
 485
 486        git config aninvalid.unit "1auto" &&
 487        s=$(git config aninvalid.unit) &&
 488        test "z1auto" = "z$s" &&
 489        if git config --int --get aninvalid.unit 2>actual
 490        then
 491                echo config should have failed
 492                false
 493        fi &&
 494        cmp actual expect
 495'
 496
 497cat > expect << EOF
 498true
 499false
 500true
 501false
 502true
 503false
 504true
 505false
 506EOF
 507
 508test_expect_success bool '
 509
 510        git config bool.true1 01 &&
 511        git config bool.true2 -1 &&
 512        git config bool.true3 YeS &&
 513        git config bool.true4 true &&
 514        git config bool.false1 000 &&
 515        git config bool.false2 "" &&
 516        git config bool.false3 nO &&
 517        git config bool.false4 FALSE &&
 518        rm -f result &&
 519        for i in 1 2 3 4
 520        do
 521            git config --bool --get bool.true$i >>result
 522            git config --bool --get bool.false$i >>result
 523        done &&
 524        cmp expect result'
 525
 526test_expect_success 'invalid bool (--get)' '
 527
 528        git config bool.nobool foobar &&
 529        ! git config --bool --get bool.nobool'
 530
 531test_expect_success 'invalid bool (set)' '
 532
 533        ! git config --bool bool.nobool foobar'
 534
 535rm .git/config
 536
 537cat > expect <<\EOF
 538[bool]
 539        true1 = true
 540        true2 = true
 541        true3 = true
 542        true4 = true
 543        false1 = false
 544        false2 = false
 545        false3 = false
 546        false4 = false
 547EOF
 548
 549test_expect_success 'set --bool' '
 550
 551        git config --bool bool.true1 01 &&
 552        git config --bool bool.true2 -1 &&
 553        git config --bool bool.true3 YeS &&
 554        git config --bool bool.true4 true &&
 555        git config --bool bool.false1 000 &&
 556        git config --bool bool.false2 "" &&
 557        git config --bool bool.false3 nO &&
 558        git config --bool bool.false4 FALSE &&
 559        cmp expect .git/config'
 560
 561rm .git/config
 562
 563cat > expect <<\EOF
 564[int]
 565        val1 = 1
 566        val2 = -1
 567        val3 = 5242880
 568EOF
 569
 570test_expect_success 'set --int' '
 571
 572        git config --int int.val1 01 &&
 573        git config --int int.val2 -1 &&
 574        git config --int int.val3 5m &&
 575        cmp expect .git/config'
 576
 577rm .git/config
 578
 579git config quote.leading " test"
 580git config quote.ending "test "
 581git config quote.semicolon "test;test"
 582git config quote.hash "test#test"
 583
 584cat > expect << EOF
 585[quote]
 586        leading = " test"
 587        ending = "test "
 588        semicolon = "test;test"
 589        hash = "test#test"
 590EOF
 591
 592test_expect_success 'quoting' 'cmp .git/config expect'
 593
 594test_expect_success 'key with newline' '
 595        ! git config "key.with
 596newline" 123'
 597
 598test_expect_success 'value with newline' 'git config key.sub value.with\\\
 599newline'
 600
 601cat > .git/config <<\EOF
 602[section]
 603        ; comment \
 604        continued = cont\
 605inued
 606        noncont   = not continued ; \
 607        quotecont = "cont;\
 608inued"
 609EOF
 610
 611cat > expect <<\EOF
 612section.continued=continued
 613section.noncont=not continued
 614section.quotecont=cont;inued
 615EOF
 616
 617git config --list > result
 618
 619test_expect_success 'value continued on next line' 'cmp result expect'
 620
 621cat > .git/config <<\EOF
 622[section "sub=section"]
 623        val1 = foo=bar
 624        val2 = foo\nbar
 625        val3 = \n\n
 626        val4 =
 627        val5
 628EOF
 629
 630cat > expect <<\EOF
 631section.sub=section.val1
 632foo=barQsection.sub=section.val2
 633foo
 634barQsection.sub=section.val3
 635
 636
 637Qsection.sub=section.val4
 638Qsection.sub=section.val5Q
 639EOF
 640
 641git config --null --list | tr '\000' 'Q' > result
 642echo >>result
 643
 644test_expect_success '--null --list' 'cmp result expect'
 645
 646git config --null --get-regexp 'val[0-9]' | tr '\000' 'Q' > result
 647echo >>result
 648
 649test_expect_success '--null --get-regexp' 'cmp result expect'
 650
 651test_expect_success 'symlinked configuration' '
 652
 653        ln -s notyet myconfig &&
 654        GIT_CONFIG=myconfig git config test.frotz nitfol &&
 655        test -h myconfig &&
 656        test -f notyet &&
 657        test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
 658        GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
 659        test -h myconfig &&
 660        test -f notyet &&
 661        test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
 662        test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov
 663
 664'
 665
 666test_done