Merge branch 'jk/repack-leakfix'
[git.git] / t / t0012-help.sh
blobdbfc5c826764bca4ec5561b603d8016f7d50f20d
1 #!/bin/sh
3 test_description='help'
5 . ./test-lib.sh
7 configure_help () {
8 test_config help.format html &&
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 &&
16 # Name a custom browser
17 test_config browser.test.cmd ./test-browser &&
18 test_config help.browser test
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
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
37 test_expect_success 'invalid usage' '
38 test_expect_code 129 git help -a add &&
39 test_expect_code 129 git help --all add &&
41 test_expect_code 129 git help -g add &&
42 test_expect_code 129 git help -a -c &&
44 test_expect_code 129 git help -g add &&
45 test_expect_code 129 git help -a -g &&
47 test_expect_code 129 git help --user-interfaces add &&
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
54 for opt in '-a' '-g' '-c' '--config-for-completion' '--config-sections-for-completion'
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
63 if test "$opt" = "-a"
64 then
65 continue
68 test_expect_success "invalid usage of '$opt' with --no-external-commands" '
69 test_expect_code 129 git help $opt --no-external-commands
72 test_expect_success "invalid usage of '$opt' with --no-aliases" '
73 test_expect_code 129 git help $opt --no-external-commands
75 done
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
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
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
101 test_expect_success 'git help' '
102 git help >help.output &&
103 test_i18ngrep "^ clone " help.output &&
104 test_i18ngrep "^ add " help.output &&
105 test_i18ngrep "^ log " help.output &&
106 test_i18ngrep "^ commit " help.output &&
107 test_i18ngrep "^ fetch " help.output
110 test_expect_success 'git help -g' '
111 git help -g >help.output &&
112 test_i18ngrep "^ everyday " help.output &&
113 test_i18ngrep "^ tutorial " help.output
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
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
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
138 test_expect_success 'git help -c' '
139 git help -c >help.output &&
140 cat >expect <<-\EOF &&
142 '\''git help config'\'' for more information
144 grep -v -E \
145 -e "^[^.]+\.[^.]+$" \
146 -e "^[^.]+\.[^.]+\.[^.]+$" \
147 help.output >actual &&
148 test_cmp expect actual
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 &&
159 git help --config-for-completion >vars &&
160 test_cmp human.munged vars
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 &&
171 git help --config-sections-for-completion >sections &&
172 test_cmp human.munged sections
175 test_section_spacing () {
176 cat >expect &&
177 "$@" >out &&
178 grep -E "(^[^ ]|^$)" out >actual
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
188 for cmd in git "git help"
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>]
194 These are common Git commands used in various situations:
196 start a working area (see also: git help tutorial)
198 work on the current change (see also: git help everyday)
200 examine the history and state (see also: git help revisions)
202 grow, mark and tweak your common history
204 collaborate (see also: git help workflows)
207 test_cmp expect actual
209 done
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
216 Main Porcelain Commands
218 Ancillary Commands / Manipulators
220 Ancillary Commands / Interrogators
222 Interacting with Others
224 Low-level Commands / Manipulators
226 Low-level Commands / Interrogators
228 Low-level Commands / Syncing Repositories
230 Low-level Commands / Internal Helpers
232 User-facing repository, command and file interfaces
234 Developer-facing file formats, protocols and other interfaces
236 test_cmp expect actual
239 test_expect_success "'git help -g' section spacing" '
240 test_section_spacing_trailer git help -g <<-\EOF &&
241 The Git concept guides are:
244 test_cmp expect actual
247 test_expect_success 'generate builtin list' '
248 mkdir -p sub &&
249 git --list-cmds=builtins >builtins
252 while read builtin
254 test_expect_success "$builtin can handle -h" '
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_i18ngrep usage output
262 done <builtins
264 test_done