]>
Commit | Line | Data |
---|---|---|
879ed753 JK |
1 | #!/bin/sh |
2 | ||
3 | test_description='basic sanity checks for git var' | |
c150064d ÆAB |
4 | |
5 | TEST_PASSES_SANITIZE_LEAK=true | |
879ed753 JK |
6 | . ./test-lib.sh |
7 | ||
2ad150e3 SA |
8 | sane_unset_all_editors () { |
9 | sane_unset GIT_EDITOR && | |
10 | sane_unset VISUAL && | |
11 | sane_unset EDITOR | |
12 | } | |
13 | ||
879ed753 JK |
14 | test_expect_success 'get GIT_AUTHOR_IDENT' ' |
15 | test_tick && | |
16 | echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect && | |
17 | git var GIT_AUTHOR_IDENT >actual && | |
18 | test_cmp expect actual | |
19 | ' | |
20 | ||
21 | test_expect_success 'get GIT_COMMITTER_IDENT' ' | |
22 | test_tick && | |
23 | echo "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE" >expect && | |
24 | git var GIT_COMMITTER_IDENT >actual && | |
25 | test_cmp expect actual | |
26 | ' | |
27 | ||
a1aba0c9 | 28 | test_expect_success !FAIL_PREREQS,!AUTOIDENT 'requested identities are strict' ' |
879ed753 JK |
29 | ( |
30 | sane_unset GIT_COMMITTER_NAME && | |
31 | sane_unset GIT_COMMITTER_EMAIL && | |
32 | test_must_fail git var GIT_COMMITTER_IDENT | |
33 | ) | |
34 | ' | |
35 | ||
e06c9e1d TW |
36 | test_expect_success 'get GIT_DEFAULT_BRANCH without configuration' ' |
37 | ( | |
38 | sane_unset GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME && | |
39 | git init defbranch && | |
40 | git -C defbranch symbolic-ref --short HEAD >expect && | |
41 | git var GIT_DEFAULT_BRANCH >actual && | |
42 | test_cmp expect actual | |
43 | ) | |
44 | ' | |
45 | ||
46 | test_expect_success 'get GIT_DEFAULT_BRANCH with configuration' ' | |
47 | test_config init.defaultbranch foo && | |
48 | ( | |
49 | sane_unset GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME && | |
50 | echo foo >expect && | |
51 | git var GIT_DEFAULT_BRANCH >actual && | |
52 | test_cmp expect actual | |
53 | ) | |
54 | ' | |
55 | ||
2ad150e3 SA |
56 | test_expect_success 'get GIT_EDITOR without configuration' ' |
57 | ( | |
58 | sane_unset_all_editors && | |
59 | test_expect_code 1 git var GIT_EDITOR >out && | |
60 | test_must_be_empty out | |
61 | ) | |
62 | ' | |
63 | ||
64 | test_expect_success 'get GIT_EDITOR with configuration' ' | |
65 | test_config core.editor foo && | |
66 | ( | |
67 | sane_unset_all_editors && | |
68 | echo foo >expect && | |
69 | git var GIT_EDITOR >actual && | |
70 | test_cmp expect actual | |
71 | ) | |
72 | ' | |
73 | ||
74 | test_expect_success 'get GIT_EDITOR with environment variable GIT_EDITOR' ' | |
75 | ( | |
76 | sane_unset_all_editors && | |
77 | echo bar >expect && | |
78 | GIT_EDITOR=bar git var GIT_EDITOR >actual && | |
79 | test_cmp expect actual | |
80 | ) | |
81 | ' | |
82 | ||
83 | test_expect_success 'get GIT_EDITOR with environment variable EDITOR' ' | |
84 | ( | |
85 | sane_unset_all_editors && | |
86 | echo bar >expect && | |
87 | EDITOR=bar git var GIT_EDITOR >actual && | |
88 | test_cmp expect actual | |
89 | ) | |
90 | ' | |
91 | ||
92 | test_expect_success 'get GIT_EDITOR with configuration and environment variable GIT_EDITOR' ' | |
93 | test_config core.editor foo && | |
94 | ( | |
95 | sane_unset_all_editors && | |
96 | echo bar >expect && | |
97 | GIT_EDITOR=bar git var GIT_EDITOR >actual && | |
98 | test_cmp expect actual | |
99 | ) | |
100 | ' | |
101 | ||
102 | test_expect_success 'get GIT_EDITOR with configuration and environment variable EDITOR' ' | |
103 | test_config core.editor foo && | |
104 | ( | |
105 | sane_unset_all_editors && | |
106 | echo foo >expect && | |
107 | EDITOR=bar git var GIT_EDITOR >actual && | |
108 | test_cmp expect actual | |
109 | ) | |
110 | ' | |
111 | ||
4c3dd930 SA |
112 | test_expect_success 'get GIT_SEQUENCE_EDITOR without configuration' ' |
113 | ( | |
114 | sane_unset GIT_SEQUENCE_EDITOR && | |
115 | git var GIT_EDITOR >expect && | |
116 | git var GIT_SEQUENCE_EDITOR >actual && | |
117 | test_cmp expect actual | |
118 | ) | |
119 | ' | |
120 | ||
121 | test_expect_success 'get GIT_SEQUENCE_EDITOR with configuration' ' | |
122 | test_config sequence.editor foo && | |
123 | ( | |
124 | sane_unset GIT_SEQUENCE_EDITOR && | |
125 | echo foo >expect && | |
126 | git var GIT_SEQUENCE_EDITOR >actual && | |
127 | test_cmp expect actual | |
128 | ) | |
129 | ' | |
130 | ||
131 | test_expect_success 'get GIT_SEQUENCE_EDITOR with environment variable' ' | |
132 | ( | |
133 | sane_unset GIT_SEQUENCE_EDITOR && | |
134 | echo bar >expect && | |
135 | GIT_SEQUENCE_EDITOR=bar git var GIT_SEQUENCE_EDITOR >actual && | |
136 | test_cmp expect actual | |
137 | ) | |
138 | ' | |
139 | ||
140 | test_expect_success 'get GIT_SEQUENCE_EDITOR with configuration and environment variable' ' | |
141 | test_config sequence.editor foo && | |
142 | ( | |
143 | sane_unset GIT_SEQUENCE_EDITOR && | |
144 | echo bar >expect && | |
145 | GIT_SEQUENCE_EDITOR=bar git var GIT_SEQUENCE_EDITOR >actual && | |
146 | test_cmp expect actual | |
147 | ) | |
148 | ' | |
149 | ||
1e657212 | 150 | test_expect_success POSIXPERM 'GIT_SHELL_PATH points to a valid executable' ' |
151 | shellpath=$(git var GIT_SHELL_PATH) && | |
152 | test_path_is_executable "$shellpath" | |
153 | ' | |
154 | ||
155 | # We know in this environment that our shell will be one of a few fixed values | |
156 | # that all end in "sh". | |
157 | test_expect_success MINGW 'GIT_SHELL_PATH points to a suitable shell' ' | |
158 | shellpath=$(git var GIT_SHELL_PATH) && | |
159 | case "$shellpath" in | |
160 | *sh) ;; | |
161 | *) return 1;; | |
162 | esac | |
163 | ' | |
164 | ||
576a37fc | 165 | test_expect_success 'GIT_ATTR_SYSTEM produces expected output' ' |
166 | test_must_fail env GIT_ATTR_NOSYSTEM=1 git var GIT_ATTR_SYSTEM && | |
167 | ( | |
168 | sane_unset GIT_ATTR_NOSYSTEM && | |
169 | systempath=$(git var GIT_ATTR_SYSTEM) && | |
170 | test "$systempath" != "" | |
171 | ) | |
172 | ' | |
173 | ||
174 | test_expect_success 'GIT_ATTR_GLOBAL points to the correct location' ' | |
175 | TRASHDIR="$(test-tool path-utils normalize_path_copy "$(pwd)")" && | |
176 | globalpath=$(XDG_CONFIG_HOME="$TRASHDIR/.config" git var GIT_ATTR_GLOBAL) && | |
177 | test "$globalpath" = "$TRASHDIR/.config/git/attributes" && | |
178 | ( | |
179 | sane_unset XDG_CONFIG_HOME && | |
180 | globalpath=$(HOME="$TRASHDIR" git var GIT_ATTR_GLOBAL) && | |
181 | test "$globalpath" = "$TRASHDIR/.config/git/attributes" | |
182 | ) | |
183 | ' | |
184 | ||
ed773a18 | 185 | test_expect_success 'GIT_CONFIG_SYSTEM points to the correct location' ' |
186 | TRASHDIR="$(test-tool path-utils normalize_path_copy "$(pwd)")" && | |
187 | test_must_fail env GIT_CONFIG_NOSYSTEM=1 git var GIT_CONFIG_SYSTEM && | |
188 | ( | |
189 | sane_unset GIT_CONFIG_NOSYSTEM && | |
190 | systempath=$(git var GIT_CONFIG_SYSTEM) && | |
191 | test "$systempath" != "" && | |
192 | systempath=$(GIT_CONFIG_SYSTEM=/dev/null git var GIT_CONFIG_SYSTEM) && | |
193 | if test_have_prereq MINGW | |
194 | then | |
195 | test "$systempath" = "nul" | |
196 | else | |
197 | test "$systempath" = "/dev/null" | |
198 | fi && | |
199 | systempath=$(GIT_CONFIG_SYSTEM="$TRASHDIR/gitconfig" git var GIT_CONFIG_SYSTEM) && | |
200 | test "$systempath" = "$TRASHDIR/gitconfig" | |
201 | ) | |
202 | ' | |
203 | ||
204 | test_expect_success 'GIT_CONFIG_GLOBAL points to the correct location' ' | |
205 | TRASHDIR="$(test-tool path-utils normalize_path_copy "$(pwd)")" && | |
206 | HOME="$TRASHDIR" XDG_CONFIG_HOME="$TRASHDIR/foo" git var GIT_CONFIG_GLOBAL >actual && | |
207 | echo "$TRASHDIR/foo/git/config" >expected && | |
208 | echo "$TRASHDIR/.gitconfig" >>expected && | |
209 | test_cmp expected actual && | |
210 | ( | |
211 | sane_unset XDG_CONFIG_HOME && | |
212 | HOME="$TRASHDIR" git var GIT_CONFIG_GLOBAL >actual && | |
213 | echo "$TRASHDIR/.config/git/config" >expected && | |
214 | echo "$TRASHDIR/.gitconfig" >>expected && | |
215 | test_cmp expected actual && | |
216 | globalpath=$(GIT_CONFIG_GLOBAL=/dev/null git var GIT_CONFIG_GLOBAL) && | |
217 | if test_have_prereq MINGW | |
218 | then | |
219 | test "$globalpath" = "nul" | |
220 | else | |
221 | test "$globalpath" = "/dev/null" | |
222 | fi && | |
223 | globalpath=$(GIT_CONFIG_GLOBAL="$TRASHDIR/gitconfig" git var GIT_CONFIG_GLOBAL) && | |
224 | test "$globalpath" = "$TRASHDIR/gitconfig" | |
225 | ) | |
226 | ' | |
227 | ||
879ed753 JK |
228 | # For git var -l, we check only a representative variable; |
229 | # testing the whole output would make our test too brittle with | |
230 | # respect to unrelated changes in the test suite's environment. | |
231 | test_expect_success 'git var -l lists variables' ' | |
232 | git var -l >actual && | |
233 | echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect && | |
234 | sed -n s/GIT_AUTHOR_IDENT=//p <actual >actual.author && | |
235 | test_cmp expect actual.author | |
236 | ' | |
237 | ||
238 | test_expect_success 'git var -l lists config' ' | |
239 | git var -l >actual && | |
240 | echo false >expect && | |
241 | sed -n s/core\\.bare=//p <actual >actual.bare && | |
242 | test_cmp expect actual.bare | |
243 | ' | |
244 | ||
ed773a18 | 245 | test_expect_success 'git var -l lists multiple global configs' ' |
246 | TRASHDIR="$(test-tool path-utils normalize_path_copy "$(pwd)")" && | |
247 | HOME="$TRASHDIR" XDG_CONFIG_HOME="$TRASHDIR/foo" git var -l >actual && | |
248 | grep "^GIT_CONFIG_GLOBAL=" actual >filtered && | |
249 | echo "GIT_CONFIG_GLOBAL=$TRASHDIR/foo/git/config" >expected && | |
250 | echo "GIT_CONFIG_GLOBAL=$TRASHDIR/.gitconfig" >>expected && | |
251 | test_cmp expected filtered | |
252 | ' | |
253 | ||
254 | test_expect_success 'git var -l does not split multiline editors' ' | |
255 | ( | |
256 | GIT_EDITOR="!f() { | |
257 | echo Hello! | |
258 | }; f" && | |
259 | export GIT_EDITOR && | |
260 | echo "GIT_EDITOR=$GIT_EDITOR" >expected && | |
261 | git var -l >var && | |
262 | sed -n -e "/^GIT_EDITOR/,\$p" var | head -n 3 >actual && | |
263 | test_cmp expected actual | |
264 | ) | |
265 | ' | |
266 | ||
879ed753 JK |
267 | test_expect_success 'listing and asking for variables are exclusive' ' |
268 | test_must_fail git var -l GIT_COMMITTER_IDENT | |
269 | ' | |
270 | ||
256a94ef JS |
271 | test_expect_success '`git var -l` works even without HOME' ' |
272 | ( | |
273 | XDG_CONFIG_HOME= && | |
274 | export XDG_CONFIG_HOME && | |
275 | unset HOME && | |
276 | git var -l | |
277 | ) | |
278 | ' | |
279 | ||
879ed753 | 280 | test_done |