]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0012-help.sh
checkout/fetch/pull/pack-objects: allow `-h` outside a repository
[thirdparty/git.git] / t / t0012-help.sh
CommitLineData
af74128f
RT
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
63eae83f
NTND
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 &&
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 37test_expect_success 'invalid usage' '
1ed4bef6 38 test_expect_code 129 git help -g add &&
0a5940fb
ÆAB
39 test_expect_code 129 git help -a -c &&
40
41 test_expect_code 129 git help -g add &&
42 test_expect_code 129 git help -a -g &&
43
5a5f04d8 44 test_expect_code 129 git help -g -c &&
a9baccca
ÆAB
45 test_expect_code 129 git help --config-for-completion add &&
46 test_expect_code 129 git help --config-sections-for-completion add
9856ea67
ÆAB
47'
48
af74128f
RT
49test_expect_success "works for commands and guides by default" '
50 configure_help &&
51 git help status &&
52 echo "test://html/git-status.html" >expect &&
53 test_cmp expect test-browser.log &&
54 git help revisions &&
55 echo "test://html/gitrevisions.html" >expect &&
56 test_cmp expect test-browser.log
57'
58
59test_expect_success "--exclude-guides does not work for guides" '
60 >test-browser.log &&
61 test_must_fail git help --exclude-guides revisions &&
62 test_must_be_empty test-browser.log
63'
64
2c6b6d9f
RT
65test_expect_success "--help does not work for guides" "
66 cat <<-EOF >expect &&
67 git: 'revisions' is not a git command. See 'git --help'.
68 EOF
69 test_must_fail git revisions --help 2>actual &&
1108cea7 70 test_cmp expect actual
2c6b6d9f
RT
71"
72
cfb22a02
NTND
73test_expect_success 'git help' '
74 git help >help.output &&
75 test_i18ngrep "^ clone " help.output &&
76 test_i18ngrep "^ add " help.output &&
77 test_i18ngrep "^ log " help.output &&
78 test_i18ngrep "^ commit " help.output &&
79 test_i18ngrep "^ fetch " help.output
80'
1b81d8cb
NTND
81test_expect_success 'git help -g' '
82 git help -g >help.output &&
83 test_i18ngrep "^ attributes " help.output &&
84 test_i18ngrep "^ everyday " help.output &&
85 test_i18ngrep "^ tutorial " help.output
86'
cfb22a02 87
a3952f8e
MA
88test_expect_success 'git help fails for non-existing html pages' '
89 configure_help &&
90 mkdir html-empty &&
91 test_must_fail git -c help.htmlpath=html-empty help status &&
92 test_must_be_empty test-browser.log
93'
94
95test_expect_success 'git help succeeds without git.html' '
96 configure_help &&
97 mkdir html-with-docs &&
98 touch html-with-docs/git-status.html &&
99 git -c help.htmlpath=html-with-docs help status &&
100 echo "html-with-docs/git-status.html" >expect &&
101 test_cmp expect test-browser.log
102'
103
ff76fc84
ÆAB
104test_expect_success 'git help -c' '
105 git help -c >help.output &&
106 cat >expect <<-\EOF &&
107
108 '\''git help config'\'' for more information
109 EOF
110 grep -v -E \
111 -e "^[^.]+\.[^.]+$" \
112 -e "^[^.]+\.[^.]+\.[^.]+$" \
113 help.output >actual &&
114 test_cmp expect actual
115'
116
5a5f04d8
ÆAB
117test_expect_success 'git help --config-for-completion' '
118 git help -c >human &&
119 grep -E \
120 -e "^[^.]+\.[^.]+$" \
121 -e "^[^.]+\.[^.]+\.[^.]+$" human |
122 sed -e "s/\*.*//" -e "s/<.*//" |
123 sort -u >human.munged &&
124
125 git help --config-for-completion >vars &&
5a5f04d8
ÆAB
126 test_cmp human.munged vars
127'
128
a9baccca
ÆAB
129test_expect_success 'git help --config-sections-for-completion' '
130 git help -c >human &&
131 grep -E \
132 -e "^[^.]+\.[^.]+$" \
133 -e "^[^.]+\.[^.]+\.[^.]+$" human |
134 sed -e "s/\..*//" |
135 sort -u >human.munged &&
136
137 git help --config-sections-for-completion >sections &&
138 test_cmp human.munged sections
139'
140
d6915511 141test_expect_success 'generate builtin list' '
0089521c 142 git --list-cmds=builtins >builtins
d6915511
JK
143'
144
145while read builtin
146do
147 test_expect_success "$builtin can handle -h" '
148 test_expect_code 129 git $builtin -h >output 2>&1 &&
149 test_i18ngrep usage output
150 '
151done <builtins
152
af74128f 153test_done