3 test_description
='basic sanity checks for git var'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 sane_unset_all_editors
() {
9 sane_unset GIT_EDITOR
&&
14 test_expect_success
'get GIT_AUTHOR_IDENT' '
16 echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
17 git var GIT_AUTHOR_IDENT >actual &&
18 test_cmp expect actual
21 test_expect_success
'get GIT_COMMITTER_IDENT' '
23 echo "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE" >expect &&
24 git var GIT_COMMITTER_IDENT >actual &&
25 test_cmp expect actual
28 test_expect_success
!FAIL_PREREQS
,!AUTOIDENT
'requested identities are strict' '
30 sane_unset GIT_COMMITTER_NAME &&
31 sane_unset GIT_COMMITTER_EMAIL &&
32 test_must_fail git var GIT_COMMITTER_IDENT
36 test_expect_success
'get GIT_DEFAULT_BRANCH without configuration' '
38 sane_unset GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME &&
40 git -C defbranch symbolic-ref --short HEAD >expect &&
41 git var GIT_DEFAULT_BRANCH >actual &&
42 test_cmp expect actual
46 test_expect_success
'get GIT_DEFAULT_BRANCH with configuration' '
47 test_config init.defaultbranch foo &&
49 sane_unset GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME &&
51 git var GIT_DEFAULT_BRANCH >actual &&
52 test_cmp expect actual
56 test_expect_success
'get GIT_EDITOR without configuration' '
58 sane_unset_all_editors &&
59 test_expect_code 1 git var GIT_EDITOR >out &&
60 test_must_be_empty out
64 test_expect_success
'get GIT_EDITOR with configuration' '
65 test_config core.editor foo &&
67 sane_unset_all_editors &&
69 git var GIT_EDITOR >actual &&
70 test_cmp expect actual
74 test_expect_success
'get GIT_EDITOR with environment variable GIT_EDITOR' '
76 sane_unset_all_editors &&
78 GIT_EDITOR=bar git var GIT_EDITOR >actual &&
79 test_cmp expect actual
83 test_expect_success
'get GIT_EDITOR with environment variable EDITOR' '
85 sane_unset_all_editors &&
87 EDITOR=bar git var GIT_EDITOR >actual &&
88 test_cmp expect actual
92 test_expect_success
'get GIT_EDITOR with configuration and environment variable GIT_EDITOR' '
93 test_config core.editor foo &&
95 sane_unset_all_editors &&
97 GIT_EDITOR=bar git var GIT_EDITOR >actual &&
98 test_cmp expect actual
102 test_expect_success
'get GIT_EDITOR with configuration and environment variable EDITOR' '
103 test_config core.editor foo &&
105 sane_unset_all_editors &&
107 EDITOR=bar git var GIT_EDITOR >actual &&
108 test_cmp expect actual
112 test_expect_success
'get GIT_SEQUENCE_EDITOR without configuration' '
114 sane_unset GIT_SEQUENCE_EDITOR &&
115 git var GIT_EDITOR >expect &&
116 git var GIT_SEQUENCE_EDITOR >actual &&
117 test_cmp expect actual
121 test_expect_success
'get GIT_SEQUENCE_EDITOR with configuration' '
122 test_config sequence.editor foo &&
124 sane_unset GIT_SEQUENCE_EDITOR &&
126 git var GIT_SEQUENCE_EDITOR >actual &&
127 test_cmp expect actual
131 test_expect_success
'get GIT_SEQUENCE_EDITOR with environment variable' '
133 sane_unset GIT_SEQUENCE_EDITOR &&
135 GIT_SEQUENCE_EDITOR=bar git var GIT_SEQUENCE_EDITOR >actual &&
136 test_cmp expect actual
140 test_expect_success
'get GIT_SEQUENCE_EDITOR with configuration and environment variable' '
141 test_config sequence.editor foo &&
143 sane_unset GIT_SEQUENCE_EDITOR &&
145 GIT_SEQUENCE_EDITOR=bar git var GIT_SEQUENCE_EDITOR >actual &&
146 test_cmp expect actual
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"
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) &&
165 test_expect_success
'GIT_ATTR_SYSTEM produces expected output' '
166 test_must_fail env GIT_ATTR_NOSYSTEM=1 git var GIT_ATTR_SYSTEM &&
168 sane_unset GIT_ATTR_NOSYSTEM &&
169 systempath=$(git var GIT_ATTR_SYSTEM) &&
170 test "$systempath" != ""
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" &&
179 sane_unset XDG_CONFIG_HOME &&
180 globalpath=$(HOME="$TRASHDIR" git var GIT_ATTR_GLOBAL) &&
181 test "$globalpath" = "$TRASHDIR/.config/git/attributes"
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 &&
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
195 test "$systempath" = "nul"
197 test "$systempath" = "/dev/null"
199 systempath=$(GIT_CONFIG_SYSTEM="$TRASHDIR/gitconfig" git var GIT_CONFIG_SYSTEM) &&
200 test "$systempath" = "$TRASHDIR/gitconfig"
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 &&
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
219 test "$globalpath" = "nul"
221 test "$globalpath" = "/dev/null"
223 globalpath=$(GIT_CONFIG_GLOBAL="$TRASHDIR/gitconfig" git var GIT_CONFIG_GLOBAL) &&
224 test "$globalpath" = "$TRASHDIR/gitconfig"
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
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
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
254 test_expect_success
'git var -l does not split multiline editors' '
260 echo "GIT_EDITOR=$GIT_EDITOR" >expected &&
262 sed -n -e "/^GIT_EDITOR/,\$p" var | head -n 3 >actual &&
263 test_cmp expected actual
267 test_expect_success
'listing and asking for variables are exclusive' '
268 test_must_fail git var -l GIT_COMMITTER_IDENT
271 test_expect_success
'`git var -l` works even without HOME' '
274 export XDG_CONFIG_HOME &&