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