]> git.ipfire.org Git - thirdparty/git.git/blob - t/t0007-git-var.sh
unicode: update the width tables to Unicode 15.1
[thirdparty/git.git] / t / t0007-git-var.sh
1 #!/bin/sh
2
3 test_description='basic sanity checks for git var'
4
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 sane_unset_all_editors () {
9 sane_unset GIT_EDITOR &&
10 sane_unset VISUAL &&
11 sane_unset EDITOR
12 }
13
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
28 test_expect_success !FAIL_PREREQS,!AUTOIDENT 'requested identities are strict' '
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
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
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
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
150 # For git var -l, we check only a representative variable;
151 # testing the whole output would make our test too brittle with
152 # respect to unrelated changes in the test suite's environment.
153 test_expect_success 'git var -l lists variables' '
154 git var -l >actual &&
155 echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
156 sed -n s/GIT_AUTHOR_IDENT=//p <actual >actual.author &&
157 test_cmp expect actual.author
158 '
159
160 test_expect_success 'git var -l lists config' '
161 git var -l >actual &&
162 echo false >expect &&
163 sed -n s/core\\.bare=//p <actual >actual.bare &&
164 test_cmp expect actual.bare
165 '
166
167 test_expect_success 'listing and asking for variables are exclusive' '
168 test_must_fail git var -l GIT_COMMITTER_IDENT
169 '
170
171 test_done