Jeff King | 02e5ba4 | 2008-01-01 01:17:34 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='Test wacky input to git config' |
| 4 | . ./test-lib.sh |
| 5 | |
Thomas Rast | 83786fa | 2013-11-13 11:19:00 +0100 | [diff] [blame] | 6 | # Leaving off the newline is intentional! |
Jeff King | 02e5ba4 | 2008-01-01 01:17:34 -0500 | [diff] [blame] | 7 | setup() { |
| 8 | (printf "[section]\n" && |
| 9 | printf " key = foo") >.git/config |
| 10 | } |
| 11 | |
Thomas Rast | 83786fa | 2013-11-13 11:19:00 +0100 | [diff] [blame] | 12 | # 'check section.key value' verifies that the entry for section.key is |
| 13 | # 'value' |
Jeff King | 02e5ba4 | 2008-01-01 01:17:34 -0500 | [diff] [blame] | 14 | check() { |
| 15 | echo "$2" >expected |
Thomas Jarosch | e0b3cc0 | 2009-04-17 14:05:11 +0200 | [diff] [blame] | 16 | git config --get "$1" >actual 2>&1 |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 17 | test_cmp expected actual |
Jeff King | 02e5ba4 | 2008-01-01 01:17:34 -0500 | [diff] [blame] | 18 | } |
| 19 | |
Thomas Rast | 83786fa | 2013-11-13 11:19:00 +0100 | [diff] [blame] | 20 | # 'check section.key regex value' verifies that the entry for |
| 21 | # section.key *that matches 'regex'* is 'value' |
| 22 | check_regex() { |
| 23 | echo "$3" >expected |
| 24 | git config --get "$1" "$2" >actual 2>&1 |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 25 | test_cmp expected actual |
Thomas Rast | 83786fa | 2013-11-13 11:19:00 +0100 | [diff] [blame] | 26 | } |
| 27 | |
Jeff King | 02e5ba4 | 2008-01-01 01:17:34 -0500 | [diff] [blame] | 28 | test_expect_success 'modify same key' ' |
| 29 | setup && |
| 30 | git config section.key bar && |
| 31 | check section.key bar |
| 32 | ' |
| 33 | |
| 34 | test_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 | |
| 41 | test_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 | |
Bryan Donlan | e5c349b | 2008-05-04 01:37:52 -0400 | [diff] [blame] | 48 | SECTION="test.q\"s\\sq'sp e.key" |
Nanako Shiraishi | 0cb0e14 | 2008-09-03 17:59:27 +0900 | [diff] [blame] | 49 | test_expect_success 'make sure git config escapes section names properly' ' |
Bryan Donlan | e5c349b | 2008-05-04 01:37:52 -0400 | [diff] [blame] | 50 | git config "$SECTION" bar && |
| 51 | check "$SECTION" bar |
| 52 | ' |
| 53 | |
Thomas Jarosch | e0b3cc0 | 2009-04-17 14:05:11 +0200 | [diff] [blame] | 54 | LONG_VALUE=$(printf "x%01021dx a" 7) |
| 55 | test_expect_success 'do not crash on special long config line' ' |
| 56 | setup && |
| 57 | git config section.key "$LONG_VALUE" && |
Erik Faye-Lund | e96c19c | 2011-04-10 22:54:18 +0200 | [diff] [blame] | 58 | check section.key "$LONG_VALUE" |
Thomas Jarosch | e0b3cc0 | 2009-04-17 14:05:11 +0200 | [diff] [blame] | 59 | ' |
| 60 | |
Thomas Rast | 83786fa | 2013-11-13 11:19:00 +0100 | [diff] [blame] | 61 | setup_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 | |
| 82 | test_expect_success 'get many entries' ' |
| 83 | setup_many && |
| 84 | git config --get-all section.key >actual && |
| 85 | test_line_count = 3126 actual |
| 86 | ' |
| 87 | |
| 88 | test_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 | |
| 94 | test_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 | |
| 102 | test_expect_success 'replace many entries' ' |
| 103 | setup_many && |
| 104 | git config --replace-all section.key bar && |
| 105 | check section.key bar |
| 106 | ' |
| 107 | |
| 108 | test_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 | |
Tanay Abhra | c846664 | 2014-08-18 03:17:57 -0700 | [diff] [blame] | 114 | test_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 | |
Jeff King | 02e5ba4 | 2008-01-01 01:17:34 -0500 | [diff] [blame] | 134 | test_done |