]>
Commit | Line | Data |
---|---|---|
02e5ba4a JK |
1 | #!/bin/sh |
2 | ||
3 | test_description='Test wacky input to git config' | |
67606301 ÆAB |
4 | |
5 | TEST_PASSES_SANITIZE_LEAK=true | |
02e5ba4a JK |
6 | . ./test-lib.sh |
7 | ||
83786fa4 | 8 | # Leaving off the newline is intentional! |
02e5ba4a JK |
9 | setup() { |
10 | (printf "[section]\n" && | |
11 | printf " key = foo") >.git/config | |
12 | } | |
13 | ||
83786fa4 TR |
14 | # 'check section.key value' verifies that the entry for section.key is |
15 | # 'value' | |
02e5ba4a JK |
16 | check() { |
17 | echo "$2" >expected | |
e0b3cc0d | 18 | git config --get "$1" >actual 2>&1 |
dcbaa0b3 | 19 | test_cmp expected actual |
02e5ba4a JK |
20 | } |
21 | ||
83786fa4 TR |
22 | # 'check section.key regex value' verifies that the entry for |
23 | # section.key *that matches 'regex'* is 'value' | |
24 | check_regex() { | |
25 | echo "$3" >expected | |
26 | git config --get "$1" "$2" >actual 2>&1 | |
dcbaa0b3 | 27 | test_cmp expected actual |
83786fa4 TR |
28 | } |
29 | ||
02e5ba4a JK |
30 | test_expect_success 'modify same key' ' |
31 | setup && | |
32 | git config section.key bar && | |
33 | check section.key bar | |
34 | ' | |
35 | ||
36 | test_expect_success 'add key in same section' ' | |
37 | setup && | |
38 | git config section.other bar && | |
39 | check section.key foo && | |
40 | check section.other bar | |
41 | ' | |
42 | ||
43 | test_expect_success 'add key in different section' ' | |
44 | setup && | |
45 | git config section2.key bar && | |
46 | check section.key foo && | |
47 | check section2.key bar | |
48 | ' | |
49 | ||
e5c349ba | 50 | SECTION="test.q\"s\\sq'sp e.key" |
0cb0e143 | 51 | test_expect_success 'make sure git config escapes section names properly' ' |
e5c349ba BD |
52 | git config "$SECTION" bar && |
53 | check "$SECTION" bar | |
54 | ' | |
55 | ||
e0b3cc0d TJ |
56 | LONG_VALUE=$(printf "x%01021dx a" 7) |
57 | test_expect_success 'do not crash on special long config line' ' | |
58 | setup && | |
59 | git config section.key "$LONG_VALUE" && | |
e96c19c5 | 60 | check section.key "$LONG_VALUE" |
e0b3cc0d TJ |
61 | ' |
62 | ||
83786fa4 TR |
63 | setup_many() { |
64 | setup && | |
65 | # This time we want the newline so that we can tack on more | |
66 | # entries. | |
67 | echo >>.git/config && | |
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. | |
71 | cat >5to1 <<-\EOF && | |
72 | key = foo | |
73 | key = foo | |
74 | key = foo | |
75 | key = foo | |
76 | key = foo | |
77 | EOF | |
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 | |
82 | } | |
83 | ||
84 | test_expect_success 'get many entries' ' | |
85 | setup_many && | |
86 | git config --get-all section.key >actual && | |
87 | test_line_count = 3126 actual | |
88 | ' | |
89 | ||
90 | test_expect_success 'get many entries by regex' ' | |
91 | setup_many && | |
92 | git config --get-regexp "sec.*ke." >actual && | |
93 | test_line_count = 3126 actual | |
94 | ' | |
95 | ||
96 | test_expect_success 'add and replace one of many entries' ' | |
97 | setup_many && | |
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 | |
102 | ' | |
103 | ||
104 | test_expect_success 'replace many entries' ' | |
105 | setup_many && | |
106 | git config --replace-all section.key bar && | |
107 | check section.key bar | |
108 | ' | |
109 | ||
110 | test_expect_success 'unset many entries' ' | |
111 | setup_many && | |
112 | git config --unset-all section.key && | |
113 | test_must_fail git config section.key | |
114 | ' | |
115 | ||
c8466645 TA |
116 | test_expect_success '--add appends new value after existing empty value' ' |
117 | cat >expect <<-\EOF && | |
118 | ||
119 | ||
120 | fool | |
121 | roll | |
122 | EOF | |
123 | cp .git/config .git/config.old && | |
124 | test_when_finished "mv .git/config.old .git/config" && | |
125 | cat >.git/config <<-\EOF && | |
126 | [foo] | |
127 | baz | |
128 | baz = | |
129 | baz = fool | |
130 | EOF | |
131 | git config --add foo.baz roll && | |
132 | git config --get-all foo.baz >output && | |
133 | test_cmp expect output | |
134 | ' | |
135 | ||
02e5ba4a | 136 | test_done |