Merge branch 'em/man-bold-literal'
[git.git] / t / t1303-wacky-config.sh
blob3b92083e19d09bad951519201f9605a17b168c1a
1 #!/bin/sh
3 test_description='Test wacky input to git config'
4 . ./test-lib.sh
6 # Leaving off the newline is intentional!
7 setup() {
8 (printf "[section]\n" &&
9 printf " key = foo") >.git/config
12 # 'check section.key value' verifies that the entry for section.key is
13 # 'value'
14 check() {
15 echo "$2" >expected
16 git config --get "$1" >actual 2>&1
17 test_cmp actual expected
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
25 test_cmp actual expected
28 test_expect_success 'modify same key' '
29 setup &&
30 git config section.key bar &&
31 check section.key bar
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
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
48 SECTION="test.q\"s\\sq'sp e.key"
49 test_expect_success 'make sure git config escapes section names properly' '
50 git config "$SECTION" bar &&
51 check "$SECTION" bar
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" &&
58 check section.key "$LONG_VALUE"
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
82 test_expect_success 'get many entries' '
83 setup_many &&
84 git config --get-all section.key >actual &&
85 test_line_count = 3126 actual
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
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
102 test_expect_success 'replace many entries' '
103 setup_many &&
104 git config --replace-all section.key bar &&
105 check section.key bar
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
114 test_expect_success '--add appends new value after existing empty value' '
115 cat >expect <<-\EOF &&
118 fool
119 roll
121 cp .git/config .git/config.old &&
122 test_when_finished "mv .git/config.old .git/config" &&
123 cat >.git/config <<-\EOF &&
124 [foo]
126 baz =
127 baz = fool
129 git config --add foo.baz roll &&
130 git config --get-all foo.baz >output &&
131 test_cmp expect output
134 test_done