]> git.ipfire.org Git - thirdparty/git.git/blame_incremental - t/t0012-help.sh
help: correct usage & behavior of "git help --all"
[thirdparty/git.git] / t / t0012-help.sh
... / ...
CommitLineData
1#!/bin/sh
2
3test_description='help'
4
5. ./test-lib.sh
6
7configure_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
21test_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
30test_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
37test_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
52test_expect_success "works for commands and guides by default" '
53 configure_help &&
54 git help status &&
55 echo "test://html/git-status.html" >expect &&
56 test_cmp expect test-browser.log &&
57 git help revisions &&
58 echo "test://html/gitrevisions.html" >expect &&
59 test_cmp expect test-browser.log
60'
61
62test_expect_success "--exclude-guides does not work for guides" '
63 >test-browser.log &&
64 test_must_fail git help --exclude-guides revisions &&
65 test_must_be_empty test-browser.log
66'
67
68test_expect_success "--help does not work for guides" "
69 cat <<-EOF >expect &&
70 git: 'revisions' is not a git command. See 'git --help'.
71 EOF
72 test_must_fail git revisions --help 2>actual &&
73 test_cmp expect actual
74"
75
76test_expect_success 'git help' '
77 git help >help.output &&
78 test_i18ngrep "^ clone " help.output &&
79 test_i18ngrep "^ add " help.output &&
80 test_i18ngrep "^ log " help.output &&
81 test_i18ngrep "^ commit " help.output &&
82 test_i18ngrep "^ fetch " help.output
83'
84test_expect_success 'git help -g' '
85 git help -g >help.output &&
86 test_i18ngrep "^ attributes " help.output &&
87 test_i18ngrep "^ everyday " help.output &&
88 test_i18ngrep "^ tutorial " help.output
89'
90
91test_expect_success 'git help fails for non-existing html pages' '
92 configure_help &&
93 mkdir html-empty &&
94 test_must_fail git -c help.htmlpath=html-empty help status &&
95 test_must_be_empty test-browser.log
96'
97
98test_expect_success 'git help succeeds without git.html' '
99 configure_help &&
100 mkdir html-with-docs &&
101 touch html-with-docs/git-status.html &&
102 git -c help.htmlpath=html-with-docs help status &&
103 echo "html-with-docs/git-status.html" >expect &&
104 test_cmp expect test-browser.log
105'
106
107test_expect_success 'git help -c' '
108 git help -c >help.output &&
109 cat >expect <<-\EOF &&
110
111 '\''git help config'\'' for more information
112 EOF
113 grep -v -E \
114 -e "^[^.]+\.[^.]+$" \
115 -e "^[^.]+\.[^.]+\.[^.]+$" \
116 help.output >actual &&
117 test_cmp expect actual
118'
119
120test_expect_success 'git help --config-for-completion' '
121 git help -c >human &&
122 grep -E \
123 -e "^[^.]+\.[^.]+$" \
124 -e "^[^.]+\.[^.]+\.[^.]+$" human |
125 sed -e "s/\*.*//" -e "s/<.*//" |
126 sort -u >human.munged &&
127
128 git help --config-for-completion >vars &&
129 test_cmp human.munged vars
130'
131
132test_expect_success 'git help --config-sections-for-completion' '
133 git help -c >human &&
134 grep -E \
135 -e "^[^.]+\.[^.]+$" \
136 -e "^[^.]+\.[^.]+\.[^.]+$" human |
137 sed -e "s/\..*//" |
138 sort -u >human.munged &&
139
140 git help --config-sections-for-completion >sections &&
141 test_cmp human.munged sections
142'
143
144test_section_spacing () {
145 cat >expect &&
146 "$@" >out &&
147 grep -E "(^[^ ]|^$)" out >actual
148}
149
150test_section_spacing_trailer () {
151 test_section_spacing "$@" &&
152 test_expect_code 1 git >out &&
153 sed -n '/list available subcommands/,$p' <out >>expect
154}
155
156
157for cmd in git "git help"
158do
159 test_expect_success "'$cmd' section spacing" '
160 test_section_spacing_trailer git help <<-\EOF &&
161 usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
162
163 These are common Git commands used in various situations:
164
165 start a working area (see also: git help tutorial)
166
167 work on the current change (see also: git help everyday)
168
169 examine the history and state (see also: git help revisions)
170
171 grow, mark and tweak your common history
172
173 collaborate (see also: git help workflows)
174
175 EOF
176 test_cmp expect actual
177 '
178done
179
180test_expect_success "'git help -g' section spacing" '
181 test_section_spacing_trailer git help -g <<-\EOF &&
182
183 The Git concept guides are:
184
185 EOF
186 test_cmp expect actual
187'
188
189test_expect_success 'generate builtin list' '
190 mkdir -p sub &&
191 git --list-cmds=builtins >builtins
192'
193
194while read builtin
195do
196 test_expect_success "$builtin can handle -h" '
197 (
198 GIT_CEILING_DIRECTORIES=$(pwd) &&
199 export GIT_CEILING_DIRECTORIES &&
200 test_expect_code 129 git -C sub $builtin -h >output 2>&1
201 ) &&
202 test_i18ngrep usage output
203 '
204done <builtins
205
206test_done