rebase: use correct base for --keep-base when a branch is given
[alt-git.git] / t / t0012-help.sh
blob6c3e1f7159d4dcc6a2e61228fa7c4f3cec42ef3b
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 -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
52 for opt in '-a' '-g' '-c' '--config-for-completion' '--config-sections-for-completion'
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
61 if test "$opt" = "-a"
62 then
63 continue
66 test_expect_success "invalid usage of '$opt' with --no-external-commands" '
67 test_expect_code 129 git help $opt --no-external-commands
70 test_expect_success "invalid usage of '$opt' with --no-aliases" '
71 test_expect_code 129 git help $opt --no-external-commands
73 done
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
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
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
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
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
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
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
130 test_expect_success 'git help -c' '
131 git help -c >help.output &&
132 cat >expect <<-\EOF &&
134 '\''git help config'\'' for more information
136 grep -v -E \
137 -e "^[^.]+\.[^.]+$" \
138 -e "^[^.]+\.[^.]+\.[^.]+$" \
139 help.output >actual &&
140 test_cmp expect actual
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 &&
151 git help --config-for-completion >vars &&
152 test_cmp human.munged vars
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 &&
163 git help --config-sections-for-completion >sections &&
164 test_cmp human.munged sections
167 test_section_spacing () {
168 cat >expect &&
169 "$@" >out &&
170 grep -E "(^[^ ]|^$)" out >actual
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
180 for cmd in git "git help"
182 test_expect_success "'$cmd' section spacing" '
183 test_section_spacing_trailer git help <<-\EOF &&
184 usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
186 These are common Git commands used in various situations:
188 start a working area (see also: git help tutorial)
190 work on the current change (see also: git help everyday)
192 examine the history and state (see also: git help revisions)
194 grow, mark and tweak your common history
196 collaborate (see also: git help workflows)
199 test_cmp expect actual
201 done
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
208 Main Porcelain Commands
210 Ancillary Commands / Manipulators
212 Ancillary Commands / Interrogators
214 Interacting with Others
216 Low-level Commands / Manipulators
218 Low-level Commands / Interrogators
220 Low-level Commands / Syncing Repositories
222 Low-level Commands / Internal Helpers
224 test_cmp expect actual
227 test_expect_success "'git help -g' section spacing" '
228 test_section_spacing_trailer git help -g <<-\EOF &&
229 The Git concept guides are:
232 test_cmp expect actual
235 test_expect_success 'generate builtin list' '
236 mkdir -p sub &&
237 git --list-cmds=builtins >builtins
240 while read builtin
242 test_expect_success "$builtin can handle -h" '
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
250 done <builtins
252 test_done