diff options
author | Ævar Arnfjörð Bjarmason <avarab@gmail.com> | 2021-09-22 00:40:38 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-09-23 10:30:43 -0700 |
commit | a9bacccae54cd449821416199f70c4dd2fcb9be4 (patch) | |
tree | 9e6372ebda52532085f7b978ab086e448e29cab7 /t/t0012-help.sh | |
parent | help tests: test --config-for-completion option & output (diff) | |
download | tgif-a9bacccae54cd449821416199f70c4dd2fcb9be4.tar.xz |
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>
Diffstat (limited to 't/t0012-help.sh')
-rwxr-xr-x | t/t0012-help.sh | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/t/t0012-help.sh b/t/t0012-help.sh index 25bbaf0d58..60d713021f 100755 --- a/t/t0012-help.sh +++ b/t/t0012-help.sh @@ -42,7 +42,8 @@ test_expect_success 'invalid usage' ' test_expect_code 129 git help -a -g && test_expect_code 129 git help -g -c && - test_expect_code 0 git help --config-for-completion add + test_expect_code 129 git help --config-for-completion add && + test_expect_code 129 git help --config-sections-for-completion add ' test_expect_success "works for commands and guides by default" ' @@ -106,11 +107,21 @@ test_expect_success 'git help --config-for-completion' ' sort -u >human.munged && git help --config-for-completion >vars && - sort -u <vars >vars.new && - mv vars.new vars && test_cmp human.munged vars ' +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 +' + test_expect_success 'generate builtin list' ' git --list-cmds=builtins >builtins ' |