]>
Commit | Line | Data |
---|---|---|
af74128f RT |
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 | ||
63eae83f NTND |
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 && | |
26c7d067 | 32 | git help -a --no-verbose >/dev/null && |
63eae83f | 33 | git help -g >/dev/null && |
26c7d067 | 34 | git help -a >/dev/null |
63eae83f NTND |
35 | ' |
36 | ||
9856ea67 | 37 | test_expect_success 'invalid usage' ' |
5e8068b7 ÆAB |
38 | test_expect_code 129 git help -a add && |
39 | test_expect_code 129 git help --all add && | |
40 | ||
1ed4bef6 | 41 | test_expect_code 129 git help -g add && |
0a5940fb ÆAB |
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 | ||
d976c510 ÆAB |
47 | test_expect_code 129 git help --user-interfaces add && |
48 | ||
5a5f04d8 | 49 | test_expect_code 129 git help -g -c && |
a9baccca ÆAB |
50 | test_expect_code 129 git help --config-for-completion add && |
51 | test_expect_code 129 git help --config-sections-for-completion add | |
9856ea67 ÆAB |
52 | ' |
53 | ||
503cddac ÆAB |
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 | ' | |
1ce59013 ÆAB |
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 | ' | |
503cddac ÆAB |
75 | done |
76 | ||
af74128f RT |
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 | ||
2c6b6d9f RT |
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 && | |
1108cea7 | 98 | test_cmp expect actual |
2c6b6d9f RT |
99 | " |
100 | ||
cfb22a02 NTND |
101 | test_expect_success 'git help' ' |
102 | git help >help.output && | |
6789275d JH |
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 | |
cfb22a02 | 108 | ' |
d976c510 | 109 | |
1b81d8cb NTND |
110 | test_expect_success 'git help -g' ' |
111 | git help -g >help.output && | |
6789275d JH |
112 | test_grep "^ everyday " help.output && |
113 | test_grep "^ tutorial " help.output | |
1b81d8cb | 114 | ' |
cfb22a02 | 115 | |
a3952f8e MA |
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 | ||
d976c510 ÆAB |
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 | ||
ff76fc84 ÆAB |
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 | ||
5a5f04d8 ÆAB |
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 && | |
5a5f04d8 ÆAB |
160 | test_cmp human.munged vars |
161 | ' | |
162 | ||
a9baccca ÆAB |
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 | ||
bf7eed75 ÆAB |
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 && | |
6b52f48b | 192 | usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>] |
bf7eed75 ÆAB |
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 | ||
1ce59013 ÆAB |
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 | |
d976c510 ÆAB |
231 | |
232 | User-facing repository, command and file interfaces | |
844739ba | 233 | |
225e815e | 234 | Developer-facing file formats, protocols and other interfaces |
1ce59013 ÆAB |
235 | EOF |
236 | test_cmp expect actual | |
237 | ' | |
238 | ||
bf7eed75 ÆAB |
239 | test_expect_success "'git help -g' section spacing" ' |
240 | test_section_spacing_trailer git help -g <<-\EOF && | |
bf7eed75 ÆAB |
241 | The Git concept guides are: |
242 | ||
243 | EOF | |
244 | test_cmp expect actual | |
245 | ' | |
246 | ||
d6915511 | 247 | test_expect_success 'generate builtin list' ' |
87ad07d7 | 248 | mkdir -p sub && |
0089521c | 249 | git --list-cmds=builtins >builtins |
d6915511 JK |
250 | ' |
251 | ||
252 | while read builtin | |
253 | do | |
254 | test_expect_success "$builtin can handle -h" ' | |
87ad07d7 JS |
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 | ) && | |
6789275d | 260 | test_grep usage output |
d6915511 JK |
261 | ' |
262 | done <builtins | |
263 | ||
af74128f | 264 | test_done |