2016-08-26 17:58:35 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='help'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
configure_help () {
|
|
|
|
test_config help.format html &&
|
|
|
|
|
|
|
|
# Unless the path has "://" in it, Git tries to make sure
|
|
|
|
# the documentation directory locally exists. Avoid it as
|
|
|
|
# we are only interested in seeing an attempt to correctly
|
|
|
|
# invoke a help browser in this test.
|
|
|
|
test_config help.htmlpath test://html &&
|
|
|
|
|
|
|
|
# Name a custom browser
|
|
|
|
test_config browser.test.cmd ./test-browser &&
|
|
|
|
test_config help.browser test
|
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success "setup" '
|
|
|
|
# Just write out which page gets requested
|
|
|
|
write_script test-browser <<-\EOF
|
|
|
|
echo "$*" >test-browser.log
|
|
|
|
EOF
|
|
|
|
'
|
|
|
|
|
2018-05-20 18:40:01 +00:00
|
|
|
# make sure to exercise these code paths, the output is a bit tricky
|
|
|
|
# to verify
|
|
|
|
test_expect_success 'basic help commands' '
|
|
|
|
git help >/dev/null &&
|
2018-09-29 06:08:14 +00:00
|
|
|
git help -a --no-verbose >/dev/null &&
|
2018-05-20 18:40:01 +00:00
|
|
|
git help -g >/dev/null &&
|
2018-09-29 06:08:14 +00:00
|
|
|
git help -a >/dev/null
|
2018-05-20 18:40:01 +00:00
|
|
|
'
|
|
|
|
|
2021-09-21 22:40:32 +00:00
|
|
|
test_expect_success 'invalid usage' '
|
2022-02-21 19:38:49 +00:00
|
|
|
test_expect_code 129 git help -a add &&
|
|
|
|
test_expect_code 129 git help --all add &&
|
|
|
|
|
2021-09-21 22:40:34 +00:00
|
|
|
test_expect_code 129 git help -g add &&
|
2021-09-21 22:40:35 +00:00
|
|
|
test_expect_code 129 git help -a -c &&
|
|
|
|
|
|
|
|
test_expect_code 129 git help -g add &&
|
|
|
|
test_expect_code 129 git help -a -g &&
|
|
|
|
|
2022-08-04 16:28:33 +00:00
|
|
|
test_expect_code 129 git help --user-interfaces add &&
|
|
|
|
|
2021-09-21 22:40:37 +00:00
|
|
|
test_expect_code 129 git help -g -c &&
|
help / completion: make "git help" do the hard work
The "help" builtin has been able to emit configuration variables since
e17ca926371 (completion: drop the hard coded list of config vars,
2018-05-26), but it hasn't produced exactly the format the completion
script wanted. Let's do that.
We got partway there in 2675ea1cc0f (completion: use 'sort -u' to
deduplicate config variable names, 2019-08-13) and
d9438873c4d (completion: deduplicate configuration sections,
2019-08-13), but after both we still needed some sorting,
de-duplicating and awk post-processing of the list.
We can instead simply do the relevant parsing ourselves (we were doing
most of it already), and call string_list_remove_duplicates() after
already sorting the list, so the caller doesn't need to invoke "sort
-u". The "--config-for-completion" output is the same as before after
being passed through "sort -u".
Then add a new "--config-sections-for-completion" option. Under that
output we'll emit config sections like "alias" (instead of "alias." in
the --config-for-completion output).
We need to be careful to leave the "--config-for-completion" option
compatible with users git, but are still running a shell with an older
git-completion.bash. If we e.g. changed the option name they'd see
messages about git-completion.bash being unable to find the
"--config-for-completion" option.
Such backwards compatibility isn't something we should bend over
backwards for, it's only helping users who:
* Upgrade git
* Are in an old shell
* The git-completion.bash in that shell hasn't cached the old
"--config-for-completion" output already.
But since it's easy in this case to retain compatibility, let's do it,
the older versions of git-completion.bash won't care that the input
they get doesn't change after a "sort -u".
While we're at it let's make "--config-for-completion" die if there's
anything left over in "argc", and do the same in the new
"--config-sections-for-completion" option.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-09-21 22:40:38 +00:00
|
|
|
test_expect_code 129 git help --config-for-completion add &&
|
|
|
|
test_expect_code 129 git help --config-sections-for-completion add
|
2021-09-21 22:40:32 +00:00
|
|
|
'
|
|
|
|
|
2022-02-21 19:38:50 +00:00
|
|
|
for opt in '-a' '-g' '-c' '--config-for-completion' '--config-sections-for-completion'
|
|
|
|
do
|
|
|
|
test_expect_success "invalid usage of '$opt' with [-i|-m|-w]" '
|
|
|
|
git help $opt &&
|
|
|
|
test_expect_code 129 git help $opt -i &&
|
|
|
|
test_expect_code 129 git help $opt -m &&
|
|
|
|
test_expect_code 129 git help $opt -w
|
|
|
|
'
|
2022-02-21 19:38:51 +00:00
|
|
|
|
|
|
|
if test "$opt" = "-a"
|
|
|
|
then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
test_expect_success "invalid usage of '$opt' with --no-external-commands" '
|
|
|
|
test_expect_code 129 git help $opt --no-external-commands
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success "invalid usage of '$opt' with --no-aliases" '
|
|
|
|
test_expect_code 129 git help $opt --no-external-commands
|
|
|
|
'
|
2022-02-21 19:38:50 +00:00
|
|
|
done
|
|
|
|
|
2016-08-26 17:58:35 +00:00
|
|
|
test_expect_success "works for commands and guides by default" '
|
|
|
|
configure_help &&
|
|
|
|
git help status &&
|
|
|
|
echo "test://html/git-status.html" >expect &&
|
|
|
|
test_cmp expect test-browser.log &&
|
|
|
|
git help revisions &&
|
|
|
|
echo "test://html/gitrevisions.html" >expect &&
|
|
|
|
test_cmp expect test-browser.log
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success "--exclude-guides does not work for guides" '
|
|
|
|
>test-browser.log &&
|
|
|
|
test_must_fail git help --exclude-guides revisions &&
|
|
|
|
test_must_be_empty test-browser.log
|
|
|
|
'
|
|
|
|
|
2016-08-26 17:58:36 +00:00
|
|
|
test_expect_success "--help does not work for guides" "
|
|
|
|
cat <<-EOF >expect &&
|
|
|
|
git: 'revisions' is not a git command. See 'git --help'.
|
|
|
|
EOF
|
|
|
|
test_must_fail git revisions --help 2>actual &&
|
2021-02-11 01:53:53 +00:00
|
|
|
test_cmp expect actual
|
2016-08-26 17:58:36 +00:00
|
|
|
"
|
|
|
|
|
2018-05-10 08:46:42 +00:00
|
|
|
test_expect_success 'git help' '
|
|
|
|
git help >help.output &&
|
|
|
|
test_i18ngrep "^ clone " help.output &&
|
|
|
|
test_i18ngrep "^ add " help.output &&
|
|
|
|
test_i18ngrep "^ log " help.output &&
|
|
|
|
test_i18ngrep "^ commit " help.output &&
|
|
|
|
test_i18ngrep "^ fetch " help.output
|
|
|
|
'
|
2022-08-04 16:28:33 +00:00
|
|
|
|
2018-05-20 18:40:02 +00:00
|
|
|
test_expect_success 'git help -g' '
|
|
|
|
git help -g >help.output &&
|
|
|
|
test_i18ngrep "^ everyday " help.output &&
|
|
|
|
test_i18ngrep "^ tutorial " help.output
|
|
|
|
'
|
2018-05-10 08:46:42 +00:00
|
|
|
|
2021-09-14 13:27:17 +00:00
|
|
|
test_expect_success 'git help fails for non-existing html pages' '
|
|
|
|
configure_help &&
|
|
|
|
mkdir html-empty &&
|
|
|
|
test_must_fail git -c help.htmlpath=html-empty help status &&
|
|
|
|
test_must_be_empty test-browser.log
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git help succeeds without git.html' '
|
|
|
|
configure_help &&
|
|
|
|
mkdir html-with-docs &&
|
|
|
|
touch html-with-docs/git-status.html &&
|
|
|
|
git -c help.htmlpath=html-with-docs help status &&
|
|
|
|
echo "html-with-docs/git-status.html" >expect &&
|
|
|
|
test_cmp expect test-browser.log
|
|
|
|
'
|
|
|
|
|
2022-08-04 16:28:33 +00:00
|
|
|
test_expect_success 'git help --user-interfaces' '
|
|
|
|
git help --user-interfaces >help.output &&
|
|
|
|
grep "^ attributes " help.output &&
|
|
|
|
grep "^ mailmap " help.output
|
|
|
|
'
|
|
|
|
|
2021-09-21 22:40:33 +00:00
|
|
|
test_expect_success 'git help -c' '
|
|
|
|
git help -c >help.output &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
|
|
|
|
'\''git help config'\'' for more information
|
|
|
|
EOF
|
|
|
|
grep -v -E \
|
|
|
|
-e "^[^.]+\.[^.]+$" \
|
|
|
|
-e "^[^.]+\.[^.]+\.[^.]+$" \
|
|
|
|
help.output >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2021-09-21 22:40:37 +00:00
|
|
|
test_expect_success 'git help --config-for-completion' '
|
|
|
|
git help -c >human &&
|
|
|
|
grep -E \
|
|
|
|
-e "^[^.]+\.[^.]+$" \
|
|
|
|
-e "^[^.]+\.[^.]+\.[^.]+$" human |
|
|
|
|
sed -e "s/\*.*//" -e "s/<.*//" |
|
|
|
|
sort -u >human.munged &&
|
|
|
|
|
|
|
|
git help --config-for-completion >vars &&
|
|
|
|
test_cmp human.munged vars
|
|
|
|
'
|
|
|
|
|
help / completion: make "git help" do the hard work
The "help" builtin has been able to emit configuration variables since
e17ca926371 (completion: drop the hard coded list of config vars,
2018-05-26), but it hasn't produced exactly the format the completion
script wanted. Let's do that.
We got partway there in 2675ea1cc0f (completion: use 'sort -u' to
deduplicate config variable names, 2019-08-13) and
d9438873c4d (completion: deduplicate configuration sections,
2019-08-13), but after both we still needed some sorting,
de-duplicating and awk post-processing of the list.
We can instead simply do the relevant parsing ourselves (we were doing
most of it already), and call string_list_remove_duplicates() after
already sorting the list, so the caller doesn't need to invoke "sort
-u". The "--config-for-completion" output is the same as before after
being passed through "sort -u".
Then add a new "--config-sections-for-completion" option. Under that
output we'll emit config sections like "alias" (instead of "alias." in
the --config-for-completion output).
We need to be careful to leave the "--config-for-completion" option
compatible with users git, but are still running a shell with an older
git-completion.bash. If we e.g. changed the option name they'd see
messages about git-completion.bash being unable to find the
"--config-for-completion" option.
Such backwards compatibility isn't something we should bend over
backwards for, it's only helping users who:
* Upgrade git
* Are in an old shell
* The git-completion.bash in that shell hasn't cached the old
"--config-for-completion" output already.
But since it's easy in this case to retain compatibility, let's do it,
the older versions of git-completion.bash won't care that the input
they get doesn't change after a "sort -u".
While we're at it let's make "--config-for-completion" die if there's
anything left over in "argc", and do the same in the new
"--config-sections-for-completion" option.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-09-21 22:40:38 +00:00
|
|
|
test_expect_success 'git help --config-sections-for-completion' '
|
|
|
|
git help -c >human &&
|
|
|
|
grep -E \
|
|
|
|
-e "^[^.]+\.[^.]+$" \
|
|
|
|
-e "^[^.]+\.[^.]+\.[^.]+$" human |
|
|
|
|
sed -e "s/\..*//" |
|
|
|
|
sort -u >human.munged &&
|
|
|
|
|
|
|
|
git help --config-sections-for-completion >sections &&
|
|
|
|
test_cmp human.munged sections
|
|
|
|
'
|
|
|
|
|
2022-02-21 19:38:46 +00:00
|
|
|
test_section_spacing () {
|
|
|
|
cat >expect &&
|
|
|
|
"$@" >out &&
|
|
|
|
grep -E "(^[^ ]|^$)" out >actual
|
|
|
|
}
|
|
|
|
|
|
|
|
test_section_spacing_trailer () {
|
|
|
|
test_section_spacing "$@" &&
|
|
|
|
test_expect_code 1 git >out &&
|
|
|
|
sed -n '/list available subcommands/,$p' <out >>expect
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for cmd in git "git help"
|
|
|
|
do
|
|
|
|
test_expect_success "'$cmd' section spacing" '
|
|
|
|
test_section_spacing_trailer git help <<-\EOF &&
|
2022-03-31 21:27:09 +00:00
|
|
|
usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>]
|
2022-02-21 19:38:46 +00:00
|
|
|
|
|
|
|
These are common Git commands used in various situations:
|
|
|
|
|
|
|
|
start a working area (see also: git help tutorial)
|
|
|
|
|
|
|
|
work on the current change (see also: git help everyday)
|
|
|
|
|
|
|
|
examine the history and state (see also: git help revisions)
|
|
|
|
|
|
|
|
grow, mark and tweak your common history
|
|
|
|
|
|
|
|
collaborate (see also: git help workflows)
|
|
|
|
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
done
|
|
|
|
|
2022-02-21 19:38:51 +00:00
|
|
|
test_expect_success "'git help -a' section spacing" '
|
|
|
|
test_section_spacing \
|
|
|
|
git help -a --no-external-commands --no-aliases <<-\EOF &&
|
|
|
|
See '\''git help <command>'\'' to read about a specific subcommand
|
|
|
|
|
|
|
|
Main Porcelain Commands
|
|
|
|
|
|
|
|
Ancillary Commands / Manipulators
|
|
|
|
|
|
|
|
Ancillary Commands / Interrogators
|
|
|
|
|
|
|
|
Interacting with Others
|
|
|
|
|
|
|
|
Low-level Commands / Manipulators
|
|
|
|
|
|
|
|
Low-level Commands / Interrogators
|
|
|
|
|
|
|
|
Low-level Commands / Syncing Repositories
|
|
|
|
|
|
|
|
Low-level Commands / Internal Helpers
|
2022-08-04 16:28:33 +00:00
|
|
|
|
|
|
|
User-facing repository, command and file interfaces
|
2022-08-04 16:28:34 +00:00
|
|
|
|
2022-09-16 13:05:29 +00:00
|
|
|
Developer-facing file formats, protocols and other interfaces
|
2022-02-21 19:38:51 +00:00
|
|
|
EOF
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2022-02-21 19:38:46 +00:00
|
|
|
test_expect_success "'git help -g' section spacing" '
|
|
|
|
test_section_spacing_trailer git help -g <<-\EOF &&
|
|
|
|
The Git concept guides are:
|
|
|
|
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2017-05-30 05:19:30 +00:00
|
|
|
test_expect_success 'generate builtin list' '
|
2022-02-08 11:21:54 +00:00
|
|
|
mkdir -p sub &&
|
2018-05-20 18:39:57 +00:00
|
|
|
git --list-cmds=builtins >builtins
|
2017-05-30 05:19:30 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
while read builtin
|
|
|
|
do
|
|
|
|
test_expect_success "$builtin can handle -h" '
|
2022-02-08 11:21:54 +00:00
|
|
|
(
|
|
|
|
GIT_CEILING_DIRECTORIES=$(pwd) &&
|
|
|
|
export GIT_CEILING_DIRECTORIES &&
|
|
|
|
test_expect_code 129 git -C sub $builtin -h >output 2>&1
|
|
|
|
) &&
|
2017-05-30 05:19:30 +00:00
|
|
|
test_i18ngrep usage output
|
|
|
|
'
|
|
|
|
done <builtins
|
|
|
|
|
2016-08-26 17:58:35 +00:00
|
|
|
test_done
|