]> git.ipfire.org Git - thirdparty/git.git/blob - t/t0012-help.sh
Sync with Git 2.45.1
[thirdparty/git.git] / t / t0012-help.sh
1 #!/bin/sh
2
3 test_description='help'
4
5 . ./test-lib.sh
6
7 configure_help () {
8 test_config help.format html &&
9
10 # Unless the path has "://" in it, Git tries to make sure
11 # the documentation directory locally exists. Avoid it as
12 # we are only interested in seeing an attempt to correctly
13 # invoke a help browser in this test.
14 test_config help.htmlpath test://html &&
15
16 # Name a custom browser
17 test_config browser.test.cmd ./test-browser &&
18 test_config help.browser test
19 }
20
21 test_expect_success "setup" '
22 # Just write out which page gets requested
23 write_script test-browser <<-\EOF
24 echo "$*" >test-browser.log
25 EOF
26 '
27
28 # make sure to exercise these code paths, the output is a bit tricky
29 # to verify
30 test_expect_success 'basic help commands' '
31 git help >/dev/null &&
32 git help -a --no-verbose >/dev/null &&
33 git help -g >/dev/null &&
34 git help -a >/dev/null
35 '
36
37 test_expect_success 'invalid usage' '
38 test_expect_code 129 git help -a add &&
39 test_expect_code 129 git help --all add &&
40
41 test_expect_code 129 git help -g add &&
42 test_expect_code 129 git help -a -c &&
43
44 test_expect_code 129 git help -g add &&
45 test_expect_code 129 git help -a -g &&
46
47 test_expect_code 129 git help --user-interfaces add &&
48
49 test_expect_code 129 git help -g -c &&
50 test_expect_code 129 git help --config-for-completion add &&
51 test_expect_code 129 git help --config-sections-for-completion add
52 '
53
54 for opt in '-a' '-g' '-c' '--config-for-completion' '--config-sections-for-completion'
55 do
56 test_expect_success "invalid usage of '$opt' with [-i|-m|-w]" '
57 git help $opt &&
58 test_expect_code 129 git help $opt -i &&
59 test_expect_code 129 git help $opt -m &&
60 test_expect_code 129 git help $opt -w
61 '
62
63 if test "$opt" = "-a"
64 then
65 continue
66 fi
67
68 test_expect_success "invalid usage of '$opt' with --no-external-commands" '
69 test_expect_code 129 git help $opt --no-external-commands
70 '
71
72 test_expect_success "invalid usage of '$opt' with --no-aliases" '
73 test_expect_code 129 git help $opt --no-external-commands
74 '
75 done
76
77 test_expect_success "works for commands and guides by default" '
78 configure_help &&
79 git help status &&
80 echo "test://html/git-status.html" >expect &&
81 test_cmp expect test-browser.log &&
82 git help revisions &&
83 echo "test://html/gitrevisions.html" >expect &&
84 test_cmp expect test-browser.log
85 '
86
87 test_expect_success "--exclude-guides does not work for guides" '
88 >test-browser.log &&
89 test_must_fail git help --exclude-guides revisions &&
90 test_must_be_empty test-browser.log
91 '
92
93 test_expect_success "--help does not work for guides" "
94 cat <<-EOF >expect &&
95 git: 'revisions' is not a git command. See 'git --help'.
96 EOF
97 test_must_fail git revisions --help 2>actual &&
98 test_cmp expect actual
99 "
100
101 test_expect_success 'git help' '
102 git help >help.output &&
103 test_grep "^ clone " help.output &&
104 test_grep "^ add " help.output &&
105 test_grep "^ log " help.output &&
106 test_grep "^ commit " help.output &&
107 test_grep "^ fetch " help.output
108 '
109
110 test_expect_success 'git help -g' '
111 git help -g >help.output &&
112 test_grep "^ everyday " help.output &&
113 test_grep "^ tutorial " help.output
114 '
115
116 test_expect_success 'git help fails for non-existing html pages' '
117 configure_help &&
118 mkdir html-empty &&
119 test_must_fail git -c help.htmlpath=html-empty help status &&
120 test_must_be_empty test-browser.log
121 '
122
123 test_expect_success 'git help succeeds without git.html' '
124 configure_help &&
125 mkdir html-with-docs &&
126 touch html-with-docs/git-status.html &&
127 git -c help.htmlpath=html-with-docs help status &&
128 echo "html-with-docs/git-status.html" >expect &&
129 test_cmp expect test-browser.log
130 '
131
132 test_expect_success 'git help --user-interfaces' '
133 git help --user-interfaces >help.output &&
134 grep "^ attributes " help.output &&
135 grep "^ mailmap " help.output
136 '
137
138 test_expect_success 'git help -c' '
139 git help -c >help.output &&
140 cat >expect <<-\EOF &&
141
142 '\''git help config'\'' for more information
143 EOF
144 grep -v -E \
145 -e "^[^.]+\.[^.]+$" \
146 -e "^[^.]+\.[^.]+\.[^.]+$" \
147 help.output >actual &&
148 test_cmp expect actual
149 '
150
151 test_expect_success 'git help --config-for-completion' '
152 git help -c >human &&
153 grep -E \
154 -e "^[^.]+\.[^.]+$" \
155 -e "^[^.]+\.[^.]+\.[^.]+$" human |
156 sed -e "s/\*.*//" -e "s/<.*//" |
157 sort -u >human.munged &&
158
159 git help --config-for-completion >vars &&
160 test_cmp human.munged vars
161 '
162
163 test_expect_success 'git help --config-sections-for-completion' '
164 git help -c >human &&
165 grep -E \
166 -e "^[^.]+\.[^.]+$" \
167 -e "^[^.]+\.[^.]+\.[^.]+$" human |
168 sed -e "s/\..*//" |
169 sort -u >human.munged &&
170
171 git help --config-sections-for-completion >sections &&
172 test_cmp human.munged sections
173 '
174
175 test_section_spacing () {
176 cat >expect &&
177 "$@" >out &&
178 grep -E "(^[^ ]|^$)" out >actual
179 }
180
181 test_section_spacing_trailer () {
182 test_section_spacing "$@" &&
183 test_expect_code 1 git >out &&
184 sed -n '/list available subcommands/,$p' <out >>expect
185 }
186
187
188 for cmd in git "git help"
189 do
190 test_expect_success "'$cmd' section spacing" '
191 test_section_spacing_trailer git help <<-\EOF &&
192 usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>]
193
194 These are common Git commands used in various situations:
195
196 start a working area (see also: git help tutorial)
197
198 work on the current change (see also: git help everyday)
199
200 examine the history and state (see also: git help revisions)
201
202 grow, mark and tweak your common history
203
204 collaborate (see also: git help workflows)
205
206 EOF
207 test_cmp expect actual
208 '
209 done
210
211 test_expect_success "'git help -a' section spacing" '
212 test_section_spacing \
213 git help -a --no-external-commands --no-aliases <<-\EOF &&
214 See '\''git help <command>'\'' to read about a specific subcommand
215
216 Main Porcelain Commands
217
218 Ancillary Commands / Manipulators
219
220 Ancillary Commands / Interrogators
221
222 Interacting with Others
223
224 Low-level Commands / Manipulators
225
226 Low-level Commands / Interrogators
227
228 Low-level Commands / Syncing Repositories
229
230 Low-level Commands / Internal Helpers
231
232 User-facing repository, command and file interfaces
233
234 Developer-facing file formats, protocols and other interfaces
235 EOF
236 test_cmp expect actual
237 '
238
239 test_expect_success "'git help -g' section spacing" '
240 test_section_spacing_trailer git help -g <<-\EOF &&
241 The Git concept guides are:
242
243 EOF
244 test_cmp expect actual
245 '
246
247 test_expect_success 'generate builtin list' '
248 mkdir -p sub &&
249 git --list-cmds=builtins >builtins
250 '
251
252 while read builtin
253 do
254 test_expect_success "$builtin can handle -h" '
255 (
256 GIT_CEILING_DIRECTORIES=$(pwd) &&
257 export GIT_CEILING_DIRECTORIES &&
258 test_expect_code 129 git -C sub $builtin -h >output 2>&1
259 ) &&
260 test_grep usage output
261 '
262 done <builtins
263
264 test_done