3 test_description
='Test wacky input to git config'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 # Leaving off the newline is intentional!
10 (printf "[section]\n" &&
11 printf " key = foo") >.git
/config
14 # 'check section.key value' verifies that the entry for section.key is
18 git config
--get "$1" >actual
2>&1
19 test_cmp expected actual
22 # 'check section.key regex value' verifies that the entry for
23 # section.key *that matches 'regex'* is 'value'
26 git config
--get "$1" "$2" >actual
2>&1
27 test_cmp expected actual
30 test_expect_success
'modify same key' '
32 git config section.key bar &&
36 test_expect_success
'add key in same section' '
38 git config section.other bar &&
39 check section.key foo &&
40 check section.other bar
43 test_expect_success
'add key in different section' '
45 git config section2.key bar &&
46 check section.key foo &&
47 check section2.key bar
50 SECTION
="test.q\"s\\sq'sp e.key"
51 test_expect_success
'make sure git config escapes section names properly' '
52 git config "$SECTION" bar &&
56 LONG_VALUE
=$
(printf "x%01021dx a" 7)
57 test_expect_success
'do not crash on special long config line' '
59 git config section.key "$LONG_VALUE" &&
60 check section.key "$LONG_VALUE"
65 # This time we want the newline so that we can tack on more
68 # Semi-efficient way of concatenating 5^5 = 3125 lines. Note
69 # that because 'setup' already put one line, this means 3126
70 # entries for section.key in the config file.
78 cat 5to1 5to1 5to1 5to1 5to1 >5to2 && # 25
79 cat 5to2 5to2 5to2 5to2 5to2 >5to3 && # 125
80 cat 5to3 5to3 5to3 5to3 5to3 >5to4 && # 635
81 cat 5to4 5to4 5to4 5to4 5to4 >>.git/config # 3125
84 test_expect_success 'get many entries' '
86 git config --get-all section.key >actual &&
87 test_line_count = 3126 actual
90 test_expect_success 'get many entries by regex' '
92 git config --get-regexp "sec.*ke." >actual &&
93 test_line_count = 3126 actual
96 test_expect_success 'add and replace one of many entries' '
98 git config --add section.key bar &&
99 check_regex section.key "b.*r" bar &&
100 git config section.key beer "b.*r" &&
101 check_regex section.key "b.*r" beer
104 test_expect_success 'replace many entries' '
106 git config --replace-all section.key bar &&
107 check section.key bar
110 test_expect_success 'unset many entries' '
112 git config --unset-all section.key &&
113 test_must_fail git config section.key
116 test_expect_success '--add appends new value after existing empty value' '
117 cat >expect <<-\
EOF &&
123 cp .git/config .git/config.old &&
124 test_when_finished "mv .git/config.old .git/config" &&
125 cat >.git/config <<-\EOF &&
131 git config --add foo.baz roll &&
132 git config --get-all foo.baz >output &&
133 test_cmp expect output