* [PATCH] completion: adapt git-config(1) to complete subcommands
@ 2024-05-16 4:56 Patrick Steinhardt
2024-05-16 15:53 ` Junio C Hamano
2024-05-17 6:13 ` [PATCH v2] " Patrick Steinhardt
0 siblings, 2 replies; 6+ messages in thread
From: Patrick Steinhardt @ 2024-05-16 4:56 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 5374 bytes --]
With fe3ccc7aab (Merge branch 'ps/config-subcommands', 2024-05-15),
git-config(1) has gained support for subcommands. These subcommands live
next to the old, action-based mode, so that both the old and new way
continue to work.
The manpage for this command has been updated to prominently show the
subcommands, and the action-based modes are marked as deprecated. Update
Bash completion scripts accordingly to advertise subcommands instead of
actions.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
I have based this on top of 19fe900cfc (The fourth batch, 2024-05-15),
which contains the config subcommands topic by now.
contrib/completion/git-completion.bash | 38 ++++++++++++-----
t/t9902-completion.sh | 56 +++++++++++++++++++-------
2 files changed, 69 insertions(+), 25 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 5c0ddeb3d4..ab370f8b49 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2989,22 +2989,38 @@ __git_complete_config_variable_name_and_value ()
_git_config ()
{
- case "$prev" in
- --get|--get-all|--unset|--unset-all)
- __gitcomp_nl "$(__git_config_get_set_variables)"
+ local subcommands="list get set unset rename-section remove-section edit"
+ local subcommand="$(__git_find_on_cmdline "$subcommands")"
+
+ if [ -z "$subcommand" ]
+ then
+ __gitcomp "$subcommands"
return
- ;;
- *.*)
- __git_complete_config_variable_value
+ fi
+
+ case "$cur" in
+ --*)
+ __gitcomp_builtin "config_$subcommand"
return
;;
esac
- case "$cur" in
- --*)
- __gitcomp_builtin config
+
+ case "$subcommand" in
+ get)
+ __gitcomp_nl "$(__git_config_get_set_variables)"
;;
- *)
- __git_complete_config_variable_name
+ set)
+ case "$prev" in
+ *.*)
+ __git_complete_config_variable_value
+ ;;
+ *)
+ __git_complete_config_variable_name
+ ;;
+ esac
+ ;;
+ unset)
+ __gitcomp_nl "$(__git_config_get_set_variables)"
;;
esac
}
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 963f865f27..64c9979423 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -2742,30 +2742,58 @@ do
'
done
-test_expect_success 'git config - section' '
- test_completion "git config br" <<-\EOF
+test_expect_success 'git config subcommand' '
+ test_completion "git config " <<-\EOF
+ edit Z
+ get Z
+ list Z
+ remove-section Z
+ rename-section Z
+ set Z
+ unset Z
+ EOF
+'
+
+test_expect_success 'git config subcommand options' '
+ test_completion "git config get --show-" <<-\EOF
+ --show-names Z
+ --show-origin Z
+ --show-scope Z
+ EOF
+'
+
+test_expect_success 'git config get' '
+ test_when_finished "rm -f cfgfile" &&
+ git config set --file cfgfile foo.bar baz &&
+ test_completion "git config get --file cfgfile foo." <<-\EOF
+ foo.bar Z
+ EOF
+'
+
+test_expect_success 'git config set - section' '
+ test_completion "git config set br" <<-\EOF
branch.Z
browser.Z
EOF
'
-test_expect_success 'git config - section include, includeIf' '
- test_completion "git config inclu" <<-\EOF
+test_expect_success 'git config set - section include, includeIf' '
+ test_completion "git config set inclu" <<-\EOF
include.Z
includeIf.Z
EOF
'
-test_expect_success 'git config - variable name' '
- test_completion "git config log.d" <<-\EOF
+test_expect_success 'git config set - variable name' '
+ test_completion "git config set log.d" <<-\EOF
log.date Z
log.decorate Z
log.diffMerges Z
EOF
'
-test_expect_success 'git config - variable name include' '
- test_completion "git config include.p" <<-\EOF
+test_expect_success 'git config set - variable name include' '
+ test_completion "git config set include.p" <<-\EOF
include.path Z
EOF
'
@@ -2776,8 +2804,8 @@ test_expect_success 'setup for git config submodule tests' '
git submodule add ./sub
'
-test_expect_success 'git config - variable name - submodule and __git_compute_first_level_config_vars_for_section' '
- test_completion "git config submodule." <<-\EOF
+test_expect_success 'git config set - variable name - submodule and __git_compute_first_level_config_vars_for_section' '
+ test_completion "git config set submodule." <<-\EOF
submodule.active Z
submodule.alternateErrorStrategy Z
submodule.alternateLocation Z
@@ -2788,8 +2816,8 @@ test_expect_success 'git config - variable name - submodule and __git_compute_fi
EOF
'
-test_expect_success 'git config - variable name - __git_compute_second_level_config_vars_for_section' '
- test_completion "git config submodule.sub." <<-\EOF
+test_expect_success 'git config set - variable name - __git_compute_second_level_config_vars_for_section' '
+ test_completion "git config set submodule.sub." <<-\EOF
submodule.sub.url Z
submodule.sub.update Z
submodule.sub.branch Z
@@ -2799,8 +2827,8 @@ test_expect_success 'git config - variable name - __git_compute_second_level_con
EOF
'
-test_expect_success 'git config - value' '
- test_completion "git config color.pager " <<-\EOF
+test_expect_success 'git config set - value' '
+ test_completion "git config set color.pager " <<-\EOF
false Z
true Z
EOF
--
2.45.1.190.g19fe900cfc.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] completion: adapt git-config(1) to complete subcommands
2024-05-16 4:56 [PATCH] completion: adapt git-config(1) to complete subcommands Patrick Steinhardt
@ 2024-05-16 15:53 ` Junio C Hamano
2024-05-17 6:05 ` Patrick Steinhardt
2024-05-17 6:13 ` [PATCH v2] " Patrick Steinhardt
1 sibling, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2024-05-16 15:53 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git
Patrick Steinhardt <ps@pks.im> writes:
> + local subcommands="list get set unset rename-section remove-section edit"
Wouldn't "git config --git-completion-helper[-all]" work here?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] completion: adapt git-config(1) to complete subcommands
2024-05-16 15:53 ` Junio C Hamano
@ 2024-05-17 6:05 ` Patrick Steinhardt
0 siblings, 0 replies; 6+ messages in thread
From: Patrick Steinhardt @ 2024-05-17 6:05 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 376 bytes --]
On Thu, May 16, 2024 at 08:53:08AM -0700, Junio C Hamano wrote:
> Patrick Steinhardt <ps@pks.im> writes:
>
> > + local subcommands="list get set unset rename-section remove-section edit"
>
> Wouldn't "git config --git-completion-helper[-all]" work here?
I knew there was something here, but I just wasn't able to find it
yesterday.
Will fix, thanks!
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] completion: adapt git-config(1) to complete subcommands
2024-05-16 4:56 [PATCH] completion: adapt git-config(1) to complete subcommands Patrick Steinhardt
2024-05-16 15:53 ` Junio C Hamano
@ 2024-05-17 6:13 ` Patrick Steinhardt
2024-05-17 16:27 ` Rubén Justo
1 sibling, 1 reply; 6+ messages in thread
From: Patrick Steinhardt @ 2024-05-17 6:13 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 6072 bytes --]
With fe3ccc7aab (Merge branch 'ps/config-subcommands', 2024-05-15),
git-config(1) has gained support for subcommands. These subcommands live
next to the old, action-based mode, so that both the old and new way
continue to work.
The manpage for this command has been updated to prominently show the
subcommands, and the action-based modes are marked as deprecated. Update
Bash completion scripts accordingly to advertise subcommands instead of
actions.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
Range-diff against v1:
1: e0039edb9b ! 1: 8d43dee332 completion: adapt git-config(1) to complete subcommands
@@ contrib/completion/git-completion.bash: __git_complete_config_variable_name_and_
- case "$prev" in
- --get|--get-all|--unset|--unset-all)
- __gitcomp_nl "$(__git_config_get_set_variables)"
-+ local subcommands="list get set unset rename-section remove-section edit"
-+ local subcommand="$(__git_find_on_cmdline "$subcommands")"
++ local subcommands subcommand
++
++ __git_resolve_builtins "config"
++
++ subcommands="$___git_resolved_builtins"
++ subcommand="$(__git_find_subcommand "$subcommands")"
+
+ if [ -z "$subcommand" ]
+ then
contrib/completion/git-completion.bash | 42 ++++++++++++++-----
t/t9902-completion.sh | 56 +++++++++++++++++++-------
2 files changed, 73 insertions(+), 25 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 5c0ddeb3d4..60a22d619a 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2989,22 +2989,42 @@ __git_complete_config_variable_name_and_value ()
_git_config ()
{
- case "$prev" in
- --get|--get-all|--unset|--unset-all)
- __gitcomp_nl "$(__git_config_get_set_variables)"
+ local subcommands subcommand
+
+ __git_resolve_builtins "config"
+
+ subcommands="$___git_resolved_builtins"
+ subcommand="$(__git_find_subcommand "$subcommands")"
+
+ if [ -z "$subcommand" ]
+ then
+ __gitcomp "$subcommands"
return
- ;;
- *.*)
- __git_complete_config_variable_value
+ fi
+
+ case "$cur" in
+ --*)
+ __gitcomp_builtin "config_$subcommand"
return
;;
esac
- case "$cur" in
- --*)
- __gitcomp_builtin config
+
+ case "$subcommand" in
+ get)
+ __gitcomp_nl "$(__git_config_get_set_variables)"
;;
- *)
- __git_complete_config_variable_name
+ set)
+ case "$prev" in
+ *.*)
+ __git_complete_config_variable_value
+ ;;
+ *)
+ __git_complete_config_variable_name
+ ;;
+ esac
+ ;;
+ unset)
+ __gitcomp_nl "$(__git_config_get_set_variables)"
;;
esac
}
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 963f865f27..64c9979423 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -2742,30 +2742,58 @@ do
'
done
-test_expect_success 'git config - section' '
- test_completion "git config br" <<-\EOF
+test_expect_success 'git config subcommand' '
+ test_completion "git config " <<-\EOF
+ edit Z
+ get Z
+ list Z
+ remove-section Z
+ rename-section Z
+ set Z
+ unset Z
+ EOF
+'
+
+test_expect_success 'git config subcommand options' '
+ test_completion "git config get --show-" <<-\EOF
+ --show-names Z
+ --show-origin Z
+ --show-scope Z
+ EOF
+'
+
+test_expect_success 'git config get' '
+ test_when_finished "rm -f cfgfile" &&
+ git config set --file cfgfile foo.bar baz &&
+ test_completion "git config get --file cfgfile foo." <<-\EOF
+ foo.bar Z
+ EOF
+'
+
+test_expect_success 'git config set - section' '
+ test_completion "git config set br" <<-\EOF
branch.Z
browser.Z
EOF
'
-test_expect_success 'git config - section include, includeIf' '
- test_completion "git config inclu" <<-\EOF
+test_expect_success 'git config set - section include, includeIf' '
+ test_completion "git config set inclu" <<-\EOF
include.Z
includeIf.Z
EOF
'
-test_expect_success 'git config - variable name' '
- test_completion "git config log.d" <<-\EOF
+test_expect_success 'git config set - variable name' '
+ test_completion "git config set log.d" <<-\EOF
log.date Z
log.decorate Z
log.diffMerges Z
EOF
'
-test_expect_success 'git config - variable name include' '
- test_completion "git config include.p" <<-\EOF
+test_expect_success 'git config set - variable name include' '
+ test_completion "git config set include.p" <<-\EOF
include.path Z
EOF
'
@@ -2776,8 +2804,8 @@ test_expect_success 'setup for git config submodule tests' '
git submodule add ./sub
'
-test_expect_success 'git config - variable name - submodule and __git_compute_first_level_config_vars_for_section' '
- test_completion "git config submodule." <<-\EOF
+test_expect_success 'git config set - variable name - submodule and __git_compute_first_level_config_vars_for_section' '
+ test_completion "git config set submodule." <<-\EOF
submodule.active Z
submodule.alternateErrorStrategy Z
submodule.alternateLocation Z
@@ -2788,8 +2816,8 @@ test_expect_success 'git config - variable name - submodule and __git_compute_fi
EOF
'
-test_expect_success 'git config - variable name - __git_compute_second_level_config_vars_for_section' '
- test_completion "git config submodule.sub." <<-\EOF
+test_expect_success 'git config set - variable name - __git_compute_second_level_config_vars_for_section' '
+ test_completion "git config set submodule.sub." <<-\EOF
submodule.sub.url Z
submodule.sub.update Z
submodule.sub.branch Z
@@ -2799,8 +2827,8 @@ test_expect_success 'git config - variable name - __git_compute_second_level_con
EOF
'
-test_expect_success 'git config - value' '
- test_completion "git config color.pager " <<-\EOF
+test_expect_success 'git config set - value' '
+ test_completion "git config set color.pager " <<-\EOF
false Z
true Z
EOF
base-commit: 19fe900cfce8096b7645ec9611a0b981f6bbd154
--
2.45.1.190.g19fe900cfc.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] completion: adapt git-config(1) to complete subcommands
2024-05-17 6:13 ` [PATCH v2] " Patrick Steinhardt
@ 2024-05-17 16:27 ` Rubén Justo
2024-05-21 6:23 ` Patrick Steinhardt
0 siblings, 1 reply; 6+ messages in thread
From: Rubén Justo @ 2024-05-17 16:27 UTC (permalink / raw)
To: Patrick Steinhardt, git; +Cc: Junio C Hamano
On Fri, May 17, 2024 at 08:13:36AM +0200, Patrick Steinhardt wrote:
> ++ __git_resolve_builtins "config"
The __git_resolve_builtins() function executes "git config
--git-completion-helper" and caches the result for future calls. And
on return ...
> ++
> ++ subcommands="$___git_resolved_builtins"
... it populates the ___git_resolved_builtins variable with the result:
the available subcommands for "git config".
> ++ subcommand="$(__git_find_subcommand "$subcommands")"
Then, we look for a subcommand among those returned, at
${words[__git_cmd_idx+1]}, where a possible command must reside.
Nicely done. This looks good to me.
I wonder, if we might consider the possibility of having "list" as
a default command:
- subcommand="$(__git_find_subcommand "$subcommands")"
+ subcommand="$(__git_find_subcommand "$subcommands" list)"
These lines are only meant to express the idea, as other changes are
also necessary and the documentation needs to be updated. Of course, it
could be done in a future series.
I think that "git config -h" is an intuitive enough way to offer the
help text and that using 'git config' as a shortcut for 'git config
list' can be convenient.
By the way, having used '__git_find_subcommand' instead of
'__git_find_on_cmdline' is reassuring when it comes to having a default
subcommand :-)
Anyway, as I said, this series looks good to me. Thanks!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] completion: adapt git-config(1) to complete subcommands
2024-05-17 16:27 ` Rubén Justo
@ 2024-05-21 6:23 ` Patrick Steinhardt
0 siblings, 0 replies; 6+ messages in thread
From: Patrick Steinhardt @ 2024-05-21 6:23 UTC (permalink / raw)
To: Rubén Justo; +Cc: git, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 1354 bytes --]
On Fri, May 17, 2024 at 06:27:54PM +0200, Rubén Justo wrote:
> On Fri, May 17, 2024 at 08:13:36AM +0200, Patrick Steinhardt wrote:
[snip]
> I wonder, if we might consider the possibility of having "list" as
> a default command:
>
> - subcommand="$(__git_find_subcommand "$subcommands")"
> + subcommand="$(__git_find_subcommand "$subcommands" list)"
>
> These lines are only meant to express the idea, as other changes are
> also necessary and the documentation needs to be updated. Of course, it
> could be done in a future series.
>
> I think that "git config -h" is an intuitive enough way to offer the
> help text and that using 'git config' as a shortcut for 'git config
> list' can be convenient.
Hm. I don't really know whether it is sensible to second-guess what the
user wants to do. They may want to list variables, but they may just as
well not want to do that. I myself use tab completion to learn about
which subcommands exist quite often, even though there is `-h` to do
that for me. So I think I lean more towards not having a default
subcommand here.
> By the way, having used '__git_find_subcommand' instead of
> '__git_find_on_cmdline' is reassuring when it comes to having a default
> subcommand :-)
>
> Anyway, as I said, this series looks good to me. Thanks!
Thanks for your review!
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-05-21 6:23 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-16 4:56 [PATCH] completion: adapt git-config(1) to complete subcommands Patrick Steinhardt
2024-05-16 15:53 ` Junio C Hamano
2024-05-17 6:05 ` Patrick Steinhardt
2024-05-17 6:13 ` [PATCH v2] " Patrick Steinhardt
2024-05-17 16:27 ` Rubén Justo
2024-05-21 6:23 ` Patrick Steinhardt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).