1#!/bin/sh
   2#
   3# Copyright (c) 2005 Johannes Schindelin
   4#
   5test_description='Test git-repo-config in different settings'
   7. ./test-lib.sh
   9test -f .git/config && rm .git/config
  11git-repo-config core.penguin "little blue"
  13cat > expect << EOF
  15[core]
  16        penguin = little blue
  17EOF
  18test_expect_success 'initial' 'cmp .git/config expect'
  20git-repo-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-repo-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-repo-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-repo-config core.penguin kingpin !blue'
  58test_expect_success 'replace with non-match (actually matching)' \
  60        'git-repo-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-repo-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-repo-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-repo-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-repo-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-repo-config beta.haha)'
 149git-repo-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-repo-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-repo-config --get nextsection.nonewline !for'
 180test_expect_success 'non-match value' \
 182        'test wow = $(git-repo-config --get nextsection.nonewline !for)'
 183test_expect_failure 'ambiguous get' \
 185        'git-repo-config --get nextsection.nonewline'
 186test_expect_success 'get multivar' \
 188        'git-repo-config --get-all nextsection.nonewline'
 189git-repo-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-repo-config nextsection.nonewline'
 206test_expect_failure 'ambiguous unset' \
 208        'git-repo-config --unset nextsection.nonewline'
 209test_expect_failure 'invalid unset' \
 211        'git-repo-config --unset somesection.nonewline'
 212git-repo-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-repo-config inval.2key blabla'
 228test_expect_success 'correct key' 'git-repo-config 123456.a123 987'
 230test_expect_success 'hierarchical section' \
 232        'git-repo-config 1.2.3.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[1.2.3]
 245        alpha = beta
 246EOF
 247test_expect_success 'hierarchical section value' 'cmp .git/config expect'
 249test_done
 251