]> git.ipfire.org Git - thirdparty/git.git/blob - t/t0012-help.sh
clone: allow "--bare" with "-o"
[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 -g -c &&
48 test_expect_code 129 git help --config-for-completion add &&
49 test_expect_code 129 git help --config-sections-for-completion add
50 '
51
52 for opt in '-a' '-g' '-c' '--config-for-completion' '--config-sections-for-completion'
53 do
54 test_expect_success "invalid usage of '$opt' with [-i|-m|-w]" '
55 git help $opt &&
56 test_expect_code 129 git help $opt -i &&
57 test_expect_code 129 git help $opt -m &&
58 test_expect_code 129 git help $opt -w
59 '
60
61 if test "$opt" = "-a"
62 then
63 continue
64 fi
65
66 test_expect_success "invalid usage of '$opt' with --no-external-commands" '
67 test_expect_code 129 git help $opt --no-external-commands
68 '
69
70 test_expect_success "invalid usage of '$opt' with --no-aliases" '
71 test_expect_code 129 git help $opt --no-external-commands
72 '
73 done
74
75 test_expect_success "works for commands and guides by default" '
76 configure_help &&
77 git help status &&
78 echo "test://html/git-status.html" >expect &&
79 test_cmp expect test-browser.log &&
80 git help revisions &&
81 echo "test://html/gitrevisions.html" >expect &&
82 test_cmp expect test-browser.log
83 '
84
85 test_expect_success "--exclude-guides does not work for guides" '
86 >test-browser.log &&
87 test_must_fail git help --exclude-guides revisions &&
88 test_must_be_empty test-browser.log
89 '
90
91 test_expect_success "--help does not work for guides" "
92 cat <<-EOF >expect &&
93 git: 'revisions' is not a git command. See 'git --help'.
94 EOF
95 test_must_fail git revisions --help 2>actual &&
96 test_cmp expect actual
97 "
98
99 test_expect_success 'git help' '
100 git help >help.output &&
101 test_i18ngrep "^ clone " help.output &&
102 test_i18ngrep "^ add " help.output &&
103 test_i18ngrep "^ log " help.output &&
104 test_i18ngrep "^ commit " help.output &&
105 test_i18ngrep "^ fetch " help.output
106 '
107 test_expect_success 'git help -g' '
108 git help -g >help.output &&
109 test_i18ngrep "^ attributes " help.output &&
110 test_i18ngrep "^ everyday " help.output &&
111 test_i18ngrep "^ tutorial " help.output
112 '
113
114 test_expect_success 'git help fails for non-existing html pages' '
115 configure_help &&
116 mkdir html-empty &&
117 test_must_fail git -c help.htmlpath=html-empty help status &&
118 test_must_be_empty test-browser.log
119 '
120
121 test_expect_success 'git help succeeds without git.html' '
122 configure_help &&
123 mkdir html-with-docs &&
124 touch html-with-docs/git-status.html &&
125 git -c help.htmlpath=html-with-docs help status &&
126 echo "html-with-docs/git-status.html" >expect &&
127 test_cmp expect test-browser.log
128 '
129
130 test_expect_success 'git help -c' '
131 git help -c >help.output &&
132 cat >expect <<-\EOF &&
133
134 '\''git help config'\'' for more information
135 EOF
136 grep -v -E \
137 -e "^[^.]+\.[^.]+$" \
138 -e "^[^.]+\.[^.]+\.[^.]+$" \
139 help.output >actual &&
140 test_cmp expect actual
141 '
142
143 test_expect_success 'git help --config-for-completion' '
144 git help -c >human &&
145 grep -E \
146 -e "^[^.]+\.[^.]+$" \
147 -e "^[^.]+\.[^.]+\.[^.]+$" human |
148 sed -e "s/\*.*//" -e "s/<.*//" |
149 sort -u >human.munged &&
150
151 git help --config-for-completion >vars &&
152 test_cmp human.munged vars
153 '
154
155 test_expect_success 'git help --config-sections-for-completion' '
156 git help -c >human &&
157 grep -E \
158 -e "^[^.]+\.[^.]+$" \
159 -e "^[^.]+\.[^.]+\.[^.]+$" human |
160 sed -e "s/\..*//" |
161 sort -u >human.munged &&
162
163 git help --config-sections-for-completion >sections &&
164 test_cmp human.munged sections
165 '
166
167 test_section_spacing () {
168 cat >expect &&
169 "$@" >out &&
170 grep -E "(^[^ ]|^$)" out >actual
171 }
172
173 test_section_spacing_trailer () {
174 test_section_spacing "$@" &&
175 test_expect_code 1 git >out &&
176 sed -n '/list available subcommands/,$p' <out >>expect
177 }
178
179
180 for cmd in git "git help"
181 do
182 test_expect_success "'$cmd' section spacing" '
183 test_section_spacing_trailer git help <<-\EOF &&
184 usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>]
185
186 These are common Git commands used in various situations:
187
188 start a working area (see also: git help tutorial)
189
190 work on the current change (see also: git help everyday)
191
192 examine the history and state (see also: git help revisions)
193
194 grow, mark and tweak your common history
195
196 collaborate (see also: git help workflows)
197
198 EOF
199 test_cmp expect actual
200 '
201 done
202
203 test_expect_success "'git help -a' section spacing" '
204 test_section_spacing \
205 git help -a --no-external-commands --no-aliases <<-\EOF &&
206 See '\''git help <command>'\'' to read about a specific subcommand
207
208 Main Porcelain Commands
209
210 Ancillary Commands / Manipulators
211
212 Ancillary Commands / Interrogators
213
214 Interacting with Others
215
216 Low-level Commands / Manipulators
217
218 Low-level Commands / Interrogators
219
220 Low-level Commands / Syncing Repositories
221
222 Low-level Commands / Internal Helpers
223 EOF
224 test_cmp expect actual
225 '
226
227 test_expect_success "'git help -g' section spacing" '
228 test_section_spacing_trailer git help -g <<-\EOF &&
229 The Git concept guides are:
230
231 EOF
232 test_cmp expect actual
233 '
234
235 test_expect_success 'generate builtin list' '
236 mkdir -p sub &&
237 git --list-cmds=builtins >builtins
238 '
239
240 while read builtin
241 do
242 test_expect_success "$builtin can handle -h" '
243 (
244 GIT_CEILING_DIRECTORIES=$(pwd) &&
245 export GIT_CEILING_DIRECTORIES &&
246 test_expect_code 129 git -C sub $builtin -h >output 2>&1
247 ) &&
248 test_i18ngrep usage output
249 '
250 done <builtins
251
252 test_done