| 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 | |
| 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 |
| 35 | ' |
| 36 | |
| 37 | test_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 --user-interfaces add && |
| 48 | |
| 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 |
| 52 | ' |
| 53 | |
| 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 | ' |
| 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 | ' |
| 75 | done |
| 76 | |
| 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 | |
| 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 |
| 99 | " |
| 100 | |
| 101 | test_expect_success 'git help' ' |
| 102 | git help >help.output && |
| 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 |
| 108 | ' |
| 109 | |
| 110 | test_expect_success 'git help -g' ' |
| 111 | git help -g >help.output && |
| 112 | test_grep "^ everyday " help.output && |
| 113 | test_grep "^ tutorial " help.output |
| 114 | ' |
| 115 | |
| 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 | |
| 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 | |
| 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 | sed -E -e " |
| 145 | /^[^.]+\.[^.]+$/d |
| 146 | /^[^.]+\.[^.]+\.[^.]+$/d |
| 147 | " help.output >actual && |
| 148 | test_cmp expect actual |
| 149 | ' |
| 150 | |
| 151 | test_expect_success 'git help --config-for-completion' ' |
| 152 | git help -c >human && |
| 153 | sed -E -e " |
| 154 | /^[^.]+\.[^.]+$/b out |
| 155 | /^[^.]+\.[^.]+\.[^.]+$/b out |
| 156 | d |
| 157 | : out |
| 158 | s/\*.*// |
| 159 | s/<.*// |
| 160 | " human | sort -u >human.munged && |
| 161 | |
| 162 | git help --config-for-completion >vars && |
| 163 | test_cmp human.munged vars |
| 164 | ' |
| 165 | |
| 166 | test_expect_success 'git help --config-sections-for-completion' ' |
| 167 | git help -c >human && |
| 168 | sed -E -e " |
| 169 | /^[^.]+\.[^.]+$/b out |
| 170 | /^[^.]+\.[^.]+\.[^.]+$/b out |
| 171 | d |
| 172 | : out |
| 173 | s/\..*// |
| 174 | " human | sort -u >expect && |
| 175 | |
| 176 | git help --config-sections-for-completion >actual && |
| 177 | test_cmp expect actual |
| 178 | ' |
| 179 | |
| 180 | test_section_spacing () { |
| 181 | cat >expect && |
| 182 | "$@" >out && |
| 183 | grep -E "(^[^ ]|^$)" out >actual |
| 184 | } |
| 185 | |
| 186 | test_section_spacing_trailer () { |
| 187 | test_section_spacing "$@" && |
| 188 | test_expect_code 1 git >out && |
| 189 | sed -n '/list available subcommands/,$p' <out >>expect |
| 190 | } |
| 191 | |
| 192 | |
| 193 | for cmd in git "git help" |
| 194 | do |
| 195 | test_expect_success "'$cmd' section spacing" ' |
| 196 | test_section_spacing_trailer git help <<-\EOF && |
| 197 | usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>] |
| 198 | |
| 199 | These are common Git commands used in various situations: |
| 200 | |
| 201 | start a working area (see also: git help tutorial) |
| 202 | |
| 203 | work on the current change (see also: git help everyday) |
| 204 | |
| 205 | examine the history and state (see also: git help revisions) |
| 206 | |
| 207 | grow, mark and tweak your common history |
| 208 | |
| 209 | collaborate (see also: git help workflows) |
| 210 | |
| 211 | EOF |
| 212 | test_cmp expect actual |
| 213 | ' |
| 214 | done |
| 215 | |
| 216 | test_expect_success "'git help -a' section spacing" ' |
| 217 | test_section_spacing \ |
| 218 | git help -a --no-external-commands --no-aliases <<-\EOF && |
| 219 | See '\''git help <command>'\'' to read about a specific subcommand |
| 220 | |
| 221 | Main Porcelain Commands |
| 222 | |
| 223 | Ancillary Commands / Manipulators |
| 224 | |
| 225 | Ancillary Commands / Interrogators |
| 226 | |
| 227 | Interacting with Others |
| 228 | |
| 229 | Low-level Commands / Manipulators |
| 230 | |
| 231 | Low-level Commands / Interrogators |
| 232 | |
| 233 | Low-level Commands / Syncing Repositories |
| 234 | |
| 235 | Low-level Commands / Internal Helpers |
| 236 | |
| 237 | User-facing repository, command and file interfaces |
| 238 | |
| 239 | Developer-facing file formats, protocols and other interfaces |
| 240 | EOF |
| 241 | test_cmp expect actual |
| 242 | ' |
| 243 | |
| 244 | test_expect_success "'git help -g' section spacing" ' |
| 245 | test_section_spacing_trailer git help -g <<-\EOF && |
| 246 | The Git concept guides are: |
| 247 | |
| 248 | EOF |
| 249 | test_cmp expect actual |
| 250 | ' |
| 251 | |
| 252 | test_expect_success 'generate builtin list' ' |
| 253 | mkdir -p sub && |
| 254 | git --list-cmds=builtins >builtins |
| 255 | ' |
| 256 | |
| 257 | while read builtin |
| 258 | do |
| 259 | test_expect_success "$builtin can handle -h" ' |
| 260 | ( |
| 261 | GIT_CEILING_DIRECTORIES=$(pwd) && |
| 262 | export GIT_CEILING_DIRECTORIES && |
| 263 | test_expect_code 129 git -C sub $builtin -h >output 2>err |
| 264 | ) && |
| 265 | test_must_be_empty err && |
| 266 | test_grep usage output |
| 267 | ' |
| 268 | done <builtins |
| 269 | |
| 270 | test_done |