1#!/bin/sh
   2#
   3# Copyright (c) 2005 Johannes Schindelin
   4#
   5test_description='Test git config in different settings'
   7. ./test-lib.sh
   9test -f .git/config && rm .git/config
  11git config core.penguin "little blue"
  13cat > expect << EOF
  15[core]
  16        penguin = little blue
  17EOF
  18test_expect_success 'initial' 'cmp .git/config expect'
  20git config Core.Movie BadPhysics
  22cat > expect << EOF
  24[core]
  25        penguin = little blue
  26        Movie = BadPhysics
  27EOF
  28test_expect_success 'mixed case' 'cmp .git/config expect'
  30git config Cores.WhatEver Second
  32cat > expect << EOF
  34[core]
  35        penguin = little blue
  36        Movie = BadPhysics
  37[Cores]
  38        WhatEver = Second
  39EOF
  40test_expect_success 'similar section' 'cmp .git/config expect'
  42git config CORE.UPPERCASE true
  44cat > expect << EOF
  46[core]
  47        penguin = little blue
  48        Movie = BadPhysics
  49        UPPERCASE = true
  50[Cores]
  51        WhatEver = Second
  52EOF
  53test_expect_success 'similar section' 'cmp .git/config expect'
  55test_expect_success 'replace with non-match' \
  57        'git config core.penguin kingpin !blue'
  58test_expect_success 'replace with non-match (actually matching)' \
  60        'git config core.penguin "very blue" !kingpin'
  61cat > expect << EOF
  63[core]
  64        penguin = very blue
  65        Movie = BadPhysics
  66        UPPERCASE = true
  67        penguin = kingpin
  68[Cores]
  69        WhatEver = Second
  70EOF
  71test_expect_success 'non-match result' 'cmp .git/config expect'
  73cat > .git/config << EOF
  75[beta] ; silly comment # another comment
  76noIndent= sillyValue ; 'nother silly comment
  77# empty line
  79                ; comment
  80                haha   ="beta" # last silly comment
  81haha = hello
  82        haha = bello
  83[nextSection] noNewline = ouch
  84EOF
  85cp .git/config .git/config2
  87test_expect_success 'multiple unset' \
  89        'git config --unset-all beta.haha'
  90cat > expect << EOF
  92[beta] ; silly comment # another comment
  93noIndent= sillyValue ; 'nother silly comment
  94# empty line
  96                ; comment
  97[nextSection] noNewline = ouch
  98EOF
  99test_expect_success 'multiple unset is correct' 'cmp .git/config expect'
 101mv .git/config2 .git/config
 103test_expect_success '--replace-all' \
 105        'git config --replace-all beta.haha gamma'
 106cat > expect << EOF
 108[beta] ; silly comment # another comment
 109noIndent= sillyValue ; 'nother silly comment
 110# empty line
 112                ; comment
 113        haha = gamma
 114[nextSection] noNewline = ouch
 115EOF
 116test_expect_success 'all replaced' 'cmp .git/config expect'
 118git config beta.haha alpha
 120cat > expect << EOF
 122[beta] ; silly comment # another comment
 123noIndent= sillyValue ; 'nother silly comment
 124# empty line
 126                ; comment
 127        haha = alpha
 128[nextSection] noNewline = ouch
 129EOF
 130test_expect_success 'really mean test' 'cmp .git/config expect'
 132git config nextsection.nonewline wow
 134cat > expect << EOF
 136[beta] ; silly comment # another comment
 137noIndent= sillyValue ; 'nother silly comment
 138# empty line
 140                ; comment
 141        haha = alpha
 142[nextSection]
 143        nonewline = wow
 144EOF
 145test_expect_success 'really really mean test' 'cmp .git/config expect'
 147test_expect_success 'get value' 'test alpha = $(git config beta.haha)'
 149git config --unset beta.haha
 150cat > expect << EOF
 152[beta] ; silly comment # another comment
 153noIndent= sillyValue ; 'nother silly comment
 154# empty line
 156                ; comment
 157[nextSection]
 158        nonewline = wow
 159EOF
 160test_expect_success 'unset' 'cmp .git/config expect'
 162git config nextsection.NoNewLine "wow2 for me" "for me$"
 164cat > expect << EOF
 166[beta] ; silly comment # another comment
 167noIndent= sillyValue ; 'nother silly comment
 168# empty line
 170                ; comment
 171[nextSection]
 172        nonewline = wow
 173        NoNewLine = wow2 for me
 174EOF
 175test_expect_success 'multivar' 'cmp .git/config expect'
 177test_expect_success 'non-match' \
 179        'git config --get nextsection.nonewline !for'
 180test_expect_success 'non-match value' \
 182        'test wow = $(git config --get nextsection.nonewline !for)'
 183test_expect_failure 'ambiguous get' \
 185        'git config --get nextsection.nonewline'
 186test_expect_success 'get multivar' \
 188        'git config --get-all nextsection.nonewline'
 189git config nextsection.nonewline "wow3" "wow$"
 191cat > expect << EOF
 193[beta] ; silly comment # another comment
 194noIndent= sillyValue ; 'nother silly comment
 195# empty line
 197                ; comment
 198[nextSection]
 199        nonewline = wow3
 200        NoNewLine = wow2 for me
 201EOF
 202test_expect_success 'multivar replace' 'cmp .git/config expect'
 204test_expect_failure 'ambiguous value' 'git config nextsection.nonewline'
 206test_expect_failure 'ambiguous unset' \
 208        'git config --unset nextsection.nonewline'
 209test_expect_failure 'invalid unset' \
 211        'git config --unset somesection.nonewline'
 212git config --unset nextsection.nonewline "wow3$"
 214cat > expect << EOF
 216[beta] ; silly comment # another comment
 217noIndent= sillyValue ; 'nother silly comment
 218# empty line
 220                ; comment
 221[nextSection]
 222        NoNewLine = wow2 for me
 223EOF
 224test_expect_success 'multivar unset' 'cmp .git/config expect'
 226test_expect_failure 'invalid key' 'git config inval.2key blabla'
 228test_expect_success 'correct key' 'git config 123456.a123 987'
 230test_expect_success 'hierarchical section' \
 232        'git config Version.1.2.3eX.Alpha beta'
 233cat > expect << EOF
 235[beta] ; silly comment # another comment
 236noIndent= sillyValue ; 'nother silly comment
 237# empty line
 239                ; comment
 240[nextSection]
 241        NoNewLine = wow2 for me
 242[123456]
 243        a123 = 987
 244[Version "1.2.3eX"]
 245        Alpha = beta
 246EOF
 247test_expect_success 'hierarchical section value' 'cmp .git/config expect'
 249cat > expect << EOF
 251beta.noindent=sillyValue
 252nextsection.nonewline=wow2 for me
 253123456.a123=987
 254version.1.2.3eX.alpha=beta
 255EOF
 256test_expect_success 'working --list' \
 258        'git config --list > output && cmp output expect'
 259cat > expect << EOF
 261beta.noindent sillyValue
 262nextsection.nonewline wow2 for me
 263EOF
 264test_expect_success '--get-regexp' \
 266        'git config --get-regexp in > output && cmp output expect'
 267git config --add nextsection.nonewline "wow4 for you"
 269cat > expect << EOF
 271wow2 for me
 272wow4 for you
 273EOF
 274test_expect_success '--add' \
 276        'git config --get-all nextsection.nonewline > output && cmp output expect'
 277cat > .git/config << EOF
 279[novalue]
 280        variable
 281EOF
 282test_expect_success 'get variable with no value' \
 284        'git config --get novalue.variable ^$'
 285echo novalue.variable > expect
 287test_expect_success 'get-regexp variable with no value' \
 289        'git config --get-regexp novalue > output &&
 290         cmp output expect'
 291git config > output 2>&1
 293test_expect_success 'no arguments, but no crash' \
 295        "test $? = 129 && grep usage output"
 296cat > .git/config << EOF
 298[a.b]
 299        c = d
 300EOF
 301git config a.x y
 303cat > expect << EOF
 305[a.b]
 306        c = d
 307[a]
 308        x = y
 309EOF
 310test_expect_success 'new section is partial match of another' 'cmp .git/config expect'
 312git config b.x y
 314git config a.b c
 315cat > expect << EOF
 317[a.b]
 318        c = d
 319[a]
 320        x = y
 321        b = c
 322[b]
 323        x = y
 324EOF
 325test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect'
 327test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \
 329        'git config --file non-existing-config -l; test $? != 0'
 330cat > other-config << EOF
 332[ein]
 333        bahn = strasse
 334EOF
 335cat > expect << EOF
 337ein.bahn=strasse
 338EOF
 339GIT_CONFIG=other-config git config -l > output
 341test_expect_success 'alternative GIT_CONFIG' 'cmp output expect'
 343test_expect_success 'alternative GIT_CONFIG (--file)' \
 345        'git config --file other-config -l > output && cmp output expect'
 346GIT_CONFIG=other-config git config anwohner.park ausweis
 348cat > expect << EOF
 350[ein]
 351        bahn = strasse
 352[anwohner]
 353        park = ausweis
 354EOF
 355test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect'
 357cat > .git/config << EOF
 359# Hallo
 360        #Bello
 361[branch "eins"]
 362        x = 1
 363[branch.eins]
 364        y = 1
 365        [branch "1 234 blabl/a"]
 366weird
 367EOF
 368test_expect_success "rename section" \
 370        "git config --rename-section branch.eins branch.zwei"
 371cat > expect << EOF
 373# Hallo
 374        #Bello
 375[branch "zwei"]
 376        x = 1
 377[branch "zwei"]
 378        y = 1
 379        [branch "1 234 blabl/a"]
 380weird
 381EOF
 382test_expect_success "rename succeeded" "git diff expect .git/config"
 384test_expect_failure "rename non-existing section" \
 386        'git config --rename-section branch."world domination" branch.drei'
 387test_expect_success "rename succeeded" "git diff expect .git/config"
 389test_expect_success "rename another section" \
 391        'git config --rename-section branch."1 234 blabl/a" branch.drei'
 392cat > expect << EOF
 394# Hallo
 395        #Bello
 396[branch "zwei"]
 397        x = 1
 398[branch "zwei"]
 399        y = 1
 400[branch "drei"]
 401weird
 402EOF
 403test_expect_success "rename succeeded" "git diff expect .git/config"
 405cat >> .git/config << EOF
 407  [branch "zwei"] a = 1 [branch "vier"]
 408EOF
 409test_expect_success "remove section" "git config --remove-section branch.zwei"
 411cat > expect << EOF
 413# Hallo
 414        #Bello
 415[branch "drei"]
 416weird
 417EOF
 418test_expect_success "section was removed properly" \
 420        "git diff -u expect .git/config"
 421rm .git/config
 423cat > expect << EOF
 425[gitcvs]
 426        enabled = true
 427        dbname = %Ggitcvs2.%a.%m.sqlite
 428[gitcvs "ext"]
 429        dbname = %Ggitcvs1.%a.%m.sqlite
 430EOF
 431test_expect_success 'section ending' '
 433        git config gitcvs.enabled true &&
 435        git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
 436        git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
 437        cmp .git/config expect
 438'
 440test_expect_success numbers '
 442        git config kilo.gram 1k &&
 444        git config mega.ton 1m &&
 445        k=$(git config --int --get kilo.gram) &&
 446        test z1024 = "z$k" &&
 447        m=$(git config --int --get mega.ton) &&
 448        test z1048576 = "z$m"
 449'
 450cat > expect << EOF
 452true
 453false
 454true
 455false
 456true
 457false
 458true
 459false
 460EOF
 461test_expect_success bool '
 463        git config bool.true1 01 &&
 465        git config bool.true2 -1 &&
 466        git config bool.true3 YeS &&
 467        git config bool.true4 true &&
 468        git config bool.false1 000 &&
 469        git config bool.false2 "" &&
 470        git config bool.false3 nO &&
 471        git config bool.false4 FALSE &&
 472        rm -f result &&
 473        for i in 1 2 3 4
 474        do
 475            git config --bool --get bool.true$i >>result
 476            git config --bool --get bool.false$i >>result
 477        done &&
 478        cmp expect result'
 479test_expect_failure 'invalid bool (--get)' '
 481        git config bool.nobool foobar &&
 483        git config --bool --get bool.nobool'
 484test_expect_failure 'invalid bool (set)' '
 486        git config --bool bool.nobool foobar'
 488rm .git/config
 490cat > expect <<\EOF
 492[bool]
 493        true1 = true
 494        true2 = true
 495        true3 = true
 496        true4 = true
 497        false1 = false
 498        false2 = false
 499        false3 = false
 500        false4 = false
 501EOF
 502test_expect_success 'set --bool' '
 504        git config --bool bool.true1 01 &&
 506        git config --bool bool.true2 -1 &&
 507        git config --bool bool.true3 YeS &&
 508        git config --bool bool.true4 true &&
 509        git config --bool bool.false1 000 &&
 510        git config --bool bool.false2 "" &&
 511        git config --bool bool.false3 nO &&
 512        git config --bool bool.false4 FALSE &&
 513        cmp expect .git/config'
 514rm .git/config
 516cat > expect <<\EOF
 518[int]
 519        val1 = 1
 520        val2 = -1
 521        val3 = 5242880
 522EOF
 523test_expect_success 'set --int' '
 525        git config --int int.val1 01 &&
 527        git config --int int.val2 -1 &&
 528        git config --int int.val3 5m &&
 529        cmp expect .git/config'
 530rm .git/config
 532git config quote.leading " test"
 534git config quote.ending "test "
 535git config quote.semicolon "test;test"
 536git config quote.hash "test#test"
 537cat > expect << EOF
 539[quote]
 540        leading = " test"
 541        ending = "test "
 542        semicolon = "test;test"
 543        hash = "test#test"
 544EOF
 545test_expect_success 'quoting' 'cmp .git/config expect'
 547test_expect_failure 'key with newline' 'git config key.with\\\
 549newline 123'
 550test_expect_success 'value with newline' 'git config key.sub value.with\\\
 552newline'
 553cat > .git/config <<\EOF
 555[section]
 556        ; comment \
 557        continued = cont\
 558inued
 559        noncont   = not continued ; \
 560        quotecont = "cont;\
 561inued"
 562EOF
 563cat > expect <<\EOF
 565section.continued=continued
 566section.noncont=not continued
 567section.quotecont=cont;inued
 568EOF
 569git config --list > result
 571test_expect_success 'value continued on next line' 'cmp result expect'
 573cat > .git/config <<\EOF
 575[section "sub=section"]
 576        val1 = foo=bar
 577        val2 = foo\nbar
 578        val3 = \n\n
 579        val4 =
 580        val5
 581EOF
 582cat > expect <<\EOF
 584section.sub=section.val1
 585foo=barQsection.sub=section.val2
 586foo
 587barQsection.sub=section.val3
 588Qsection.sub=section.val4
 591Qsection.sub=section.val5Q
 592EOF
 593git config --null --list | tr '[\000]' 'Q' > result
 595echo >>result
 596test_expect_success '--null --list' 'cmp result expect'
 598git config --null --get-regexp 'val[0-9]' | tr '[\000]' 'Q' > result
 600echo >>result
 601test_expect_success '--null --get-regexp' 'cmp result expect'
 603test_expect_success 'symlinked configuration' '
 605        ln -s notyet myconfig &&
 607        GIT_CONFIG=myconfig git config test.frotz nitfol &&
 608        test -h myconfig &&
 609        test -f notyet &&
 610        test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
 611        GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
 612        test -h myconfig &&
 613        test -f notyet &&
 614        test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
 615        test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov
 616'
 618test_done