Merge branch 'es/worktree-repair-copied' into cw/worktrees-relative
[git/gitster.git] / t / t1303-wacky-config.sh
blob0506f3d6bba6cb64255a1b7685481b8ccdb7784d
1 #!/bin/sh
3 test_description='Test wacky input to git config'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 # Leaving off the newline is intentional!
9 setup() {
10 (printf "[section]\n" &&
11 printf " key = foo") >.git/config
14 # 'check section.key value' verifies that the entry for section.key is
15 # 'value'
16 check() {
17 echo "$2" >expected
18 git config --get "$1" >actual 2>&1
19 test_cmp expected actual
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
27 test_cmp expected actual
30 test_expect_success 'modify same key' '
31 setup &&
32 git config section.key bar &&
33 check section.key bar
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
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
50 SECTION="test.q\"s\\sq'sp e.key"
51 test_expect_success 'make sure git config escapes section names properly' '
52 git config "$SECTION" bar &&
53 check "$SECTION" bar
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" &&
60 check section.key "$LONG_VALUE"
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
84 test_expect_success 'get many entries' '
85 setup_many &&
86 git config --get-all section.key >actual &&
87 test_line_count = 3126 actual
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
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
104 test_expect_success 'replace many entries' '
105 setup_many &&
106 git config --replace-all section.key bar &&
107 check section.key bar
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
116 test_expect_success '--add appends new value after existing empty value' '
117 cat >expect <<-\EOF &&
120 fool
121 roll
123 cp .git/config .git/config.old &&
124 test_when_finished "mv .git/config.old .git/config" &&
125 cat >.git/config <<-\EOF &&
126 [foo]
128 baz =
129 baz = fool
131 git config --add foo.baz roll &&
132 git config --get-all foo.baz >output &&
133 test_cmp expect output
136 test_done