t / t1303-wacky-config.shon commit userdiff: add a builtin pattern for dts files (3c81760)
   1#!/bin/sh
   2
   3test_description='Test wacky input to git config'
   4. ./test-lib.sh
   5
   6# Leaving off the newline is intentional!
   7setup() {
   8        (printf "[section]\n" &&
   9        printf "  key = foo") >.git/config
  10}
  11
  12# 'check section.key value' verifies that the entry for section.key is
  13# 'value'
  14check() {
  15        echo "$2" >expected
  16        git config --get "$1" >actual 2>&1
  17        test_cmp expected actual
  18}
  19
  20# 'check section.key regex value' verifies that the entry for
  21# section.key *that matches 'regex'* is 'value'
  22check_regex() {
  23        echo "$3" >expected
  24        git config --get "$1" "$2" >actual 2>&1
  25        test_cmp expected actual
  26}
  27
  28test_expect_success 'modify same key' '
  29        setup &&
  30        git config section.key bar &&
  31        check section.key bar
  32'
  33
  34test_expect_success 'add key in same section' '
  35        setup &&
  36        git config section.other bar &&
  37        check section.key foo &&
  38        check section.other bar
  39'
  40
  41test_expect_success 'add key in different section' '
  42        setup &&
  43        git config section2.key bar &&
  44        check section.key foo &&
  45        check section2.key bar
  46'
  47
  48SECTION="test.q\"s\\sq'sp e.key"
  49test_expect_success 'make sure git config escapes section names properly' '
  50        git config "$SECTION" bar &&
  51        check "$SECTION" bar
  52'
  53
  54LONG_VALUE=$(printf "x%01021dx a" 7)
  55test_expect_success 'do not crash on special long config line' '
  56        setup &&
  57        git config section.key "$LONG_VALUE" &&
  58        check section.key "$LONG_VALUE"
  59'
  60
  61setup_many() {
  62        setup &&
  63        # This time we want the newline so that we can tack on more
  64        # entries.
  65        echo >>.git/config &&
  66        # Semi-efficient way of concatenating 5^5 = 3125 lines. Note
  67        # that because 'setup' already put one line, this means 3126
  68        # entries for section.key in the config file.
  69        cat >5to1 <<-\EOF &&
  70          key = foo
  71          key = foo
  72          key = foo
  73          key = foo
  74          key = foo
  75        EOF
  76        cat 5to1 5to1 5to1 5to1 5to1 >5to2 &&      # 25
  77        cat 5to2 5to2 5to2 5to2 5to2 >5to3 &&      # 125
  78        cat 5to3 5to3 5to3 5to3 5to3 >5to4 &&      # 635
  79        cat 5to4 5to4 5to4 5to4 5to4 >>.git/config # 3125
  80}
  81
  82test_expect_success 'get many entries' '
  83        setup_many &&
  84        git config --get-all section.key >actual &&
  85        test_line_count = 3126 actual
  86'
  87
  88test_expect_success 'get many entries by regex' '
  89        setup_many &&
  90        git config --get-regexp "sec.*ke." >actual &&
  91        test_line_count = 3126 actual
  92'
  93
  94test_expect_success 'add and replace one of many entries' '
  95        setup_many &&
  96        git config --add section.key bar &&
  97        check_regex section.key "b.*r" bar &&
  98        git config section.key beer "b.*r" &&
  99        check_regex section.key "b.*r" beer
 100'
 101
 102test_expect_success 'replace many entries' '
 103        setup_many &&
 104        git config --replace-all section.key bar &&
 105        check section.key bar
 106'
 107
 108test_expect_success 'unset many entries' '
 109        setup_many &&
 110        git config --unset-all section.key &&
 111        test_must_fail git config section.key
 112'
 113
 114test_expect_success '--add appends new value after existing empty value' '
 115        cat >expect <<-\EOF &&
 116
 117
 118        fool
 119        roll
 120        EOF
 121        cp .git/config .git/config.old &&
 122        test_when_finished "mv .git/config.old .git/config" &&
 123        cat >.git/config <<-\EOF &&
 124        [foo]
 125                baz
 126                baz =
 127                baz = fool
 128        EOF
 129        git config --add foo.baz roll &&
 130        git config --get-all foo.baz >output &&
 131        test_cmp expect output
 132'
 133
 134test_done