]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1300-repo-config.sh
unpack-trees.c: verify_uptodate: remove dead code
[thirdparty/git.git] / t / t1300-repo-config.sh
CommitLineData
942c1f53
JS
1#!/bin/sh
2#
3# Copyright (c) 2005 Johannes Schindelin
4#
5
e0d10e1c 6test_description='Test git-config in different settings'
942c1f53
JS
7
8. ./test-lib.sh
9
10test -f .git/config && rm .git/config
11
e0d10e1c 12git-config core.penguin "little blue"
942c1f53
JS
13
14cat > expect << EOF
942c1f53
JS
15[core]
16 penguin = little blue
17EOF
18
19test_expect_success 'initial' 'cmp .git/config expect'
20
e0d10e1c 21git-config Core.Movie BadPhysics
942c1f53
JS
22
23cat > expect << EOF
942c1f53
JS
24[core]
25 penguin = little blue
26 Movie = BadPhysics
27EOF
28
29test_expect_success 'mixed case' 'cmp .git/config expect'
30
e0d10e1c 31git-config Cores.WhatEver Second
942c1f53
JS
32
33cat > expect << EOF
942c1f53
JS
34[core]
35 penguin = little blue
36 Movie = BadPhysics
37[Cores]
38 WhatEver = Second
39EOF
40
41test_expect_success 'similar section' 'cmp .git/config expect'
42
e0d10e1c 43git-config CORE.UPPERCASE true
942c1f53
JS
44
45cat > expect << EOF
942c1f53
JS
46[core]
47 penguin = little blue
48 Movie = BadPhysics
49 UPPERCASE = true
50[Cores]
51 WhatEver = Second
52EOF
53
54test_expect_success 'similar section' 'cmp .git/config expect'
55
f98d863d 56test_expect_success 'replace with non-match' \
e0d10e1c 57 'git-config core.penguin kingpin !blue'
f98d863d
JS
58
59test_expect_success 'replace with non-match (actually matching)' \
e0d10e1c 60 'git-config core.penguin "very blue" !kingpin'
f98d863d
JS
61
62cat > expect << EOF
f98d863d
JS
63[core]
64 penguin = very blue
65 Movie = BadPhysics
66 UPPERCASE = true
67 penguin = kingpin
68[Cores]
69 WhatEver = Second
70EOF
71
72test_expect_success 'non-match result' 'cmp .git/config expect'
73
942c1f53
JS
74cat > .git/config << EOF
75[beta] ; silly comment # another comment
76noIndent= sillyValue ; 'nother silly comment
77
78# empty line
79 ; comment
80 haha ="beta" # last silly comment
4ddba79d
JS
81haha = hello
82 haha = bello
942c1f53
JS
83[nextSection] noNewline = ouch
84EOF
85
4ddba79d
JS
86cp .git/config .git/config2
87
88test_expect_success 'multiple unset' \
e0d10e1c 89 'git-config --unset-all beta.haha'
4ddba79d
JS
90
91cat > expect << EOF
92[beta] ; silly comment # another comment
93noIndent= sillyValue ; 'nother silly comment
94
95# empty line
96 ; comment
97[nextSection] noNewline = ouch
98EOF
99
100test_expect_success 'multiple unset is correct' 'cmp .git/config expect'
101
102mv .git/config2 .git/config
103
104test_expect_success '--replace-all' \
e0d10e1c 105 'git-config --replace-all beta.haha gamma'
4ddba79d
JS
106
107cat > expect << EOF
108[beta] ; silly comment # another comment
109noIndent= sillyValue ; 'nother silly comment
110
111# empty line
112 ; comment
113 haha = gamma
114[nextSection] noNewline = ouch
115EOF
116
117test_expect_success 'all replaced' 'cmp .git/config expect'
118
e0d10e1c 119git-config beta.haha alpha
942c1f53
JS
120
121cat > expect << EOF
122[beta] ; silly comment # another comment
123noIndent= sillyValue ; 'nother silly comment
124
125# empty line
126 ; comment
127 haha = alpha
128[nextSection] noNewline = ouch
129EOF
130
131test_expect_success 'really mean test' 'cmp .git/config expect'
132
e0d10e1c 133git-config nextsection.nonewline wow
942c1f53
JS
134
135cat > expect << EOF
136[beta] ; silly comment # another comment
137noIndent= sillyValue ; 'nother silly comment
138
139# empty line
140 ; comment
141 haha = alpha
142[nextSection]
143 nonewline = wow
144EOF
145
146test_expect_success 'really really mean test' 'cmp .git/config expect'
147
e0d10e1c
TP
148test_expect_success 'get value' 'test alpha = $(git-config beta.haha)'
149git-config --unset beta.haha
942c1f53
JS
150
151cat > expect << EOF
152[beta] ; silly comment # another comment
153noIndent= sillyValue ; 'nother silly comment
154
155# empty line
156 ; comment
157[nextSection]
158 nonewline = wow
159EOF
160
161test_expect_success 'unset' 'cmp .git/config expect'
162
e0d10e1c 163git-config nextsection.NoNewLine "wow2 for me" "for me$"
942c1f53
JS
164
165cat > expect << EOF
166[beta] ; silly comment # another comment
167noIndent= sillyValue ; 'nother silly comment
168
169# empty line
170 ; comment
171[nextSection]
172 nonewline = wow
173 NoNewLine = wow2 for me
174EOF
175
176test_expect_success 'multivar' 'cmp .git/config expect'
177
f98d863d 178test_expect_success 'non-match' \
e0d10e1c 179 'git-config --get nextsection.nonewline !for'
f98d863d
JS
180
181test_expect_success 'non-match value' \
e0d10e1c 182 'test wow = $(git-config --get nextsection.nonewline !for)'
f98d863d 183
4ddba79d 184test_expect_failure 'ambiguous get' \
e0d10e1c 185 'git-config --get nextsection.nonewline'
4ddba79d
JS
186
187test_expect_success 'get multivar' \
e0d10e1c 188 'git-config --get-all nextsection.nonewline'
4ddba79d 189
e0d10e1c 190git-config nextsection.nonewline "wow3" "wow$"
942c1f53
JS
191
192cat > expect << EOF
193[beta] ; silly comment # another comment
194noIndent= sillyValue ; 'nother silly comment
195
196# empty line
197 ; comment
198[nextSection]
199 nonewline = wow3
200 NoNewLine = wow2 for me
201EOF
202
203test_expect_success 'multivar replace' 'cmp .git/config expect'
204
e0d10e1c 205test_expect_failure 'ambiguous value' 'git-config nextsection.nonewline'
4ddba79d 206
942c1f53 207test_expect_failure 'ambiguous unset' \
e0d10e1c 208 'git-config --unset nextsection.nonewline'
942c1f53
JS
209
210test_expect_failure 'invalid unset' \
e0d10e1c 211 'git-config --unset somesection.nonewline'
942c1f53 212
e0d10e1c 213git-config --unset nextsection.nonewline "wow3$"
942c1f53
JS
214
215cat > expect << EOF
216[beta] ; silly comment # another comment
217noIndent= sillyValue ; 'nother silly comment
218
219# empty line
220 ; comment
221[nextSection]
222 NoNewLine = wow2 for me
223EOF
224
225test_expect_success 'multivar unset' 'cmp .git/config expect'
226
e0d10e1c 227test_expect_failure 'invalid key' 'git-config inval.2key blabla'
942c1f53 228
e0d10e1c 229test_expect_success 'correct key' 'git-config 123456.a123 987'
942c1f53 230
b17e659d 231test_expect_success 'hierarchical section' \
e0d10e1c 232 'git-config Version.1.2.3eX.Alpha beta'
b17e659d
JS
233
234cat > expect << EOF
235[beta] ; silly comment # another comment
236noIndent= sillyValue ; 'nother silly comment
237
238# empty line
239 ; comment
240[nextSection]
241 NoNewLine = wow2 for me
242[123456]
243 a123 = 987
d14f7764
LT
244[Version "1.2.3eX"]
245 Alpha = beta
b17e659d
JS
246EOF
247
248test_expect_success 'hierarchical section value' 'cmp .git/config expect'
249
2fa9a0fb
JS
250cat > expect << EOF
251beta.noindent=sillyValue
252nextsection.nonewline=wow2 for me
253123456.a123=987
d55aaefa 254version.1.2.3eX.alpha=beta
2fa9a0fb
JS
255EOF
256
257test_expect_success 'working --list' \
e0d10e1c 258 'git-config --list > output && cmp output expect'
2fa9a0fb
JS
259
260cat > expect << EOF
261beta.noindent sillyValue
262nextsection.nonewline wow2 for me
263EOF
264
265test_expect_success '--get-regexp' \
e0d10e1c 266 'git-config --get-regexp in > output && cmp output expect'
2fa9a0fb 267
e0d10e1c 268git-config --add nextsection.nonewline "wow4 for you"
89c4afe0
BG
269
270cat > expect << EOF
271wow2 for me
272wow4 for you
273EOF
274
275test_expect_success '--add' \
e0d10e1c 276 'git-config --get-all nextsection.nonewline > output && cmp output expect'
89c4afe0 277
f067a137
JF
278cat > .git/config << EOF
279[novalue]
280 variable
281EOF
282
283test_expect_success 'get variable with no value' \
e0d10e1c 284 'git-config --get novalue.variable ^$'
f067a137 285
e0d10e1c 286git-config > output 2>&1
2fa9a0fb
JS
287
288test_expect_success 'no arguments, but no crash' \
289 "test $? = 129 && grep usage output"
290
bd886fd3
SE
291cat > .git/config << EOF
292[a.b]
293 c = d
294EOF
295
e0d10e1c 296git-config a.x y
bd886fd3
SE
297
298cat > expect << EOF
299[a.b]
300 c = d
301[a]
302 x = y
303EOF
304
305test_expect_success 'new section is partial match of another' 'cmp .git/config expect'
306
e0d10e1c
TP
307git-config b.x y
308git-config a.b c
bd886fd3
SE
309
310cat > expect << EOF
311[a.b]
312 c = d
313[a]
314 x = y
315 b = c
316[b]
317 x = y
318EOF
319
320test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect'
321
9c3796fc
JS
322cat > other-config << EOF
323[ein]
324 bahn = strasse
325EOF
326
327cat > expect << EOF
328ein.bahn=strasse
329EOF
330
e0d10e1c 331GIT_CONFIG=other-config git-config -l > output
9c3796fc
JS
332
333test_expect_success 'alternative GIT_CONFIG' 'cmp output expect'
334
e0d10e1c 335GIT_CONFIG=other-config git-config anwohner.park ausweis
9c3796fc
JS
336
337cat > expect << EOF
338[ein]
339 bahn = strasse
340[anwohner]
341 park = ausweis
342EOF
343
344test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect'
345
0667fcfb
JS
346cat > .git/config << EOF
347# Hallo
348 #Bello
349[branch "eins"]
350 x = 1
351[branch.eins]
352 y = 1
353 [branch "1 234 blabl/a"]
354weird
355EOF
356
357test_expect_success "rename section" \
e0d10e1c 358 "git-config --rename-section branch.eins branch.zwei"
0667fcfb
JS
359
360cat > expect << EOF
361# Hallo
362 #Bello
363[branch "zwei"]
364 x = 1
365[branch "zwei"]
366 y = 1
367 [branch "1 234 blabl/a"]
368weird
369EOF
370
5bd74506 371test_expect_success "rename succeeded" "git diff expect .git/config"
0667fcfb
JS
372
373test_expect_failure "rename non-existing section" \
e0d10e1c 374 'git-config --rename-section branch."world domination" branch.drei'
0667fcfb 375
5bd74506 376test_expect_success "rename succeeded" "git diff expect .git/config"
0667fcfb
JS
377
378test_expect_success "rename another section" \
e0d10e1c 379 'git-config --rename-section branch."1 234 blabl/a" branch.drei'
0667fcfb
JS
380
381cat > expect << EOF
382# Hallo
383 #Bello
384[branch "zwei"]
385 x = 1
386[branch "zwei"]
387 y = 1
388[branch "drei"]
389weird
390EOF
391
5bd74506 392test_expect_success "rename succeeded" "git diff expect .git/config"
0667fcfb 393
118f8b24
PB
394cat >> .git/config << EOF
395 [branch "zwei"] a = 1 [branch "vier"]
396EOF
397
398test_expect_success "remove section" "git config --remove-section branch.zwei"
399
400cat > expect << EOF
401# Hallo
402 #Bello
403[branch "drei"]
404weird
405EOF
406
407test_expect_success "section was removed properly" \
cf6981d4 408 "git diff -u expect .git/config"
118f8b24 409
b18a2be3
SP
410rm .git/config
411
412cat > expect << EOF
413[gitcvs]
414 enabled = true
415 dbname = %Ggitcvs2.%a.%m.sqlite
416[gitcvs "ext"]
417 dbname = %Ggitcvs1.%a.%m.sqlite
418EOF
419
420test_expect_success 'section ending' '
421
422 git-config gitcvs.enabled true &&
423 git-config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
424 git-config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
425 cmp .git/config expect
426
427'
428
d77a64d3
SP
429test_expect_success numbers '
430
e0d10e1c
TP
431 git-config kilo.gram 1k &&
432 git-config mega.ton 1m &&
433 k=$(git-config --int --get kilo.gram) &&
d77a64d3 434 test z1024 = "z$k" &&
e0d10e1c 435 m=$(git-config --int --get mega.ton) &&
d77a64d3
SP
436 test z1048576 = "z$m"
437'
438
cdd4fb15
BG
439rm .git/config
440
e0d10e1c
TP
441git-config quote.leading " test"
442git-config quote.ending "test "
443git-config quote.semicolon "test;test"
444git-config quote.hash "test#test"
cdd4fb15
BG
445
446cat > expect << EOF
447[quote]
448 leading = " test"
449 ending = "test "
450 semicolon = "test;test"
451 hash = "test#test"
452EOF
453
454test_expect_success 'quoting' 'cmp .git/config expect'
455
e0d10e1c 456test_expect_failure 'key with newline' 'git config key.with\\\
6f71686e
JS
457newline 123'
458
e0d10e1c 459test_expect_success 'value with newline' 'git config key.sub value.with\\\
6f71686e
JS
460newline'
461
83cd10a0
JN
462cat > .git/config <<\EOF
463[section]
464 ; comment \
465 continued = cont\
466inued
467 noncont = not continued ; \
468 quotecont = "cont;\
469inued"
470EOF
471
472cat > expect <<\EOF
473section.continued=continued
474section.noncont=not continued
475section.quotecont=cont;inued
476EOF
477
e0d10e1c 478git config --list > result
83cd10a0
JN
479
480test_expect_success 'value continued on next line' 'cmp result expect'
481
942c1f53
JS
482test_done
483