Commit | Line | Data |
---|---|---|
02e5ba4a JK |
1 | #!/bin/sh |
2 | ||
3 | test_description='Test wacky input to git config' | |
4 | . ./test-lib.sh | |
5 | ||
83786fa4 | 6 | # Leaving off the newline is intentional! |
02e5ba4a JK |
7 | setup() { |
8 | (printf "[section]\n" && | |
9 | printf " key = foo") >.git/config | |
10 | } | |
11 | ||
83786fa4 TR |
12 | # 'check section.key value' verifies that the entry for section.key is |
13 | # 'value' | |
02e5ba4a JK |
14 | check() { |
15 | echo "$2" >expected | |
e0b3cc0d | 16 | git config --get "$1" >actual 2>&1 |
dcbaa0b3 | 17 | test_cmp expected actual |
02e5ba4a JK |
18 | } |
19 | ||
83786fa4 TR |
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 | |
dcbaa0b3 | 25 | test_cmp expected actual |
83786fa4 TR |
26 | } |
27 | ||
02e5ba4a JK |
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 | ||
e5c349ba | 48 | SECTION="test.q\"s\\sq'sp e.key" |
0cb0e143 | 49 | test_expect_success 'make sure git config escapes section names properly' ' |
e5c349ba BD |
50 | git config "$SECTION" bar && |
51 | check "$SECTION" bar | |
52 | ' | |
53 | ||
e0b3cc0d TJ |
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" && | |
e96c19c5 | 58 | check section.key "$LONG_VALUE" |
e0b3cc0d TJ |
59 | ' |
60 | ||
83786fa4 TR |
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 | ||
c8466645 TA |
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 | ||
02e5ba4a | 134 | test_done |