84977355a3a1e7812964c3bcbc37f1aa9c67e846
   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_failure 'ambiguous get' \
 185        'git-config --get nextsection.nonewline'
 186
 187test_expect_success 'get multivar' \
 188        'git-config --get-all nextsection.nonewline'
 189
 190git-config nextsection.nonewline "wow3" "wow$"
 191
 192cat > expect << EOF
 193[beta] ; silly comment # another comment
 194noIndent= sillyValue ; 'nother silly comment
 195
 196# empty line
 197                ; comment
 198[nextSection]
 199        nonewline = wow3
 200        NoNewLine = wow2 for me
 201EOF
 202
 203test_expect_success 'multivar replace' 'cmp .git/config expect'
 204
 205test_expect_failure 'ambiguous value' 'git-config nextsection.nonewline'
 206
 207test_expect_failure 'ambiguous unset' \
 208        'git-config --unset nextsection.nonewline'
 209
 210test_expect_failure 'invalid unset' \
 211        'git-config --unset somesection.nonewline'
 212
 213git-config --unset nextsection.nonewline "wow3$"
 214
 215cat > expect << EOF
 216[beta] ; silly comment # another comment
 217noIndent= sillyValue ; 'nother silly comment
 218
 219# empty line
 220                ; comment
 221[nextSection]
 222        NoNewLine = wow2 for me
 223EOF
 224
 225test_expect_success 'multivar unset' 'cmp .git/config expect'
 226
 227test_expect_failure 'invalid key' 'git-config inval.2key blabla'
 228
 229test_expect_success 'correct key' 'git-config 123456.a123 987'
 230
 231test_expect_success 'hierarchical section' \
 232        'git-config Version.1.2.3eX.Alpha beta'
 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
 242[123456]
 243        a123 = 987
 244[Version "1.2.3eX"]
 245        Alpha = beta
 246EOF
 247
 248test_expect_success 'hierarchical section value' 'cmp .git/config expect'
 249
 250cat > expect << EOF
 251beta.noindent=sillyValue
 252nextsection.nonewline=wow2 for me
 253123456.a123=987
 254version.1.2.3eX.alpha=beta
 255EOF
 256
 257test_expect_success 'working --list' \
 258        'git-config --list > output && cmp output expect'
 259
 260cat > expect << EOF
 261beta.noindent sillyValue
 262nextsection.nonewline wow2 for me
 263EOF
 264
 265test_expect_success '--get-regexp' \
 266        'git-config --get-regexp in > output && cmp output expect'
 267
 268git-config --add nextsection.nonewline "wow4 for you"
 269
 270cat > expect << EOF
 271wow2 for me
 272wow4 for you
 273EOF
 274
 275test_expect_success '--add' \
 276        'git-config --get-all nextsection.nonewline > output && cmp output expect'
 277
 278cat > .git/config << EOF
 279[novalue]
 280        variable
 281EOF
 282
 283test_expect_success 'get variable with no value' \
 284        'git-config --get novalue.variable ^$'
 285
 286echo novalue.variable > expect
 287
 288test_expect_success 'get-regexp variable with no value' \
 289        'git-config --get-regexp novalue > output &&
 290         cmp output expect'
 291
 292git-config > output 2>&1
 293
 294test_expect_success 'no arguments, but no crash' \
 295        "test $? = 129 && grep usage output"
 296
 297cat > .git/config << EOF
 298[a.b]
 299        c = d
 300EOF
 301
 302git-config a.x y
 303
 304cat > expect << EOF
 305[a.b]
 306        c = d
 307[a]
 308        x = y
 309EOF
 310
 311test_expect_success 'new section is partial match of another' 'cmp .git/config expect'
 312
 313git-config b.x y
 314git-config a.b c
 315
 316cat > expect << EOF
 317[a.b]
 318        c = d
 319[a]
 320        x = y
 321        b = c
 322[b]
 323        x = y
 324EOF
 325
 326test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect'
 327
 328cat > other-config << EOF
 329[ein]
 330        bahn = strasse
 331EOF
 332
 333cat > expect << EOF
 334ein.bahn=strasse
 335EOF
 336
 337GIT_CONFIG=other-config git-config -l > output
 338
 339test_expect_success 'alternative GIT_CONFIG' 'cmp output expect'
 340
 341GIT_CONFIG=other-config git-config anwohner.park ausweis
 342
 343cat > expect << EOF
 344[ein]
 345        bahn = strasse
 346[anwohner]
 347        park = ausweis
 348EOF
 349
 350test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect'
 351
 352cat > .git/config << EOF
 353# Hallo
 354        #Bello
 355[branch "eins"]
 356        x = 1
 357[branch.eins]
 358        y = 1
 359        [branch "1 234 blabl/a"]
 360weird
 361EOF
 362
 363test_expect_success "rename section" \
 364        "git-config --rename-section branch.eins branch.zwei"
 365
 366cat > expect << EOF
 367# Hallo
 368        #Bello
 369[branch "zwei"]
 370        x = 1
 371[branch "zwei"]
 372        y = 1
 373        [branch "1 234 blabl/a"]
 374weird
 375EOF
 376
 377test_expect_success "rename succeeded" "git diff expect .git/config"
 378
 379test_expect_failure "rename non-existing section" \
 380        'git-config --rename-section branch."world domination" branch.drei'
 381
 382test_expect_success "rename succeeded" "git diff expect .git/config"
 383
 384test_expect_success "rename another section" \
 385        'git-config --rename-section branch."1 234 blabl/a" branch.drei'
 386
 387cat > expect << EOF
 388# Hallo
 389        #Bello
 390[branch "zwei"]
 391        x = 1
 392[branch "zwei"]
 393        y = 1
 394[branch "drei"]
 395weird
 396EOF
 397
 398test_expect_success "rename succeeded" "git diff expect .git/config"
 399
 400cat >> .git/config << EOF
 401  [branch "zwei"] a = 1 [branch "vier"]
 402EOF
 403
 404test_expect_success "remove section" "git config --remove-section branch.zwei"
 405
 406cat > expect << EOF
 407# Hallo
 408        #Bello
 409[branch "drei"]
 410weird
 411EOF
 412
 413test_expect_success "section was removed properly" \
 414        "git diff -u expect .git/config"
 415
 416rm .git/config
 417
 418cat > expect << EOF
 419[gitcvs]
 420        enabled = true
 421        dbname = %Ggitcvs2.%a.%m.sqlite
 422[gitcvs "ext"]
 423        dbname = %Ggitcvs1.%a.%m.sqlite
 424EOF
 425
 426test_expect_success 'section ending' '
 427
 428        git-config gitcvs.enabled true &&
 429        git-config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
 430        git-config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
 431        cmp .git/config expect
 432
 433'
 434
 435test_expect_success numbers '
 436
 437        git-config kilo.gram 1k &&
 438        git-config mega.ton 1m &&
 439        k=$(git-config --int --get kilo.gram) &&
 440        test z1024 = "z$k" &&
 441        m=$(git-config --int --get mega.ton) &&
 442        test z1048576 = "z$m"
 443'
 444
 445cat > expect << EOF
 446true
 447false
 448true
 449false
 450true
 451false
 452true
 453false
 454EOF
 455
 456test_expect_success bool '
 457
 458        git-config bool.true1 01 &&
 459        git-config bool.true2 -1 &&
 460        git-config bool.true3 YeS &&
 461        git-config bool.true4 true &&
 462        git-config bool.false1 000 &&
 463        git-config bool.false2 "" &&
 464        git-config bool.false3 nO &&
 465        git-config bool.false4 FALSE &&
 466        rm -f result &&
 467        for i in 1 2 3 4
 468        do
 469            git-config --bool --get bool.true$i >>result
 470            git-config --bool --get bool.false$i >>result
 471        done &&
 472        cmp expect result'
 473
 474test_expect_failure 'invalid bool' '
 475
 476        git-config bool.nobool foobar &&
 477        git-config --bool --get bool.nobool'
 478
 479rm .git/config
 480
 481git-config quote.leading " test"
 482git-config quote.ending "test "
 483git-config quote.semicolon "test;test"
 484git-config quote.hash "test#test"
 485
 486cat > expect << EOF
 487[quote]
 488        leading = " test"
 489        ending = "test "
 490        semicolon = "test;test"
 491        hash = "test#test"
 492EOF
 493
 494test_expect_success 'quoting' 'cmp .git/config expect'
 495
 496test_expect_failure 'key with newline' 'git config key.with\\\
 497newline 123'
 498
 499test_expect_success 'value with newline' 'git config key.sub value.with\\\
 500newline'
 501
 502cat > .git/config <<\EOF
 503[section]
 504        ; comment \
 505        continued = cont\
 506inued
 507        noncont   = not continued ; \
 508        quotecont = "cont;\
 509inued"
 510EOF
 511
 512cat > expect <<\EOF
 513section.continued=continued
 514section.noncont=not continued
 515section.quotecont=cont;inued
 516EOF
 517
 518git config --list > result
 519
 520test_expect_success 'value continued on next line' 'cmp result expect'
 521
 522test_done