interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t1303-wacky-config.sh

135 lines · 3094 bytes Raw Blame History
1#!/bin/sh
2
3test_description='Test wacky input to git config'
4
5. ./test-lib.sh
6
7# Leaving off the newline is intentional!
8setup() {
9 (printf "[section]\n" &&
10 printf " key = foo") >.git/config
11}
12
13# 'check section.key value' verifies that the entry for section.key is
14# 'value'
15check() {
16 echo "$2" >expected
17 git config --get "$1" >actual 2>&1
18 test_cmp expected actual
19}
20
21# 'check section.key regex value' verifies that the entry for
22# section.key *that matches 'regex'* is 'value'
23check_regex() {
24 echo "$3" >expected
25 git config --get "$1" "$2" >actual 2>&1
26 test_cmp expected actual
27}
28
29test_expect_success 'modify same key' '
30 setup &&
31 git config section.key bar &&
32 check section.key bar
33'
34
35test_expect_success 'add key in same section' '
36 setup &&
37 git config section.other bar &&
38 check section.key foo &&
39 check section.other bar
40'
41
42test_expect_success 'add key in different section' '
43 setup &&
44 git config section2.key bar &&
45 check section.key foo &&
46 check section2.key bar
47'
48
49SECTION="test.q\"s\\sq'sp e.key"
50test_expect_success 'make sure git config escapes section names properly' '
51 git config "$SECTION" bar &&
52 check "$SECTION" bar
53'
54
55LONG_VALUE=$(printf "x%01021dx a" 7)
56test_expect_success 'do not crash on special long config line' '
57 setup &&
58 git config section.key "$LONG_VALUE" &&
59 check section.key "$LONG_VALUE"
60'
61
62setup_many() {
63 setup &&
64 # This time we want the newline so that we can tack on more
65 # entries.
66 echo >>.git/config &&
67 # Semi-efficient way of concatenating 5^5 = 3125 lines. Note
68 # that because 'setup' already put one line, this means 3126
69 # entries for section.key in the config file.
70 cat >5to1 <<-\EOF &&
71 key = foo
72 key = foo
73 key = foo
74 key = foo
75 key = foo
76 EOF
77 cat 5to1 5to1 5to1 5to1 5to1 >5to2 && # 25
78 cat 5to2 5to2 5to2 5to2 5to2 >5to3 && # 125
79 cat 5to3 5to3 5to3 5to3 5to3 >5to4 && # 635
80 cat 5to4 5to4 5to4 5to4 5to4 >>.git/config # 3125
81}
82
83test_expect_success 'get many entries' '
84 setup_many &&
85 git config --get-all section.key >actual &&
86 test_line_count = 3126 actual
87'
88
89test_expect_success 'get many entries by regex' '
90 setup_many &&
91 git config --get-regexp "sec.*ke." >actual &&
92 test_line_count = 3126 actual
93'
94
95test_expect_success 'add and replace one of many entries' '
96 setup_many &&
97 git config --add section.key bar &&
98 check_regex section.key "b.*r" bar &&
99 git config section.key beer "b.*r" &&
100 check_regex section.key "b.*r" beer
101'
102
103test_expect_success 'replace many entries' '
104 setup_many &&
105 git config --replace-all section.key bar &&
106 check section.key bar
107'
108
109test_expect_success 'unset many entries' '
110 setup_many &&
111 git config --unset-all section.key &&
112 test_must_fail git config section.key
113'
114
115test_expect_success '--add appends new value after existing empty value' '
116 cat >expect <<-\EOF &&
117
118
119 fool
120 roll
121 EOF
122 cp .git/config .git/config.old &&
123 test_when_finished "mv .git/config.old .git/config" &&
124 cat >.git/config <<-\EOF &&
125 [foo]
126 baz
127 baz =
128 baz = fool
129 EOF
130 git config --add foo.baz roll &&
131 git config --get-all foo.baz >output &&
132 test_cmp expect output
133'
134
135test_done