* [PATCH v4 1/8] completion: bisect: complete bad, new, old, and help subcommands
2024-01-28 22:34 ` [PATCH v4 0/8] " Britton Leo Kerin
@ 2024-01-28 22:34 ` Britton Leo Kerin
2024-02-01 9:55 ` Patrick Steinhardt
2024-01-28 22:34 ` [PATCH v4 2/8] completion: bisect: complete custom terms and related options Britton Leo Kerin
` (8 subsequent siblings)
9 siblings, 1 reply; 58+ messages in thread
From: Britton Leo Kerin @ 2024-01-28 22:34 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
The bad, new, old and help subcommands to git-bisect(1) are not
completed.
Add the bad, new, old, and help subcommands to the appropriate lists
such that the commands and their possible ref arguments are completed.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
contrib/completion/git-completion.bash | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 185b47d802..06d0b156e7 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1449,7 +1449,7 @@ _git_bisect ()
{
__git_has_doubledash && return
- local subcommands="start bad good skip reset visualize replay log run"
+ local subcommands="start bad new good old skip reset visualize replay log run help"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__git_find_repo_path
@@ -1462,7 +1462,7 @@ _git_bisect ()
fi
case "$subcommand" in
- bad|good|reset|skip|start)
+ bad|new|good|old|reset|skip|start)
__git_complete_refs
;;
*)
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* Re: [PATCH v4 1/8] completion: bisect: complete bad, new, old, and help subcommands
2024-01-28 22:34 ` [PATCH v4 1/8] completion: bisect: complete bad, new, old, and help subcommands Britton Leo Kerin
@ 2024-02-01 9:55 ` Patrick Steinhardt
0 siblings, 0 replies; 58+ messages in thread
From: Patrick Steinhardt @ 2024-02-01 9:55 UTC (permalink / raw)
To: Britton Leo Kerin; +Cc: git, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 1359 bytes --]
On Sun, Jan 28, 2024 at 01:34:40PM -0900, Britton Leo Kerin wrote:
> The bad, new, old and help subcommands to git-bisect(1) are not
> completed.
>
> Add the bad, new, old, and help subcommands to the appropriate lists
> such that the commands and their possible ref arguments are completed.
>
> Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
> ---
> contrib/completion/git-completion.bash | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 185b47d802..06d0b156e7 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1449,7 +1449,7 @@ _git_bisect ()
> {
> __git_has_doubledash && return
>
> - local subcommands="start bad good skip reset visualize replay log run"
> + local subcommands="start bad new good old skip reset visualize replay log run help"
> local subcommand="$(__git_find_on_cmdline "$subcommands")"
> if [ -z "$subcommand" ]; then
> __git_find_repo_path
> @@ -1462,7 +1462,7 @@ _git_bisect ()
> fi
>
> case "$subcommand" in
> - bad|good|reset|skip|start)
> + bad|new|good|old|reset|skip|start)
> __git_complete_refs
> ;;
> *)
I didn't even know that `git bisect reset` takes a commit :)
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 58+ messages in thread
* [PATCH v4 2/8] completion: bisect: complete custom terms and related options
2024-01-28 22:34 ` [PATCH v4 0/8] " Britton Leo Kerin
2024-01-28 22:34 ` [PATCH v4 1/8] completion: bisect: complete bad, new, old, and help subcommands Britton Leo Kerin
@ 2024-01-28 22:34 ` Britton Leo Kerin
2024-02-01 9:55 ` Patrick Steinhardt
2024-01-28 22:34 ` [PATCH v4 3/8] completion: bisect: complete missing --first-parent and --no-checkout options Britton Leo Kerin
` (7 subsequent siblings)
9 siblings, 1 reply; 58+ messages in thread
From: Britton Leo Kerin @ 2024-01-28 22:34 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
git bisect supports the use of custom terms via the --term-(new|bad) and
--term-(old|good) options, but the completion code doesn't know about
these options or the new subcommands they define.
Add support for these options and the custom subcommands by checking for
them if a bisection is in progress and adding them to the list of
subcommands.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
contrib/completion/git-completion.bash | 32 ++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 06d0b156e7..8baf330824 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1449,7 +1449,20 @@ _git_bisect ()
{
__git_has_doubledash && return
- local subcommands="start bad new good old skip reset visualize replay log run help"
+ __git_find_repo_path
+
+ # If a bisection is in progress get the terms being used.
+ local term_bad term_good
+ if [ -f "$__git_repo_path"/BISECT_START ]; then
+ term_bad=$(__git bisect terms --term-bad)
+ term_good=$(__git bisect terms --term-good)
+ fi
+
+ # We will complete any custom terms, but still always complete the
+ # more usual bad/new/good/old because git bisect gives a good error
+ # message if these are given when not in use, and that's better than
+ # silent refusal to complete if the user is confused.
+ local subcommands="start bad new $term_bad good old $term_good terms skip reset visualize replay log run help"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__git_find_repo_path
@@ -1462,7 +1475,22 @@ _git_bisect ()
fi
case "$subcommand" in
- bad|new|good|old|reset|skip|start)
+ start)
+ case "$cur" in
+ --*)
+ __gitcomp "--term-new --term-bad --term-old --term-good"
+ return
+ ;;
+ *)
+ __git_complete_refs
+ ;;
+ esac
+ ;;
+ terms)
+ __gitcomp "--term-good --term-old --term-bad --term-new"
+ return
+ ;;
+ bad|new|"$term_bad"|good|old|"$term_good"|reset|skip)
__git_complete_refs
;;
*)
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* Re: [PATCH v4 2/8] completion: bisect: complete custom terms and related options
2024-01-28 22:34 ` [PATCH v4 2/8] completion: bisect: complete custom terms and related options Britton Leo Kerin
@ 2024-02-01 9:55 ` Patrick Steinhardt
0 siblings, 0 replies; 58+ messages in thread
From: Patrick Steinhardt @ 2024-02-01 9:55 UTC (permalink / raw)
To: Britton Leo Kerin; +Cc: git, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 2794 bytes --]
On Sun, Jan 28, 2024 at 01:34:41PM -0900, Britton Leo Kerin wrote:
> git bisect supports the use of custom terms via the --term-(new|bad) and
> --term-(old|good) options, but the completion code doesn't know about
> these options or the new subcommands they define.
>
> Add support for these options and the custom subcommands by checking for
> them if a bisection is in progress and adding them to the list of
> subcommands.
>
> Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
> ---
> contrib/completion/git-completion.bash | 32 ++++++++++++++++++++++++--
> 1 file changed, 30 insertions(+), 2 deletions(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 06d0b156e7..8baf330824 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1449,7 +1449,20 @@ _git_bisect ()
> {
> __git_has_doubledash && return
>
> - local subcommands="start bad new good old skip reset visualize replay log run help"
> + __git_find_repo_path
> +
> + # If a bisection is in progress get the terms being used.
> + local term_bad term_good
> + if [ -f "$__git_repo_path"/BISECT_START ]; then
> + term_bad=$(__git bisect terms --term-bad)
> + term_good=$(__git bisect terms --term-good)
> + fi
Nit: instead of checking for `BISECT_START` we should rather check for
`BISECT_TERMS`. Like that we don't waste two processes for users who
didn't specify any terms, which should be the majority.
We could also parse the terms directly from the file... but I'm not sure
that is really worth it and feels a lot more fragile to me. So I'm not
sure whether or not that is a good idea.
Patrick
> + # We will complete any custom terms, but still always complete the
> + # more usual bad/new/good/old because git bisect gives a good error
> + # message if these are given when not in use, and that's better than
> + # silent refusal to complete if the user is confused.
> + local subcommands="start bad new $term_bad good old $term_good terms skip reset visualize replay log run help"
> local subcommand="$(__git_find_on_cmdline "$subcommands")"
> if [ -z "$subcommand" ]; then
> __git_find_repo_path
> @@ -1462,7 +1475,22 @@ _git_bisect ()
> fi
>
> case "$subcommand" in
> - bad|new|good|old|reset|skip|start)
> + start)
> + case "$cur" in
> + --*)
> + __gitcomp "--term-new --term-bad --term-old --term-good"
> + return
> + ;;
> + *)
> + __git_complete_refs
> + ;;
> + esac
> + ;;
> + terms)
> + __gitcomp "--term-good --term-old --term-bad --term-new"
> + return
> + ;;
> + bad|new|"$term_bad"|good|old|"$term_good"|reset|skip)
> __git_complete_refs
> ;;
> *)
> --
> 2.43.0
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 58+ messages in thread
* [PATCH v4 3/8] completion: bisect: complete missing --first-parent and --no-checkout options
2024-01-28 22:34 ` [PATCH v4 0/8] " Britton Leo Kerin
2024-01-28 22:34 ` [PATCH v4 1/8] completion: bisect: complete bad, new, old, and help subcommands Britton Leo Kerin
2024-01-28 22:34 ` [PATCH v4 2/8] completion: bisect: complete custom terms and related options Britton Leo Kerin
@ 2024-01-28 22:34 ` Britton Leo Kerin
2024-01-28 22:34 ` [PATCH v4 4/8] completion: new function __git_complete_log_opts Britton Leo Kerin
` (6 subsequent siblings)
9 siblings, 0 replies; 58+ messages in thread
From: Britton Leo Kerin @ 2024-01-28 22:34 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
The --first-parent and --no-checkout options to the start subcommand of
git-bisect(1) are not completed.
Enable completion of the --first-parent and --no-checkout options to the
start subcommand.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
contrib/completion/git-completion.bash | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 8baf330824..2ed600244a 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1478,7 +1478,7 @@ _git_bisect ()
start)
case "$cur" in
--*)
- __gitcomp "--term-new --term-bad --term-old --term-good"
+ __gitcomp "--first-parent --no-checkout --term-new --term-bad --term-old --term-good"
return
;;
*)
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH v4 4/8] completion: new function __git_complete_log_opts
2024-01-28 22:34 ` [PATCH v4 0/8] " Britton Leo Kerin
` (2 preceding siblings ...)
2024-01-28 22:34 ` [PATCH v4 3/8] completion: bisect: complete missing --first-parent and --no-checkout options Britton Leo Kerin
@ 2024-01-28 22:34 ` Britton Leo Kerin
2024-01-28 22:34 ` [PATCH v4 5/8] completion: log: use __git_complete_log_opts Britton Leo Kerin
` (5 subsequent siblings)
9 siblings, 0 replies; 58+ messages in thread
From: Britton Leo Kerin @ 2024-01-28 22:34 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
The options accepted by git-log are also accepted by at least one other
command (git-bisect). Prepare to factor out the common option and
option argument completion code by defining a new function.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
contrib/completion/git-completion.bash | 101 +++++++++++++++++++++++++
1 file changed, 101 insertions(+)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 2ed600244a..dfd504c37e 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2089,6 +2089,107 @@ __git_diff_merges_opts="off none on first-parent 1 separate m combined c dense-c
__git_log_pretty_formats="oneline short medium full fuller reference email raw format: tformat: mboxrd"
__git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default human raw unix auto: format:"
+# Complete porcelain (i.e. not git-rev-list) options and at least some
+# option arguments accepted by git-log. Note that this same set of options
+# are also accepted by some other git commands besides git-log.
+__git_complete_log_opts ()
+{
+ COMPREPLY=""
+
+ local merge=""
+ if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
+ merge="--merge"
+ fi
+ case "$prev,$cur" in
+ -L,:*:*)
+ return # fall back to Bash filename completion
+ ;;
+ -L,:*)
+ __git_complete_symbol --cur="${cur#:}" --sfx=":"
+ return
+ ;;
+ -G,*|-S,*)
+ __git_complete_symbol
+ return
+ ;;
+ esac
+ case "$cur" in
+ --pretty=*|--format=*)
+ __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
+ " "" "${cur#*=}"
+ return
+ ;;
+ --date=*)
+ __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
+ return
+ ;;
+ --decorate=*)
+ __gitcomp "full short no" "" "${cur##--decorate=}"
+ return
+ ;;
+ --diff-algorithm=*)
+ __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
+ return
+ ;;
+ --submodule=*)
+ __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
+ return
+ ;;
+ --ws-error-highlight=*)
+ __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
+ return
+ ;;
+ --no-walk=*)
+ __gitcomp "sorted unsorted" "" "${cur##--no-walk=}"
+ return
+ ;;
+ --diff-merges=*)
+ __gitcomp "$__git_diff_merges_opts" "" "${cur##--diff-merges=}"
+ return
+ ;;
+ --*)
+ __gitcomp "
+ $__git_log_common_options
+ $__git_log_shortlog_options
+ $__git_log_gitk_options
+ $__git_log_show_options
+ --root --topo-order --date-order --reverse
+ --follow --full-diff
+ --abbrev-commit --no-abbrev-commit --abbrev=
+ --relative-date --date=
+ --pretty= --format= --oneline
+ --show-signature
+ --cherry-mark
+ --cherry-pick
+ --graph
+ --decorate --decorate= --no-decorate
+ --walk-reflogs
+ --no-walk --no-walk= --do-walk
+ --parents --children
+ --expand-tabs --expand-tabs= --no-expand-tabs
+ $merge
+ $__git_diff_common_options
+ "
+ return
+ ;;
+ -L:*:*)
+ return # fall back to Bash filename completion
+ ;;
+ -L:*)
+ __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
+ return
+ ;;
+ -G*)
+ __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
+ return
+ ;;
+ -S*)
+ __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
+ return
+ ;;
+ esac
+}
+
_git_log ()
{
__git_has_doubledash && return
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH v4 5/8] completion: log: use __git_complete_log_opts
2024-01-28 22:34 ` [PATCH v4 0/8] " Britton Leo Kerin
` (3 preceding siblings ...)
2024-01-28 22:34 ` [PATCH v4 4/8] completion: new function __git_complete_log_opts Britton Leo Kerin
@ 2024-01-28 22:34 ` Britton Leo Kerin
2024-02-01 9:55 ` Patrick Steinhardt
2024-01-28 22:34 ` [PATCH v4 6/8] completion: bisect: complete log opts for visualize subcommand Britton Leo Kerin
` (4 subsequent siblings)
9 siblings, 1 reply; 58+ messages in thread
From: Britton Leo Kerin @ 2024-01-28 22:34 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
Use the new __git_complete_log_opts function to handle option and
optiona rgument completion in _git_log.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
contrib/completion/git-completion.bash | 95 +-------------------------
1 file changed, 3 insertions(+), 92 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index dfd504c37e..41c76c1246 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2195,98 +2195,9 @@ _git_log ()
__git_has_doubledash && return
__git_find_repo_path
- local merge=""
- if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
- merge="--merge"
- fi
- case "$prev,$cur" in
- -L,:*:*)
- return # fall back to Bash filename completion
- ;;
- -L,:*)
- __git_complete_symbol --cur="${cur#:}" --sfx=":"
- return
- ;;
- -G,*|-S,*)
- __git_complete_symbol
- return
- ;;
- esac
- case "$cur" in
- --pretty=*|--format=*)
- __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
- " "" "${cur#*=}"
- return
- ;;
- --date=*)
- __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
- return
- ;;
- --decorate=*)
- __gitcomp "full short no" "" "${cur##--decorate=}"
- return
- ;;
- --diff-algorithm=*)
- __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
- return
- ;;
- --submodule=*)
- __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
- return
- ;;
- --ws-error-highlight=*)
- __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
- return
- ;;
- --no-walk=*)
- __gitcomp "sorted unsorted" "" "${cur##--no-walk=}"
- return
- ;;
- --diff-merges=*)
- __gitcomp "$__git_diff_merges_opts" "" "${cur##--diff-merges=}"
- return
- ;;
- --*)
- __gitcomp "
- $__git_log_common_options
- $__git_log_shortlog_options
- $__git_log_gitk_options
- $__git_log_show_options
- --root --topo-order --date-order --reverse
- --follow --full-diff
- --abbrev-commit --no-abbrev-commit --abbrev=
- --relative-date --date=
- --pretty= --format= --oneline
- --show-signature
- --cherry-mark
- --cherry-pick
- --graph
- --decorate --decorate= --no-decorate
- --walk-reflogs
- --no-walk --no-walk= --do-walk
- --parents --children
- --expand-tabs --expand-tabs= --no-expand-tabs
- $merge
- $__git_diff_common_options
- "
- return
- ;;
- -L:*:*)
- return # fall back to Bash filename completion
- ;;
- -L:*)
- __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
- return
- ;;
- -G*)
- __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
- return
- ;;
- -S*)
- __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
- return
- ;;
- esac
+ __git_complete_log_opts
+ [ -z "$COMPREPLY" ] || return
+
__git_complete_revlist
}
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* Re: [PATCH v4 5/8] completion: log: use __git_complete_log_opts
2024-01-28 22:34 ` [PATCH v4 5/8] completion: log: use __git_complete_log_opts Britton Leo Kerin
@ 2024-02-01 9:55 ` Patrick Steinhardt
0 siblings, 0 replies; 58+ messages in thread
From: Patrick Steinhardt @ 2024-02-01 9:55 UTC (permalink / raw)
To: Britton Leo Kerin; +Cc: git, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 3446 bytes --]
On Sun, Jan 28, 2024 at 01:34:44PM -0900, Britton Leo Kerin wrote:
> Use the new __git_complete_log_opts function to handle option and
> optiona rgument completion in _git_log.
I think this commit could be merged with the preceding one to clarify
that this really only is a move of code. Sorry if my comments on the
previous round weren't clear on that.
Patrick
> Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
> ---
> contrib/completion/git-completion.bash | 95 +-------------------------
> 1 file changed, 3 insertions(+), 92 deletions(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index dfd504c37e..41c76c1246 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -2195,98 +2195,9 @@ _git_log ()
> __git_has_doubledash && return
> __git_find_repo_path
>
> - local merge=""
> - if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
> - merge="--merge"
> - fi
> - case "$prev,$cur" in
> - -L,:*:*)
> - return # fall back to Bash filename completion
> - ;;
> - -L,:*)
> - __git_complete_symbol --cur="${cur#:}" --sfx=":"
> - return
> - ;;
> - -G,*|-S,*)
> - __git_complete_symbol
> - return
> - ;;
> - esac
> - case "$cur" in
> - --pretty=*|--format=*)
> - __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
> - " "" "${cur#*=}"
> - return
> - ;;
> - --date=*)
> - __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
> - return
> - ;;
> - --decorate=*)
> - __gitcomp "full short no" "" "${cur##--decorate=}"
> - return
> - ;;
> - --diff-algorithm=*)
> - __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
> - return
> - ;;
> - --submodule=*)
> - __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
> - return
> - ;;
> - --ws-error-highlight=*)
> - __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
> - return
> - ;;
> - --no-walk=*)
> - __gitcomp "sorted unsorted" "" "${cur##--no-walk=}"
> - return
> - ;;
> - --diff-merges=*)
> - __gitcomp "$__git_diff_merges_opts" "" "${cur##--diff-merges=}"
> - return
> - ;;
> - --*)
> - __gitcomp "
> - $__git_log_common_options
> - $__git_log_shortlog_options
> - $__git_log_gitk_options
> - $__git_log_show_options
> - --root --topo-order --date-order --reverse
> - --follow --full-diff
> - --abbrev-commit --no-abbrev-commit --abbrev=
> - --relative-date --date=
> - --pretty= --format= --oneline
> - --show-signature
> - --cherry-mark
> - --cherry-pick
> - --graph
> - --decorate --decorate= --no-decorate
> - --walk-reflogs
> - --no-walk --no-walk= --do-walk
> - --parents --children
> - --expand-tabs --expand-tabs= --no-expand-tabs
> - $merge
> - $__git_diff_common_options
> - "
> - return
> - ;;
> - -L:*:*)
> - return # fall back to Bash filename completion
> - ;;
> - -L:*)
> - __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
> - return
> - ;;
> - -G*)
> - __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
> - return
> - ;;
> - -S*)
> - __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
> - return
> - ;;
> - esac
> + __git_complete_log_opts
> + [ -z "$COMPREPLY" ] || return
> +
> __git_complete_revlist
> }
>
> --
> 2.43.0
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 58+ messages in thread
* [PATCH v4 6/8] completion: bisect: complete log opts for visualize subcommand
2024-01-28 22:34 ` [PATCH v4 0/8] " Britton Leo Kerin
` (4 preceding siblings ...)
2024-01-28 22:34 ` [PATCH v4 5/8] completion: log: use __git_complete_log_opts Britton Leo Kerin
@ 2024-01-28 22:34 ` Britton Leo Kerin
2024-01-28 22:34 ` [PATCH v4 7/8] completion: bisect: recognize but do not complete view subcommand Britton Leo Kerin
` (3 subsequent siblings)
9 siblings, 0 replies; 58+ messages in thread
From: Britton Leo Kerin @ 2024-01-28 22:34 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
Arguments passed to the "visualize" subcommand of git-bisect(1) get
forwarded to git-log(1). It thus supports the same options as git-log(1)
would, but our Bash completion script does not know to handle this.
Make completion of porcelain git-log options and option arguments to the
visualize subcommand work by calling __git_complete_log_opts when the
start of an option to the subcommand is seen (visualize doesn't support
any options besides the git-log options).
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
contrib/completion/git-completion.bash | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 41c76c1246..ae16e742a4 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1490,6 +1490,10 @@ _git_bisect ()
__gitcomp "--term-good --term-old --term-bad --term-new"
return
;;
+ visualize)
+ __git_complete_log_opts
+ return
+ ;;
bad|new|"$term_bad"|good|old|"$term_good"|reset|skip)
__git_complete_refs
;;
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH v4 7/8] completion: bisect: recognize but do not complete view subcommand
2024-01-28 22:34 ` [PATCH v4 0/8] " Britton Leo Kerin
` (5 preceding siblings ...)
2024-01-28 22:34 ` [PATCH v4 6/8] completion: bisect: complete log opts for visualize subcommand Britton Leo Kerin
@ 2024-01-28 22:34 ` Britton Leo Kerin
2024-01-28 22:34 ` [PATCH v4 8/8] completion: add tests for git-bisect Britton Leo Kerin
` (2 subsequent siblings)
9 siblings, 0 replies; 58+ messages in thread
From: Britton Leo Kerin @ 2024-01-28 22:34 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
The "view" alias for the visualize subcommand is neither completed nor
recognized. It's undesirable to complete it because it's first letters
are the same as for visualize, making completion less rather than more
efficient without adding much in the way of interface discovery.
However, it needs to be recognized in order to enable log option
completion for it.
Recognize but do not complete the view command by creating and using
separate lists of completable_subcommands and all_subcommands.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
contrib/completion/git-completion.bash | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index ae16e742a4..0cf1a5a393 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1462,12 +1462,19 @@ _git_bisect ()
# more usual bad/new/good/old because git bisect gives a good error
# message if these are given when not in use, and that's better than
# silent refusal to complete if the user is confused.
- local subcommands="start bad new $term_bad good old $term_good terms skip reset visualize replay log run help"
- local subcommand="$(__git_find_on_cmdline "$subcommands")"
+ #
+ # We want to recognize 'view' but not complete it, because it overlaps
+ # with 'visualize' too much and is just an alias for it.
+ #
+ local completable_subcommands="start bad new $term_bad good old $term_good terms skip reset visualize replay log run help"
+ local all_subcommands="$completable_subcommands view"
+
+ local subcommand="$(__git_find_on_cmdline "$all_subcommands")"
+
if [ -z "$subcommand" ]; then
__git_find_repo_path
if [ -f "$__git_repo_path"/BISECT_START ]; then
- __gitcomp "$subcommands"
+ __gitcomp "$completable_subcommands"
else
__gitcomp "replay start"
fi
@@ -1490,7 +1497,7 @@ _git_bisect ()
__gitcomp "--term-good --term-old --term-bad --term-new"
return
;;
- visualize)
+ visualize|view)
__git_complete_log_opts
return
;;
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH v4 8/8] completion: add tests for git-bisect
2024-01-28 22:34 ` [PATCH v4 0/8] " Britton Leo Kerin
` (6 preceding siblings ...)
2024-01-28 22:34 ` [PATCH v4 7/8] completion: bisect: recognize but do not complete view subcommand Britton Leo Kerin
@ 2024-01-28 22:34 ` Britton Leo Kerin
2024-01-30 5:47 ` Junio C Hamano
2024-02-01 9:55 ` Patrick Steinhardt
2024-02-01 9:55 ` [PATCH v4 0/8] completion: improvements " Patrick Steinhardt
2024-02-06 2:09 ` [PATCH v5 0/7] " Britton Leo Kerin
9 siblings, 2 replies; 58+ messages in thread
From: Britton Leo Kerin @ 2024-01-28 22:34 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
There aren't any tests for completion of git bisect and it's
subcommands.
Add tests.
---
t/t9902-completion.sh | 135 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 135 insertions(+)
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index aa9a614de3..698e278450 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1259,6 +1259,141 @@ test_expect_success 'git switch - with no options, complete local branches and u
EOF
'
+test_expect_success 'git bisect - when not bisecting, complete only replay and start subcommands' '
+ test_completion "git bisect " <<-\EOF
+ replay Z
+ start Z
+ EOF
+'
+
+test_expect_success 'git bisect - complete options to start subcommand' '
+ test_completion "git bisect start --" <<-\EOF
+ --term-new Z
+ --term-bad Z
+ --term-old Z
+ --term-good Z
+ --no-checkout Z
+ --first-parent Z
+ EOF
+'
+
+test_expect_success 'setup for git-bisect tests requiring a repo' '
+ git init git-bisect &&
+ (
+ cd git-bisect &&
+ echo "initial contents" >file &&
+ git add file &&
+ git commit -am "Initial commit" &&
+ git tag initial &&
+ echo "new line" >>file &&
+ git commit -am "First change" &&
+ echo "another new line" >>file &&
+ git commit -am "Second change" &&
+ git tag final
+ )
+'
+
+test_expect_success 'git bisect - start subcommand arguments before double-dash are completed as revs' '
+ (
+ cd git-bisect &&
+ test_completion "git bisect start " <<-\EOF
+ HEAD Z
+ final Z
+ initial Z
+ master Z
+ EOF
+ )
+'
+
+# Note that these arguments are <pathspec>s, which in practice the fallback
+# completion (not the git completion) later ends up completing as paths.
+test_expect_success 'git bisect - start subcommand arguments after double-dash are not completed' '
+ (
+ cd git-bisect &&
+ test_completion "git bisect start final initial -- " ""
+ )
+'
+
+test_expect_success 'setup for git-bisect tests requiring ongoing bisection' '
+ (
+ cd git-bisect &&
+ git bisect start --term-new=custom_new --term-old=custom_old final initial
+ )
+'
+
+test_expect_success 'git-bisect - when bisecting all subcommands are candidates' '
+ (
+ cd git-bisect &&
+ test_completion "git bisect " <<-\EOF
+ start Z
+ bad Z
+ custom_new Z
+ custom_old Z
+ new Z
+ good Z
+ old Z
+ terms Z
+ skip Z
+ reset Z
+ visualize Z
+ replay Z
+ log Z
+ run Z
+ help Z
+ EOF
+ )
+'
+test_expect_success 'git-bisect - options to terms subcommand are candidates' '
+ (
+ cd git-bisect &&
+ test_completion "git bisect terms --" <<-\EOF
+ --term-bad Z
+ --term-good Z
+ --term-new Z
+ --term-old Z
+ EOF
+ )
+'
+
+test_expect_success 'git-bisect - git-log options to visualize subcommand are candidates' '
+ (
+ cd git-bisect &&
+ # The completion used for git-log and here does not complete
+ # every git-log option, so rather than hope to stay in sync
+ # with exactly what it does we will just spot-test here.
+ test_completion "git bisect visualize --sta" <<-\EOF &&
+ --stat Z
+ EOF
+ test_completion "git bisect visualize --summar" <<-\EOF
+ --summary Z
+ EOF
+ )
+'
+
+test_expect_success 'git-bisect - view subcommand is not a candidate' '
+ (
+ cd git-bisect &&
+ test_completion "git bisect vi" <<-\EOF
+ visualize Z
+ EOF
+ )
+'
+
+test_expect_success 'git-bisect - existing view subcommand is recognized and enables completion of git-log options' '
+ (
+ cd git-bisect &&
+ # The completion used for git-log and here does not complete
+ # every git-log option, so rather than hope to stay in sync
+ # with exactly what it does we will just spot-test here.
+ test_completion "git bisect view --sta" <<-\EOF &&
+ --stat Z
+ EOF
+ test_completion "git bisect view --summar" <<-\EOF
+ --summary Z
+ EOF
+ )
+'
+
test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
test_completion "git checkout " <<-\EOF
HEAD Z
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* Re: [PATCH v4 8/8] completion: add tests for git-bisect
2024-01-28 22:34 ` [PATCH v4 8/8] completion: add tests for git-bisect Britton Leo Kerin
@ 2024-01-30 5:47 ` Junio C Hamano
2024-02-01 9:55 ` Patrick Steinhardt
1 sibling, 0 replies; 58+ messages in thread
From: Junio C Hamano @ 2024-01-30 5:47 UTC (permalink / raw)
To: Britton Leo Kerin; +Cc: git, Patrick Steinhardt
Britton Leo Kerin <britton.kerin@gmail.com> writes:
> +test_expect_success 'git bisect - start subcommand arguments before double-dash are completed as revs' '
> + (
> + cd git-bisect &&
> + test_completion "git bisect start " <<-\EOF
> + HEAD Z
> + final Z
> + initial Z
> + master Z
> + EOF
> + )
> +'
When GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME is set to 'main' (can be
seen as a failure in linux-gcc job in GitHub CI), this piece breaks
the test, because 'master' would not appear there in the list.
You could detect what the initial default branch name currently is
and use that branch name to dynamically generate the above list
during the test. I do not think it is worth it, and forcing the
fixed name should be sufficient.
Perhaps like this (not tested):
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 698e278450..26f616fcfe 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -5,6 +5,8 @@
test_description='test bash completion'
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./lib-bash.sh
complete ()
^ permalink raw reply related [flat|nested] 58+ messages in thread
* Re: [PATCH v4 8/8] completion: add tests for git-bisect
2024-01-28 22:34 ` [PATCH v4 8/8] completion: add tests for git-bisect Britton Leo Kerin
2024-01-30 5:47 ` Junio C Hamano
@ 2024-02-01 9:55 ` Patrick Steinhardt
1 sibling, 0 replies; 58+ messages in thread
From: Patrick Steinhardt @ 2024-02-01 9:55 UTC (permalink / raw)
To: Britton Leo Kerin; +Cc: git, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 4911 bytes --]
On Sun, Jan 28, 2024 at 01:34:47PM -0900, Britton Leo Kerin wrote:
> There aren't any tests for completion of git bisect and it's
> subcommands.
>
> Add tests.
I think it would be nice if you added relevant tests directly in the
commits that introduce the new completions. E.g. add a test for the
bisect terms in the same commit where you introduce the completion for
it.
Like that you can easily add tests one by one, which decreases the
review load. Also, it serves to demonstrate both that the functionality
works and helps the reviewer to understand better what exactly you are
adding by having a nice example.
Patrick
> ---
> t/t9902-completion.sh | 135 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 135 insertions(+)
>
> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
> index aa9a614de3..698e278450 100755
> --- a/t/t9902-completion.sh
> +++ b/t/t9902-completion.sh
> @@ -1259,6 +1259,141 @@ test_expect_success 'git switch - with no options, complete local branches and u
> EOF
> '
>
> +test_expect_success 'git bisect - when not bisecting, complete only replay and start subcommands' '
> + test_completion "git bisect " <<-\EOF
> + replay Z
> + start Z
> + EOF
> +'
> +
> +test_expect_success 'git bisect - complete options to start subcommand' '
> + test_completion "git bisect start --" <<-\EOF
> + --term-new Z
> + --term-bad Z
> + --term-old Z
> + --term-good Z
> + --no-checkout Z
> + --first-parent Z
> + EOF
> +'
> +
> +test_expect_success 'setup for git-bisect tests requiring a repo' '
> + git init git-bisect &&
> + (
> + cd git-bisect &&
> + echo "initial contents" >file &&
> + git add file &&
> + git commit -am "Initial commit" &&
> + git tag initial &&
> + echo "new line" >>file &&
> + git commit -am "First change" &&
> + echo "another new line" >>file &&
> + git commit -am "Second change" &&
> + git tag final
> + )
> +'
> +
> +test_expect_success 'git bisect - start subcommand arguments before double-dash are completed as revs' '
> + (
> + cd git-bisect &&
> + test_completion "git bisect start " <<-\EOF
> + HEAD Z
> + final Z
> + initial Z
> + master Z
> + EOF
> + )
> +'
> +
> +# Note that these arguments are <pathspec>s, which in practice the fallback
> +# completion (not the git completion) later ends up completing as paths.
> +test_expect_success 'git bisect - start subcommand arguments after double-dash are not completed' '
> + (
> + cd git-bisect &&
> + test_completion "git bisect start final initial -- " ""
> + )
> +'
> +
> +test_expect_success 'setup for git-bisect tests requiring ongoing bisection' '
> + (
> + cd git-bisect &&
> + git bisect start --term-new=custom_new --term-old=custom_old final initial
> + )
> +'
> +
> +test_expect_success 'git-bisect - when bisecting all subcommands are candidates' '
> + (
> + cd git-bisect &&
> + test_completion "git bisect " <<-\EOF
> + start Z
> + bad Z
> + custom_new Z
> + custom_old Z
> + new Z
> + good Z
> + old Z
> + terms Z
> + skip Z
> + reset Z
> + visualize Z
> + replay Z
> + log Z
> + run Z
> + help Z
> + EOF
> + )
> +'
> +test_expect_success 'git-bisect - options to terms subcommand are candidates' '
> + (
> + cd git-bisect &&
> + test_completion "git bisect terms --" <<-\EOF
> + --term-bad Z
> + --term-good Z
> + --term-new Z
> + --term-old Z
> + EOF
> + )
> +'
> +
> +test_expect_success 'git-bisect - git-log options to visualize subcommand are candidates' '
> + (
> + cd git-bisect &&
> + # The completion used for git-log and here does not complete
> + # every git-log option, so rather than hope to stay in sync
> + # with exactly what it does we will just spot-test here.
> + test_completion "git bisect visualize --sta" <<-\EOF &&
> + --stat Z
> + EOF
> + test_completion "git bisect visualize --summar" <<-\EOF
> + --summary Z
> + EOF
> + )
> +'
> +
> +test_expect_success 'git-bisect - view subcommand is not a candidate' '
> + (
> + cd git-bisect &&
> + test_completion "git bisect vi" <<-\EOF
> + visualize Z
> + EOF
> + )
> +'
> +
> +test_expect_success 'git-bisect - existing view subcommand is recognized and enables completion of git-log options' '
> + (
> + cd git-bisect &&
> + # The completion used for git-log and here does not complete
> + # every git-log option, so rather than hope to stay in sync
> + # with exactly what it does we will just spot-test here.
> + test_completion "git bisect view --sta" <<-\EOF &&
> + --stat Z
> + EOF
> + test_completion "git bisect view --summar" <<-\EOF
> + --summary Z
> + EOF
> + )
> +'
> +
> test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
> test_completion "git checkout " <<-\EOF
> HEAD Z
> --
> 2.43.0
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 58+ messages in thread
* Re: [PATCH v4 0/8] completion: improvements for git-bisect
2024-01-28 22:34 ` [PATCH v4 0/8] " Britton Leo Kerin
` (7 preceding siblings ...)
2024-01-28 22:34 ` [PATCH v4 8/8] completion: add tests for git-bisect Britton Leo Kerin
@ 2024-02-01 9:55 ` Patrick Steinhardt
2024-02-06 2:09 ` [PATCH v5 0/7] " Britton Leo Kerin
9 siblings, 0 replies; 58+ messages in thread
From: Patrick Steinhardt @ 2024-02-01 9:55 UTC (permalink / raw)
To: Britton Leo Kerin; +Cc: git, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 441 bytes --]
On Sun, Jan 28, 2024 at 01:34:39PM -0900, Britton Leo Kerin wrote:
> Relative to v3 this reworks the commit contents and descriptions
> according to review suggestions, removes unnecessary case statements and
> precondition, adds option completion for the terms subcommand, and adds
> tests.
Thanks for this new version! I've got a few more comments, but overall I
really like what I see here and think that this is getting close.
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 58+ messages in thread
* [PATCH v5 0/7] completion: improvements for git-bisect
2024-01-28 22:34 ` [PATCH v4 0/8] " Britton Leo Kerin
` (8 preceding siblings ...)
2024-02-01 9:55 ` [PATCH v4 0/8] completion: improvements " Patrick Steinhardt
@ 2024-02-06 2:09 ` Britton Leo Kerin
2024-02-06 2:09 ` [PATCH v5 1/7] completion: tests: always use 'master' for default initial branch name Britton Leo Kerin
` (8 more replies)
9 siblings, 9 replies; 58+ messages in thread
From: Britton Leo Kerin @ 2024-02-06 2:09 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
Relative to v4 this make the following actual changes:
* fixes GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME to 'master' for all of
t9902-completion.sh as suggested by Junio. This change affects all
of t9902-completion.sh so I've put it by itself in it's own commit.
* uses BISECT_TERMS to avoid pointless processes as suggested by Patrick.
The commits are also refactored as follows:
* squashes the introduction of __git_complete_log_opts in with it's
first use a suggested by Patrick.
* spreads tests across commits as suggest by Patrick.
Thanks for the reviews.
Britton Leo Kerin (7):
completion: tests: always use 'master' for default initial branch name
completion: bisect: complete bad, new, old, and help subcommands
completion: bisect: complete custom terms and related options
completion: bisect: complete missing --first-parent and --no-checkout
options
completion: new function __git_complete_log_opts
completion: bisect: complete log opts for visualize subcommand
completion: bisect: recognize but do not complete view subcommand
contrib/completion/git-completion.bash | 65 ++++++++++--
t/t9902-completion.sh | 140 +++++++++++++++++++++++++
2 files changed, 198 insertions(+), 7 deletions(-)
Range-diff against v4:
1: 66153024c3 < -: ---------- completion: bisect: complete bad, new, old, and help subcommands
-: ---------- > 1: 71b73de914 completion: tests: always use 'master' for default initial branch name
8: 451b7a4467 ! 2: 3a478a7a08 completion: add tests for git-bisect
@@ Metadata
Author: Britton Leo Kerin <britton.kerin@gmail.com>
## Commit message ##
- completion: add tests for git-bisect
+ completion: bisect: complete bad, new, old, and help subcommands
- There aren't any tests for completion of git bisect and it's
- subcommands.
+ The bad, new, old and help subcommands to git-bisect(1) are not
+ completed.
+ Add the bad, new, old, and help subcommands to the appropriate lists
+ such that the commands and their possible ref arguments are completed.
Add tests.
+ Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.c
+
+ ## contrib/completion/git-completion.bash ##
+@@ contrib/completion/git-completion.bash: _git_bisect ()
+ {
+ __git_has_doubledash && return
+
+- local subcommands="start bad good skip reset visualize replay log run"
++ local subcommands="start bad new good old skip reset visualize replay log run help"
+ local subcommand="$(__git_find_on_cmdline "$subcommands")"
+ if [ -z "$subcommand" ]; then
+ __git_find_repo_path
+@@ contrib/completion/git-completion.bash: _git_bisect ()
+ fi
+
+ case "$subcommand" in
+- bad|good|reset|skip|start)
++ bad|new|good|old|reset|skip|start)
+ __git_complete_refs
+ ;;
+ *)
+
## t/t9902-completion.sh ##
@@ t/t9902-completion.sh: test_expect_success 'git switch - with no options, complete local branches and u
EOF
@@ t/t9902-completion.sh: test_expect_success 'git switch - with no options, comple
+ EOF
+'
+
-+test_expect_success 'git bisect - complete options to start subcommand' '
-+ test_completion "git bisect start --" <<-\EOF
-+ --term-new Z
-+ --term-bad Z
-+ --term-old Z
-+ --term-good Z
-+ --no-checkout Z
-+ --first-parent Z
-+ EOF
-+'
-+
+test_expect_success 'setup for git-bisect tests requiring a repo' '
+ git init git-bisect &&
+ (
@@ t/t9902-completion.sh: test_expect_success 'git switch - with no options, comple
+ test_completion "git bisect " <<-\EOF
+ start Z
+ bad Z
-+ custom_new Z
-+ custom_old Z
+ new Z
+ good Z
+ old Z
-+ terms Z
+ skip Z
+ reset Z
+ visualize Z
@@ t/t9902-completion.sh: test_expect_success 'git switch - with no options, comple
+ EOF
+ )
+'
-+test_expect_success 'git-bisect - options to terms subcommand are candidates' '
-+ (
-+ cd git-bisect &&
-+ test_completion "git bisect terms --" <<-\EOF
-+ --term-bad Z
-+ --term-good Z
-+ --term-new Z
-+ --term-old Z
-+ EOF
-+ )
-+'
-+
-+test_expect_success 'git-bisect - git-log options to visualize subcommand are candidates' '
-+ (
-+ cd git-bisect &&
-+ # The completion used for git-log and here does not complete
-+ # every git-log option, so rather than hope to stay in sync
-+ # with exactly what it does we will just spot-test here.
-+ test_completion "git bisect visualize --sta" <<-\EOF &&
-+ --stat Z
-+ EOF
-+ test_completion "git bisect visualize --summar" <<-\EOF
-+ --summary Z
-+ EOF
-+ )
-+'
-+
-+test_expect_success 'git-bisect - view subcommand is not a candidate' '
-+ (
-+ cd git-bisect &&
-+ test_completion "git bisect vi" <<-\EOF
-+ visualize Z
-+ EOF
-+ )
-+'
-+
-+test_expect_success 'git-bisect - existing view subcommand is recognized and enables completion of git-log options' '
-+ (
-+ cd git-bisect &&
-+ # The completion used for git-log and here does not complete
-+ # every git-log option, so rather than hope to stay in sync
-+ # with exactly what it does we will just spot-test here.
-+ test_completion "git bisect view --sta" <<-\EOF &&
-+ --stat Z
-+ EOF
-+ test_completion "git bisect view --summar" <<-\EOF
-+ --summary Z
-+ EOF
-+ )
-+'
+
test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
test_completion "git checkout " <<-\EOF
2: 7eb8c842a3 ! 3: fab7159cf4 completion: bisect: complete custom terms and related options
@@ Commit message
these options or the new subcommands they define.
Add support for these options and the custom subcommands by checking for
- them if a bisection is in progress and adding them to the list of
- subcommands.
+ BISECT_TERMS and adding them to the list of subcommands. Add tests.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
@@ contrib/completion/git-completion.bash: _git_bisect ()
+
+ # If a bisection is in progress get the terms being used.
+ local term_bad term_good
-+ if [ -f "$__git_repo_path"/BISECT_START ]; then
++ if [ -f "$__git_repo_path"/BISECT_TERMS ]; then
+ term_bad=$(__git bisect terms --term-bad)
+ term_good=$(__git bisect terms --term-good)
+ fi
@@ contrib/completion/git-completion.bash: _git_bisect ()
__git_complete_refs
;;
*)
+
+ ## t/t9902-completion.sh ##
+@@ t/t9902-completion.sh: test_expect_success 'git-bisect - when bisecting all subcommands are candidates'
+ test_completion "git bisect " <<-\EOF
+ start Z
+ bad Z
++ custom_new Z
++ custom_old Z
+ new Z
+ good Z
+ old Z
++ terms Z
+ skip Z
+ reset Z
+ visualize Z
+@@ t/t9902-completion.sh: test_expect_success 'git-bisect - when bisecting all subcommands are candidates'
+ EOF
+ )
+ '
++test_expect_success 'git-bisect - options to terms subcommand are candidates' '
++ (
++ cd git-bisect &&
++ test_completion "git bisect terms --" <<-\EOF
++ --term-bad Z
++ --term-good Z
++ --term-new Z
++ --term-old Z
++ EOF
++ )
++'
++
+
+ test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
+ test_completion "git checkout " <<-\EOF
3: 5f5076bb93 < -: ---------- completion: bisect: complete missing --first-parent and --no-checkout options
4: c8ffa0e915 < -: ---------- completion: new function __git_complete_log_opts
5: 733613d1ed < -: ---------- completion: log: use __git_complete_log_opts
-: ---------- > 4: 73f3343b94 completion: bisect: complete missing --first-parent and --no-checkout options
-: ---------- > 5: a20846bbd3 completion: new function __git_complete_log_opts
6: 06f5973b3b ! 6: fe5545c9a3 completion: bisect: complete log opts for visualize subcommand
@@ Commit message
Make completion of porcelain git-log options and option arguments to the
visualize subcommand work by calling __git_complete_log_opts when the
start of an option to the subcommand is seen (visualize doesn't support
- any options besides the git-log options).
+ any options besides the git-log options). Add test.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
@@ contrib/completion/git-completion.bash: _git_bisect ()
bad|new|"$term_bad"|good|old|"$term_good"|reset|skip)
__git_complete_refs
;;
+
+ ## t/t9902-completion.sh ##
+@@ t/t9902-completion.sh: test_expect_success 'git-bisect - options to terms subcommand are candidates' '
+ )
+ '
+
++test_expect_success 'git-bisect - git-log options to visualize subcommand are candidates' '
++ (
++ cd git-bisect &&
++ # The completion used for git-log and here does not complete
++ # every git-log option, so rather than hope to stay in sync
++ # with exactly what it does we will just spot-test here.
++ test_completion "git bisect visualize --sta" <<-\EOF &&
++ --stat Z
++ EOF
++ test_completion "git bisect visualize --summar" <<-\EOF
++ --summary Z
++ EOF
++ )
++'
+
+ test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
+ test_completion "git checkout " <<-\EOF
7: 1dc9323f24 ! 7: c9102ac532 completion: bisect: recognize but do not complete view subcommand
@@ Commit message
completion for it.
Recognize but do not complete the view command by creating and using
- separate lists of completable_subcommands and all_subcommands.
+ separate lists of completable_subcommands and all_subcommands. Add
+ tests.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
@@ contrib/completion/git-completion.bash: _git_bisect ()
__git_complete_log_opts
return
;;
+
+ ## t/t9902-completion.sh ##
+@@ t/t9902-completion.sh: test_expect_success 'git-bisect - git-log options to visualize subcommand are ca
+ )
+ '
+
++test_expect_success 'git-bisect - view subcommand is not a candidate' '
++ (
++ cd git-bisect &&
++ test_completion "git bisect vi" <<-\EOF
++ visualize Z
++ EOF
++ )
++'
++
++test_expect_success 'git-bisect - existing view subcommand is recognized and enables completion of git-log options' '
++ (
++ cd git-bisect &&
++ # The completion used for git-log and here does not complete
++ # every git-log option, so rather than hope to stay in sync
++ # with exactly what it does we will just spot-test here.
++ test_completion "git bisect view --sta" <<-\EOF &&
++ --stat Z
++ EOF
++ test_completion "git bisect view --summar" <<-\EOF
++ --summary Z
++ EOF
++ )
++'
++
+ test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
+ test_completion "git checkout " <<-\EOF
+ HEAD Z
--
2.43.0
^ permalink raw reply [flat|nested] 58+ messages in thread
* [PATCH v5 1/7] completion: tests: always use 'master' for default initial branch name
2024-02-06 2:09 ` [PATCH v5 0/7] " Britton Leo Kerin
@ 2024-02-06 2:09 ` Britton Leo Kerin
2024-02-06 2:09 ` [PATCH v5 2/7] completion: bisect: complete bad, new, old, and help subcommands Britton Leo Kerin
` (7 subsequent siblings)
8 siblings, 0 replies; 58+ messages in thread
From: Britton Leo Kerin @ 2024-02-06 2:09 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
The default initial branch name can normally be configured using the
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME environment variable. However,
when testing e.g. <rev> completion it's convenient to know the
exact initial branch name that will be used.
To achieve that without too much trouble it is considered sufficient
to force the default initial branch name to 'master' for all of
t9902-completion.sh.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
t/t9902-completion.sh | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index aa9a614de3..a5d4e900a2 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -5,6 +5,11 @@
test_description='test bash completion'
+# Override environment and always use master for the default initial branch
+# name for these tests, so that rev completion candidates are as expected.
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
. ./lib-bash.sh
complete ()
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH v5 2/7] completion: bisect: complete bad, new, old, and help subcommands
2024-02-06 2:09 ` [PATCH v5 0/7] " Britton Leo Kerin
2024-02-06 2:09 ` [PATCH v5 1/7] completion: tests: always use 'master' for default initial branch name Britton Leo Kerin
@ 2024-02-06 2:09 ` Britton Leo Kerin
2024-02-06 7:40 ` Patrick Steinhardt
2024-02-06 2:09 ` [PATCH v5 3/7] completion: bisect: complete custom terms and related options Britton Leo Kerin
` (6 subsequent siblings)
8 siblings, 1 reply; 58+ messages in thread
From: Britton Leo Kerin @ 2024-02-06 2:09 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
The bad, new, old and help subcommands to git-bisect(1) are not
completed.
Add the bad, new, old, and help subcommands to the appropriate lists
such that the commands and their possible ref arguments are completed.
Add tests.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.c
---
contrib/completion/git-completion.bash | 4 +-
t/t9902-completion.sh | 71 ++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 2 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 185b47d802..06d0b156e7 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1449,7 +1449,7 @@ _git_bisect ()
{
__git_has_doubledash && return
- local subcommands="start bad good skip reset visualize replay log run"
+ local subcommands="start bad new good old skip reset visualize replay log run help"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__git_find_repo_path
@@ -1462,7 +1462,7 @@ _git_bisect ()
fi
case "$subcommand" in
- bad|good|reset|skip|start)
+ bad|new|good|old|reset|skip|start)
__git_complete_refs
;;
*)
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index a5d4e900a2..7388c892cf 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1264,6 +1264,77 @@ test_expect_success 'git switch - with no options, complete local branches and u
EOF
'
+test_expect_success 'git bisect - when not bisecting, complete only replay and start subcommands' '
+ test_completion "git bisect " <<-\EOF
+ replay Z
+ start Z
+ EOF
+'
+
+test_expect_success 'setup for git-bisect tests requiring a repo' '
+ git init git-bisect &&
+ (
+ cd git-bisect &&
+ echo "initial contents" >file &&
+ git add file &&
+ git commit -am "Initial commit" &&
+ git tag initial &&
+ echo "new line" >>file &&
+ git commit -am "First change" &&
+ echo "another new line" >>file &&
+ git commit -am "Second change" &&
+ git tag final
+ )
+'
+
+test_expect_success 'git bisect - start subcommand arguments before double-dash are completed as revs' '
+ (
+ cd git-bisect &&
+ test_completion "git bisect start " <<-\EOF
+ HEAD Z
+ final Z
+ initial Z
+ master Z
+ EOF
+ )
+'
+
+# Note that these arguments are <pathspec>s, which in practice the fallback
+# completion (not the git completion) later ends up completing as paths.
+test_expect_success 'git bisect - start subcommand arguments after double-dash are not completed' '
+ (
+ cd git-bisect &&
+ test_completion "git bisect start final initial -- " ""
+ )
+'
+
+test_expect_success 'setup for git-bisect tests requiring ongoing bisection' '
+ (
+ cd git-bisect &&
+ git bisect start --term-new=custom_new --term-old=custom_old final initial
+ )
+'
+
+test_expect_success 'git-bisect - when bisecting all subcommands are candidates' '
+ (
+ cd git-bisect &&
+ test_completion "git bisect " <<-\EOF
+ start Z
+ bad Z
+ new Z
+ good Z
+ old Z
+ skip Z
+ reset Z
+ visualize Z
+ replay Z
+ log Z
+ run Z
+ help Z
+ EOF
+ )
+'
+
test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
test_completion "git checkout " <<-\EOF
HEAD Z
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* Re: [PATCH v5 2/7] completion: bisect: complete bad, new, old, and help subcommands
2024-02-06 2:09 ` [PATCH v5 2/7] completion: bisect: complete bad, new, old, and help subcommands Britton Leo Kerin
@ 2024-02-06 7:40 ` Patrick Steinhardt
0 siblings, 0 replies; 58+ messages in thread
From: Patrick Steinhardt @ 2024-02-06 7:40 UTC (permalink / raw)
To: Britton Leo Kerin; +Cc: git, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 473 bytes --]
On Mon, Feb 05, 2024 at 05:09:25PM -0900, Britton Leo Kerin wrote:
> The bad, new, old and help subcommands to git-bisect(1) are not
> completed.
>
> Add the bad, new, old, and help subcommands to the appropriate lists
> such that the commands and their possible ref arguments are completed.
> Add tests.
>
> Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.c
Nit: the SOB has been truncated here. Other than that the patch looks
good to me.
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 58+ messages in thread
* [PATCH v5 3/7] completion: bisect: complete custom terms and related options
2024-02-06 2:09 ` [PATCH v5 0/7] " Britton Leo Kerin
2024-02-06 2:09 ` [PATCH v5 1/7] completion: tests: always use 'master' for default initial branch name Britton Leo Kerin
2024-02-06 2:09 ` [PATCH v5 2/7] completion: bisect: complete bad, new, old, and help subcommands Britton Leo Kerin
@ 2024-02-06 2:09 ` Britton Leo Kerin
2024-02-06 7:40 ` Patrick Steinhardt
2024-02-06 2:09 ` [PATCH v5 4/7] completion: bisect: complete missing --first-parent and --no-checkout options Britton Leo Kerin
` (5 subsequent siblings)
8 siblings, 1 reply; 58+ messages in thread
From: Britton Leo Kerin @ 2024-02-06 2:09 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
git bisect supports the use of custom terms via the --term-(new|bad) and
--term-(old|good) options, but the completion code doesn't know about
these options or the new subcommands they define.
Add support for these options and the custom subcommands by checking for
BISECT_TERMS and adding them to the list of subcommands. Add tests.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
contrib/completion/git-completion.bash | 32 ++++++++++++++++++++++++--
t/t9902-completion.sh | 15 ++++++++++++
2 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 06d0b156e7..6a3d9c7760 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1449,7 +1449,20 @@ _git_bisect ()
{
__git_has_doubledash && return
- local subcommands="start bad new good old skip reset visualize replay log run help"
+ __git_find_repo_path
+
+ # If a bisection is in progress get the terms being used.
+ local term_bad term_good
+ if [ -f "$__git_repo_path"/BISECT_TERMS ]; then
+ term_bad=$(__git bisect terms --term-bad)
+ term_good=$(__git bisect terms --term-good)
+ fi
+
+ # We will complete any custom terms, but still always complete the
+ # more usual bad/new/good/old because git bisect gives a good error
+ # message if these are given when not in use, and that's better than
+ # silent refusal to complete if the user is confused.
+ local subcommands="start bad new $term_bad good old $term_good terms skip reset visualize replay log run help"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__git_find_repo_path
@@ -1462,7 +1475,22 @@ _git_bisect ()
fi
case "$subcommand" in
- bad|new|good|old|reset|skip|start)
+ start)
+ case "$cur" in
+ --*)
+ __gitcomp "--term-new --term-bad --term-old --term-good"
+ return
+ ;;
+ *)
+ __git_complete_refs
+ ;;
+ esac
+ ;;
+ terms)
+ __gitcomp "--term-good --term-old --term-bad --term-new"
+ return
+ ;;
+ bad|new|"$term_bad"|good|old|"$term_good"|reset|skip)
__git_complete_refs
;;
*)
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 7388c892cf..409a5a49d5 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1321,9 +1321,12 @@ test_expect_success 'git-bisect - when bisecting all subcommands are candidates'
test_completion "git bisect " <<-\EOF
start Z
bad Z
+ custom_new Z
+ custom_old Z
new Z
good Z
old Z
+ terms Z
skip Z
reset Z
visualize Z
@@ -1334,6 +1337,18 @@ test_expect_success 'git-bisect - when bisecting all subcommands are candidates'
EOF
)
'
+test_expect_success 'git-bisect - options to terms subcommand are candidates' '
+ (
+ cd git-bisect &&
+ test_completion "git bisect terms --" <<-\EOF
+ --term-bad Z
+ --term-good Z
+ --term-new Z
+ --term-old Z
+ EOF
+ )
+'
+
test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
test_completion "git checkout " <<-\EOF
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* Re: [PATCH v5 3/7] completion: bisect: complete custom terms and related options
2024-02-06 2:09 ` [PATCH v5 3/7] completion: bisect: complete custom terms and related options Britton Leo Kerin
@ 2024-02-06 7:40 ` Patrick Steinhardt
0 siblings, 0 replies; 58+ messages in thread
From: Patrick Steinhardt @ 2024-02-06 7:40 UTC (permalink / raw)
To: Britton Leo Kerin; +Cc: git, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 3577 bytes --]
On Mon, Feb 05, 2024 at 05:09:26PM -0900, Britton Leo Kerin wrote:
> git bisect supports the use of custom terms via the --term-(new|bad) and
> --term-(old|good) options, but the completion code doesn't know about
> these options or the new subcommands they define.
>
> Add support for these options and the custom subcommands by checking for
> BISECT_TERMS and adding them to the list of subcommands. Add tests.
>
> Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
> ---
> contrib/completion/git-completion.bash | 32 ++++++++++++++++++++++++--
> t/t9902-completion.sh | 15 ++++++++++++
> 2 files changed, 45 insertions(+), 2 deletions(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 06d0b156e7..6a3d9c7760 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1449,7 +1449,20 @@ _git_bisect ()
> {
> __git_has_doubledash && return
>
> - local subcommands="start bad new good old skip reset visualize replay log run help"
> + __git_find_repo_path
> +
> + # If a bisection is in progress get the terms being used.
> + local term_bad term_good
> + if [ -f "$__git_repo_path"/BISECT_TERMS ]; then
> + term_bad=$(__git bisect terms --term-bad)
> + term_good=$(__git bisect terms --term-good)
> + fi
> +
> + # We will complete any custom terms, but still always complete the
> + # more usual bad/new/good/old because git bisect gives a good error
> + # message if these are given when not in use, and that's better than
> + # silent refusal to complete if the user is confused.
> + local subcommands="start bad new $term_bad good old $term_good terms skip reset visualize replay log run help"
> local subcommand="$(__git_find_on_cmdline "$subcommands")"
> if [ -z "$subcommand" ]; then
> __git_find_repo_path
> @@ -1462,7 +1475,22 @@ _git_bisect ()
> fi
>
> case "$subcommand" in
> - bad|new|good|old|reset|skip|start)
> + start)
> + case "$cur" in
> + --*)
> + __gitcomp "--term-new --term-bad --term-old --term-good"
> + return
> + ;;
> + *)
> + __git_complete_refs
> + ;;
> + esac
> + ;;
> + terms)
> + __gitcomp "--term-good --term-old --term-bad --term-new"
> + return
> + ;;
> + bad|new|"$term_bad"|good|old|"$term_good"|reset|skip)
> __git_complete_refs
> ;;
> *)
> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
> index 7388c892cf..409a5a49d5 100755
> --- a/t/t9902-completion.sh
> +++ b/t/t9902-completion.sh
> @@ -1321,9 +1321,12 @@ test_expect_success 'git-bisect - when bisecting all subcommands are candidates'
> test_completion "git bisect " <<-\EOF
> start Z
> bad Z
> + custom_new Z
> + custom_old Z
> new Z
> good Z
> old Z
> + terms Z
> skip Z
> reset Z
> visualize Z
> @@ -1334,6 +1337,18 @@ test_expect_success 'git-bisect - when bisecting all subcommands are candidates'
> EOF
> )
> '
Nit: missing a newline between the tests...
> +test_expect_success 'git-bisect - options to terms subcommand are candidates' '
> + (
> + cd git-bisect &&
> + test_completion "git bisect terms --" <<-\EOF
> + --term-bad Z
> + --term-good Z
> + --term-new Z
> + --term-old Z
> + EOF
> + )
> +'
> +
>
... wheeras here we have a newline too many now.
Patrick
> test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
> test_completion "git checkout " <<-\EOF
> --
> 2.43.0
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 58+ messages in thread
* [PATCH v5 4/7] completion: bisect: complete missing --first-parent and --no-checkout options
2024-02-06 2:09 ` [PATCH v5 0/7] " Britton Leo Kerin
` (2 preceding siblings ...)
2024-02-06 2:09 ` [PATCH v5 3/7] completion: bisect: complete custom terms and related options Britton Leo Kerin
@ 2024-02-06 2:09 ` Britton Leo Kerin
2024-02-06 2:09 ` [PATCH v5 5/7] completion: new function __git_complete_log_opts Britton Leo Kerin
` (4 subsequent siblings)
8 siblings, 0 replies; 58+ messages in thread
From: Britton Leo Kerin @ 2024-02-06 2:09 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
The --first-parent and --no-checkout options to the start subcommand of
git-bisect(1) are not completed.
Enable completion of the --first-parent and --no-checkout options to the
start subcommand. Add test.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
contrib/completion/git-completion.bash | 2 +-
t/t9902-completion.sh | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 6a3d9c7760..57c6e09968 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1478,7 +1478,7 @@ _git_bisect ()
start)
case "$cur" in
--*)
- __gitcomp "--term-new --term-bad --term-old --term-good"
+ __gitcomp "--first-parent --no-checkout --term-new --term-bad --term-old --term-good"
return
;;
*)
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 409a5a49d5..f4d3aa67e3 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1271,6 +1271,17 @@ test_expect_success 'git bisect - when not bisecting, complete only replay and s
EOF
'
+test_expect_success 'git bisect - complete options to start subcommand' '
+ test_completion "git bisect start --" <<-\EOF
+ --term-new Z
+ --term-bad Z
+ --term-old Z
+ --term-good Z
+ --no-checkout Z
+ --first-parent Z
+ EOF
+'
+
test_expect_success 'setup for git-bisect tests requiring a repo' '
git init git-bisect &&
(
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH v5 5/7] completion: new function __git_complete_log_opts
2024-02-06 2:09 ` [PATCH v5 0/7] " Britton Leo Kerin
` (3 preceding siblings ...)
2024-02-06 2:09 ` [PATCH v5 4/7] completion: bisect: complete missing --first-parent and --no-checkout options Britton Leo Kerin
@ 2024-02-06 2:09 ` Britton Leo Kerin
2024-02-06 7:40 ` Patrick Steinhardt
2024-02-06 2:09 ` [PATCH v5 6/7] completion: bisect: complete log opts for visualize subcommand Britton Leo Kerin
` (3 subsequent siblings)
8 siblings, 1 reply; 58+ messages in thread
From: Britton Leo Kerin @ 2024-02-06 2:09 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
The options accepted by git-log are also accepted by at least one other
command (git-bisect). Factor the common option completion code into
a new function and use it from _git_log.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
contrib/completion/git-completion.bash | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 57c6e09968..8c3b1b8e96 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2089,10 +2089,12 @@ __git_diff_merges_opts="off none on first-parent 1 separate m combined c dense-c
__git_log_pretty_formats="oneline short medium full fuller reference email raw format: tformat: mboxrd"
__git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default human raw unix auto: format:"
-_git_log ()
+# Complete porcelain (i.e. not git-rev-list) options and at least some
+# option arguments accepted by git-log. Note that this same set of options
+# are also accepted by some other git commands besides git-log.
+__git_complete_log_opts ()
{
- __git_has_doubledash && return
- __git_find_repo_path
+ COMPREPLY=""
local merge=""
if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
@@ -2186,6 +2188,16 @@ _git_log ()
return
;;
esac
+}
+
+_git_log ()
+{
+ __git_has_doubledash && return
+ __git_find_repo_path
+
+ __git_complete_log_opts
+ [ -z "$COMPREPLY" ] || return
+
__git_complete_revlist
}
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* Re: [PATCH v5 5/7] completion: new function __git_complete_log_opts
2024-02-06 2:09 ` [PATCH v5 5/7] completion: new function __git_complete_log_opts Britton Leo Kerin
@ 2024-02-06 7:40 ` Patrick Steinhardt
0 siblings, 0 replies; 58+ messages in thread
From: Patrick Steinhardt @ 2024-02-06 7:40 UTC (permalink / raw)
To: Britton Leo Kerin; +Cc: git, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 1999 bytes --]
On Mon, Feb 05, 2024 at 05:09:28PM -0900, Britton Leo Kerin wrote:
> The options accepted by git-log are also accepted by at least one other
> command (git-bisect). Factor the common option completion code into
> a new function and use it from _git_log.
>
> Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
> ---
> contrib/completion/git-completion.bash | 18 +++++++++++++++---
> 1 file changed, 15 insertions(+), 3 deletions(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 57c6e09968..8c3b1b8e96 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -2089,10 +2089,12 @@ __git_diff_merges_opts="off none on first-parent 1 separate m combined c dense-c
> __git_log_pretty_formats="oneline short medium full fuller reference email raw format: tformat: mboxrd"
> __git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default human raw unix auto: format:"
>
> -_git_log ()
> +# Complete porcelain (i.e. not git-rev-list) options and at least some
> +# option arguments accepted by git-log. Note that this same set of options
> +# are also accepted by some other git commands besides git-log.
> +__git_complete_log_opts ()
> {
> - __git_has_doubledash && return
> - __git_find_repo_path
> + COMPREPLY=""
Nit: this is indented with spaces instead of tabs.
It would also be nice to mention in the commit message why we empty
COMPREPLY here. It didn't happen before either, so this is essentially
not a no-op conversion.
Patrick
>
> local merge=""
> if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
> @@ -2186,6 +2188,16 @@ _git_log ()
> return
> ;;
> esac
> +}
> +
> +_git_log ()
> +{
> + __git_has_doubledash && return
> + __git_find_repo_path
> +
> + __git_complete_log_opts
> + [ -z "$COMPREPLY" ] || return
> +
> __git_complete_revlist
> }
>
> --
> 2.43.0
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 58+ messages in thread
* [PATCH v5 6/7] completion: bisect: complete log opts for visualize subcommand
2024-02-06 2:09 ` [PATCH v5 0/7] " Britton Leo Kerin
` (4 preceding siblings ...)
2024-02-06 2:09 ` [PATCH v5 5/7] completion: new function __git_complete_log_opts Britton Leo Kerin
@ 2024-02-06 2:09 ` Britton Leo Kerin
2024-02-06 2:09 ` [PATCH v5 7/7] completion: bisect: recognize but do not complete view subcommand Britton Leo Kerin
` (2 subsequent siblings)
8 siblings, 0 replies; 58+ messages in thread
From: Britton Leo Kerin @ 2024-02-06 2:09 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
Arguments passed to the "visualize" subcommand of git-bisect(1) get
forwarded to git-log(1). It thus supports the same options as git-log(1)
would, but our Bash completion script does not know to handle this.
Make completion of porcelain git-log options and option arguments to the
visualize subcommand work by calling __git_complete_log_opts when the
start of an option to the subcommand is seen (visualize doesn't support
any options besides the git-log options). Add test.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
contrib/completion/git-completion.bash | 4 ++++
t/t9902-completion.sh | 14 ++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 8c3b1b8e96..b4cd94182e 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1490,6 +1490,10 @@ _git_bisect ()
__gitcomp "--term-good --term-old --term-bad --term-new"
return
;;
+ visualize)
+ __git_complete_log_opts
+ return
+ ;;
bad|new|"$term_bad"|good|old|"$term_good"|reset|skip)
__git_complete_refs
;;
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index f4d3aa67e3..74132699b1 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1360,6 +1360,20 @@ test_expect_success 'git-bisect - options to terms subcommand are candidates' '
)
'
+test_expect_success 'git-bisect - git-log options to visualize subcommand are candidates' '
+ (
+ cd git-bisect &&
+ # The completion used for git-log and here does not complete
+ # every git-log option, so rather than hope to stay in sync
+ # with exactly what it does we will just spot-test here.
+ test_completion "git bisect visualize --sta" <<-\EOF &&
+ --stat Z
+ EOF
+ test_completion "git bisect visualize --summar" <<-\EOF
+ --summary Z
+ EOF
+ )
+'
test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
test_completion "git checkout " <<-\EOF
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH v5 7/7] completion: bisect: recognize but do not complete view subcommand
2024-02-06 2:09 ` [PATCH v5 0/7] " Britton Leo Kerin
` (5 preceding siblings ...)
2024-02-06 2:09 ` [PATCH v5 6/7] completion: bisect: complete log opts for visualize subcommand Britton Leo Kerin
@ 2024-02-06 2:09 ` Britton Leo Kerin
2024-02-06 7:40 ` [PATCH v5 0/7] completion: improvements for git-bisect Patrick Steinhardt
2024-02-06 21:50 ` [PATCH v6 " Britton Leo Kerin
8 siblings, 0 replies; 58+ messages in thread
From: Britton Leo Kerin @ 2024-02-06 2:09 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
The "view" alias for the visualize subcommand is neither completed nor
recognized. It's undesirable to complete it because it's first letters
are the same as for visualize, making completion less rather than more
efficient without adding much in the way of interface discovery.
However, it needs to be recognized in order to enable log option
completion for it.
Recognize but do not complete the view command by creating and using
separate lists of completable_subcommands and all_subcommands. Add
tests.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
contrib/completion/git-completion.bash | 15 +++++++++++----
t/t9902-completion.sh | 24 ++++++++++++++++++++++++
2 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index b4cd94182e..b3d5468c15 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1462,12 +1462,19 @@ _git_bisect ()
# more usual bad/new/good/old because git bisect gives a good error
# message if these are given when not in use, and that's better than
# silent refusal to complete if the user is confused.
- local subcommands="start bad new $term_bad good old $term_good terms skip reset visualize replay log run help"
- local subcommand="$(__git_find_on_cmdline "$subcommands")"
+ #
+ # We want to recognize 'view' but not complete it, because it overlaps
+ # with 'visualize' too much and is just an alias for it.
+ #
+ local completable_subcommands="start bad new $term_bad good old $term_good terms skip reset visualize replay log run help"
+ local all_subcommands="$completable_subcommands view"
+
+ local subcommand="$(__git_find_on_cmdline "$all_subcommands")"
+
if [ -z "$subcommand" ]; then
__git_find_repo_path
if [ -f "$__git_repo_path"/BISECT_START ]; then
- __gitcomp "$subcommands"
+ __gitcomp "$completable_subcommands"
else
__gitcomp "replay start"
fi
@@ -1490,7 +1497,7 @@ _git_bisect ()
__gitcomp "--term-good --term-old --term-bad --term-new"
return
;;
- visualize)
+ visualize|view)
__git_complete_log_opts
return
;;
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 74132699b1..6a6019b0a8 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1375,6 +1375,30 @@ test_expect_success 'git-bisect - git-log options to visualize subcommand are ca
)
'
+test_expect_success 'git-bisect - view subcommand is not a candidate' '
+ (
+ cd git-bisect &&
+ test_completion "git bisect vi" <<-\EOF
+ visualize Z
+ EOF
+ )
+'
+
+test_expect_success 'git-bisect - existing view subcommand is recognized and enables completion of git-log options' '
+ (
+ cd git-bisect &&
+ # The completion used for git-log and here does not complete
+ # every git-log option, so rather than hope to stay in sync
+ # with exactly what it does we will just spot-test here.
+ test_completion "git bisect view --sta" <<-\EOF &&
+ --stat Z
+ EOF
+ test_completion "git bisect view --summar" <<-\EOF
+ --summary Z
+ EOF
+ )
+'
+
test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
test_completion "git checkout " <<-\EOF
HEAD Z
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* Re: [PATCH v5 0/7] completion: improvements for git-bisect
2024-02-06 2:09 ` [PATCH v5 0/7] " Britton Leo Kerin
` (6 preceding siblings ...)
2024-02-06 2:09 ` [PATCH v5 7/7] completion: bisect: recognize but do not complete view subcommand Britton Leo Kerin
@ 2024-02-06 7:40 ` Patrick Steinhardt
2024-02-06 21:50 ` [PATCH v6 " Britton Leo Kerin
8 siblings, 0 replies; 58+ messages in thread
From: Patrick Steinhardt @ 2024-02-06 7:40 UTC (permalink / raw)
To: Britton Leo Kerin; +Cc: git, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 990 bytes --]
On Mon, Feb 05, 2024 at 05:09:23PM -0900, Britton Leo Kerin wrote:
> Relative to v4 this make the following actual changes:
>
> * fixes GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME to 'master' for all of
> t9902-completion.sh as suggested by Junio. This change affects all
> of t9902-completion.sh so I've put it by itself in it's own commit.
>
> * uses BISECT_TERMS to avoid pointless processes as suggested by Patrick.
>
> The commits are also refactored as follows:
>
> * squashes the introduction of __git_complete_log_opts in with it's
> first use a suggested by Patrick.
>
> * spreads tests across commits as suggest by Patrick.
>
> Thanks for the reviews.
This version looks great to me, thanks! I have a last set of nits to
bring this over the finish line (at least from my perspective). Each one
of them on its own wouldn't be worth addressing, but combined I think it
does make sense to send out a new version to address them.
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 58+ messages in thread
* [PATCH v6 0/7] completion: improvements for git-bisect
2024-02-06 2:09 ` [PATCH v5 0/7] " Britton Leo Kerin
` (7 preceding siblings ...)
2024-02-06 7:40 ` [PATCH v5 0/7] completion: improvements for git-bisect Patrick Steinhardt
@ 2024-02-06 21:50 ` Britton Leo Kerin
2024-02-06 21:50 ` [PATCH v6 1/7] completion: tests: always use 'master' for default initial branch name Britton Leo Kerin
` (7 more replies)
8 siblings, 8 replies; 58+ messages in thread
From: Britton Leo Kerin @ 2024-02-06 21:50 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
Relative to v5 this makes the following actual changes:
* Treat COMPREPLY as an array on assignment and test, rather than
relying on the bash mechanism of implicitly acting on the first
element of the array.
* Whitespace fixes.
The commit message about __git_complete_log_opts has also been changed
to indicate that COMPREPLY is emptied and why, and a broken
Signed-off-by line fixed.
Britton Leo Kerin (7):
completion: tests: always use 'master' for default initial branch name
completion: bisect: complete bad, new, old, and help subcommands
completion: bisect: complete custom terms and related options
completion: bisect: complete missing --first-parent and --no-checkout
options
completion: new function __git_complete_log_opts
completion: bisect: complete log opts for visualize subcommand
completion: bisect: recognize but do not complete view subcommand
contrib/completion/git-completion.bash | 65 ++++++++++--
t/t9902-completion.sh | 141 +++++++++++++++++++++++++
2 files changed, 199 insertions(+), 7 deletions(-)
Range-diff against v5:
1: 71b73de914 = 1: 71b73de914 completion: tests: always use 'master' for default initial branch name
2: 3a478a7a08 ! 2: 7bc45bfc13 completion: bisect: complete bad, new, old, and help subcommands
@@ Commit message
such that the commands and their possible ref arguments are completed.
Add tests.
- Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.c
+ Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
## contrib/completion/git-completion.bash ##
@@ contrib/completion/git-completion.bash: _git_bisect ()
3: fab7159cf4 ! 3: be925327d3 completion: bisect: complete custom terms and related options
@@ t/t9902-completion.sh: test_expect_success 'git-bisect - when bisecting all subc
reset Z
visualize Z
@@ t/t9902-completion.sh: test_expect_success 'git-bisect - when bisecting all subcommands are candidates'
- EOF
)
'
+
+test_expect_success 'git-bisect - options to terms subcommand are candidates' '
+ (
+ cd git-bisect &&
@@ t/t9902-completion.sh: test_expect_success 'git-bisect - when bisecting all subc
+ )
+'
+
-
test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
test_completion "git checkout " <<-\EOF
+ HEAD Z
4: 73f3343b94 = 4: c3141921e5 completion: bisect: complete missing --first-parent and --no-checkout options
5: a20846bbd3 ! 5: 092bfba6b1 completion: new function __git_complete_log_opts
@@ Commit message
completion: new function __git_complete_log_opts
The options accepted by git-log are also accepted by at least one other
- command (git-bisect). Factor the common option completion code into
- a new function and use it from _git_log.
+ command (git-bisect). Factor the common option completion code into a
+ new function and use it from _git_log. The new function leaves
+ COMPREPLY empty if no option candidates are found, so that callers can
+ safely check it to determine if completion for other arguments should be
+ attempted.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
@@ contrib/completion/git-completion.bash: __git_diff_merges_opts="off none on firs
{
- __git_has_doubledash && return
- __git_find_repo_path
-+ COMPREPLY=""
++ COMPREPLY=()
local merge=""
if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
@@ contrib/completion/git-completion.bash: _git_log ()
+ __git_find_repo_path
+
+ __git_complete_log_opts
-+ [ -z "$COMPREPLY" ] || return
++ [ ${#COMPREPLY[@]} -eq 0 ] || return
+
__git_complete_revlist
}
6: fe5545c9a3 ! 6: 9afd4d4e0f completion: bisect: complete log opts for visualize subcommand
@@ t/t9902-completion.sh: test_expect_success 'git-bisect - options to terms subcom
+ EOF
+ )
+'
-
++
test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
test_completion "git checkout " <<-\EOF
+ HEAD Z
7: c9102ac532 = 7: dba916b31c completion: bisect: recognize but do not complete view subcommand
--
2.43.0
^ permalink raw reply [flat|nested] 58+ messages in thread
* [PATCH v6 1/7] completion: tests: always use 'master' for default initial branch name
2024-02-06 21:50 ` [PATCH v6 " Britton Leo Kerin
@ 2024-02-06 21:50 ` Britton Leo Kerin
2024-02-06 21:50 ` [PATCH v6 2/7] completion: bisect: complete bad, new, old, and help subcommands Britton Leo Kerin
` (6 subsequent siblings)
7 siblings, 0 replies; 58+ messages in thread
From: Britton Leo Kerin @ 2024-02-06 21:50 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
The default initial branch name can normally be configured using the
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME environment variable. However,
when testing e.g. <rev> completion it's convenient to know the
exact initial branch name that will be used.
To achieve that without too much trouble it is considered sufficient
to force the default initial branch name to 'master' for all of
t9902-completion.sh.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
t/t9902-completion.sh | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index aa9a614de3..a5d4e900a2 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -5,6 +5,11 @@
test_description='test bash completion'
+# Override environment and always use master for the default initial branch
+# name for these tests, so that rev completion candidates are as expected.
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
. ./lib-bash.sh
complete ()
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH v6 2/7] completion: bisect: complete bad, new, old, and help subcommands
2024-02-06 21:50 ` [PATCH v6 " Britton Leo Kerin
2024-02-06 21:50 ` [PATCH v6 1/7] completion: tests: always use 'master' for default initial branch name Britton Leo Kerin
@ 2024-02-06 21:50 ` Britton Leo Kerin
2024-02-06 21:50 ` [PATCH v6 3/7] completion: bisect: complete custom terms and related options Britton Leo Kerin
` (5 subsequent siblings)
7 siblings, 0 replies; 58+ messages in thread
From: Britton Leo Kerin @ 2024-02-06 21:50 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
The bad, new, old and help subcommands to git-bisect(1) are not
completed.
Add the bad, new, old, and help subcommands to the appropriate lists
such that the commands and their possible ref arguments are completed.
Add tests.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
contrib/completion/git-completion.bash | 4 +-
t/t9902-completion.sh | 71 ++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 2 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 185b47d802..06d0b156e7 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1449,7 +1449,7 @@ _git_bisect ()
{
__git_has_doubledash && return
- local subcommands="start bad good skip reset visualize replay log run"
+ local subcommands="start bad new good old skip reset visualize replay log run help"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__git_find_repo_path
@@ -1462,7 +1462,7 @@ _git_bisect ()
fi
case "$subcommand" in
- bad|good|reset|skip|start)
+ bad|new|good|old|reset|skip|start)
__git_complete_refs
;;
*)
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index a5d4e900a2..7388c892cf 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1264,6 +1264,77 @@ test_expect_success 'git switch - with no options, complete local branches and u
EOF
'
+test_expect_success 'git bisect - when not bisecting, complete only replay and start subcommands' '
+ test_completion "git bisect " <<-\EOF
+ replay Z
+ start Z
+ EOF
+'
+
+test_expect_success 'setup for git-bisect tests requiring a repo' '
+ git init git-bisect &&
+ (
+ cd git-bisect &&
+ echo "initial contents" >file &&
+ git add file &&
+ git commit -am "Initial commit" &&
+ git tag initial &&
+ echo "new line" >>file &&
+ git commit -am "First change" &&
+ echo "another new line" >>file &&
+ git commit -am "Second change" &&
+ git tag final
+ )
+'
+
+test_expect_success 'git bisect - start subcommand arguments before double-dash are completed as revs' '
+ (
+ cd git-bisect &&
+ test_completion "git bisect start " <<-\EOF
+ HEAD Z
+ final Z
+ initial Z
+ master Z
+ EOF
+ )
+'
+
+# Note that these arguments are <pathspec>s, which in practice the fallback
+# completion (not the git completion) later ends up completing as paths.
+test_expect_success 'git bisect - start subcommand arguments after double-dash are not completed' '
+ (
+ cd git-bisect &&
+ test_completion "git bisect start final initial -- " ""
+ )
+'
+
+test_expect_success 'setup for git-bisect tests requiring ongoing bisection' '
+ (
+ cd git-bisect &&
+ git bisect start --term-new=custom_new --term-old=custom_old final initial
+ )
+'
+
+test_expect_success 'git-bisect - when bisecting all subcommands are candidates' '
+ (
+ cd git-bisect &&
+ test_completion "git bisect " <<-\EOF
+ start Z
+ bad Z
+ new Z
+ good Z
+ old Z
+ skip Z
+ reset Z
+ visualize Z
+ replay Z
+ log Z
+ run Z
+ help Z
+ EOF
+ )
+'
+
test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
test_completion "git checkout " <<-\EOF
HEAD Z
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH v6 3/7] completion: bisect: complete custom terms and related options
2024-02-06 21:50 ` [PATCH v6 " Britton Leo Kerin
2024-02-06 21:50 ` [PATCH v6 1/7] completion: tests: always use 'master' for default initial branch name Britton Leo Kerin
2024-02-06 21:50 ` [PATCH v6 2/7] completion: bisect: complete bad, new, old, and help subcommands Britton Leo Kerin
@ 2024-02-06 21:50 ` Britton Leo Kerin
2024-02-06 21:50 ` [PATCH v6 4/7] completion: bisect: complete missing --first-parent and --no-checkout options Britton Leo Kerin
` (4 subsequent siblings)
7 siblings, 0 replies; 58+ messages in thread
From: Britton Leo Kerin @ 2024-02-06 21:50 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
git bisect supports the use of custom terms via the --term-(new|bad) and
--term-(old|good) options, but the completion code doesn't know about
these options or the new subcommands they define.
Add support for these options and the custom subcommands by checking for
BISECT_TERMS and adding them to the list of subcommands. Add tests.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
contrib/completion/git-completion.bash | 32 ++++++++++++++++++++++++--
t/t9902-completion.sh | 15 ++++++++++++
2 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 06d0b156e7..6a3d9c7760 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1449,7 +1449,20 @@ _git_bisect ()
{
__git_has_doubledash && return
- local subcommands="start bad new good old skip reset visualize replay log run help"
+ __git_find_repo_path
+
+ # If a bisection is in progress get the terms being used.
+ local term_bad term_good
+ if [ -f "$__git_repo_path"/BISECT_TERMS ]; then
+ term_bad=$(__git bisect terms --term-bad)
+ term_good=$(__git bisect terms --term-good)
+ fi
+
+ # We will complete any custom terms, but still always complete the
+ # more usual bad/new/good/old because git bisect gives a good error
+ # message if these are given when not in use, and that's better than
+ # silent refusal to complete if the user is confused.
+ local subcommands="start bad new $term_bad good old $term_good terms skip reset visualize replay log run help"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__git_find_repo_path
@@ -1462,7 +1475,22 @@ _git_bisect ()
fi
case "$subcommand" in
- bad|new|good|old|reset|skip|start)
+ start)
+ case "$cur" in
+ --*)
+ __gitcomp "--term-new --term-bad --term-old --term-good"
+ return
+ ;;
+ *)
+ __git_complete_refs
+ ;;
+ esac
+ ;;
+ terms)
+ __gitcomp "--term-good --term-old --term-bad --term-new"
+ return
+ ;;
+ bad|new|"$term_bad"|good|old|"$term_good"|reset|skip)
__git_complete_refs
;;
*)
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 7388c892cf..304903b1a7 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1321,9 +1321,12 @@ test_expect_success 'git-bisect - when bisecting all subcommands are candidates'
test_completion "git bisect " <<-\EOF
start Z
bad Z
+ custom_new Z
+ custom_old Z
new Z
good Z
old Z
+ terms Z
skip Z
reset Z
visualize Z
@@ -1335,6 +1338,18 @@ test_expect_success 'git-bisect - when bisecting all subcommands are candidates'
)
'
+test_expect_success 'git-bisect - options to terms subcommand are candidates' '
+ (
+ cd git-bisect &&
+ test_completion "git bisect terms --" <<-\EOF
+ --term-bad Z
+ --term-good Z
+ --term-new Z
+ --term-old Z
+ EOF
+ )
+'
+
test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
test_completion "git checkout " <<-\EOF
HEAD Z
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH v6 4/7] completion: bisect: complete missing --first-parent and --no-checkout options
2024-02-06 21:50 ` [PATCH v6 " Britton Leo Kerin
` (2 preceding siblings ...)
2024-02-06 21:50 ` [PATCH v6 3/7] completion: bisect: complete custom terms and related options Britton Leo Kerin
@ 2024-02-06 21:50 ` Britton Leo Kerin
2024-02-06 21:50 ` [PATCH v6 5/7] completion: new function __git_complete_log_opts Britton Leo Kerin
` (3 subsequent siblings)
7 siblings, 0 replies; 58+ messages in thread
From: Britton Leo Kerin @ 2024-02-06 21:50 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
The --first-parent and --no-checkout options to the start subcommand of
git-bisect(1) are not completed.
Enable completion of the --first-parent and --no-checkout options to the
start subcommand. Add test.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
contrib/completion/git-completion.bash | 2 +-
t/t9902-completion.sh | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 6a3d9c7760..57c6e09968 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1478,7 +1478,7 @@ _git_bisect ()
start)
case "$cur" in
--*)
- __gitcomp "--term-new --term-bad --term-old --term-good"
+ __gitcomp "--first-parent --no-checkout --term-new --term-bad --term-old --term-good"
return
;;
*)
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 304903b1a7..8fcd1cfa7e 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1271,6 +1271,17 @@ test_expect_success 'git bisect - when not bisecting, complete only replay and s
EOF
'
+test_expect_success 'git bisect - complete options to start subcommand' '
+ test_completion "git bisect start --" <<-\EOF
+ --term-new Z
+ --term-bad Z
+ --term-old Z
+ --term-good Z
+ --no-checkout Z
+ --first-parent Z
+ EOF
+'
+
test_expect_success 'setup for git-bisect tests requiring a repo' '
git init git-bisect &&
(
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH v6 5/7] completion: new function __git_complete_log_opts
2024-02-06 21:50 ` [PATCH v6 " Britton Leo Kerin
` (3 preceding siblings ...)
2024-02-06 21:50 ` [PATCH v6 4/7] completion: bisect: complete missing --first-parent and --no-checkout options Britton Leo Kerin
@ 2024-02-06 21:50 ` Britton Leo Kerin
2024-02-06 21:50 ` [PATCH v6 6/7] completion: bisect: complete log opts for visualize subcommand Britton Leo Kerin
` (2 subsequent siblings)
7 siblings, 0 replies; 58+ messages in thread
From: Britton Leo Kerin @ 2024-02-06 21:50 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
The options accepted by git-log are also accepted by at least one other
command (git-bisect). Factor the common option completion code into a
new function and use it from _git_log. The new function leaves
COMPREPLY empty if no option candidates are found, so that callers can
safely check it to determine if completion for other arguments should be
attempted.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
contrib/completion/git-completion.bash | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 57c6e09968..b9ebd5e409 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2089,10 +2089,12 @@ __git_diff_merges_opts="off none on first-parent 1 separate m combined c dense-c
__git_log_pretty_formats="oneline short medium full fuller reference email raw format: tformat: mboxrd"
__git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default human raw unix auto: format:"
-_git_log ()
+# Complete porcelain (i.e. not git-rev-list) options and at least some
+# option arguments accepted by git-log. Note that this same set of options
+# are also accepted by some other git commands besides git-log.
+__git_complete_log_opts ()
{
- __git_has_doubledash && return
- __git_find_repo_path
+ COMPREPLY=()
local merge=""
if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
@@ -2186,6 +2188,16 @@ _git_log ()
return
;;
esac
+}
+
+_git_log ()
+{
+ __git_has_doubledash && return
+ __git_find_repo_path
+
+ __git_complete_log_opts
+ [ ${#COMPREPLY[@]} -eq 0 ] || return
+
__git_complete_revlist
}
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH v6 6/7] completion: bisect: complete log opts for visualize subcommand
2024-02-06 21:50 ` [PATCH v6 " Britton Leo Kerin
` (4 preceding siblings ...)
2024-02-06 21:50 ` [PATCH v6 5/7] completion: new function __git_complete_log_opts Britton Leo Kerin
@ 2024-02-06 21:50 ` Britton Leo Kerin
2024-02-06 21:50 ` [PATCH v6 7/7] completion: bisect: recognize but do not complete view subcommand Britton Leo Kerin
2024-02-06 22:58 ` [PATCH v6 0/7] completion: improvements for git-bisect Junio C Hamano
7 siblings, 0 replies; 58+ messages in thread
From: Britton Leo Kerin @ 2024-02-06 21:50 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
Arguments passed to the "visualize" subcommand of git-bisect(1) get
forwarded to git-log(1). It thus supports the same options as git-log(1)
would, but our Bash completion script does not know to handle this.
Make completion of porcelain git-log options and option arguments to the
visualize subcommand work by calling __git_complete_log_opts when the
start of an option to the subcommand is seen (visualize doesn't support
any options besides the git-log options). Add test.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
contrib/completion/git-completion.bash | 4 ++++
t/t9902-completion.sh | 15 +++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index b9ebd5e409..5337ae4ce2 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1490,6 +1490,10 @@ _git_bisect ()
__gitcomp "--term-good --term-old --term-bad --term-new"
return
;;
+ visualize)
+ __git_complete_log_opts
+ return
+ ;;
bad|new|"$term_bad"|good|old|"$term_good"|reset|skip)
__git_complete_refs
;;
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 8fcd1cfa7e..b989388e7e 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1361,6 +1361,21 @@ test_expect_success 'git-bisect - options to terms subcommand are candidates' '
)
'
+test_expect_success 'git-bisect - git-log options to visualize subcommand are candidates' '
+ (
+ cd git-bisect &&
+ # The completion used for git-log and here does not complete
+ # every git-log option, so rather than hope to stay in sync
+ # with exactly what it does we will just spot-test here.
+ test_completion "git bisect visualize --sta" <<-\EOF &&
+ --stat Z
+ EOF
+ test_completion "git bisect visualize --summar" <<-\EOF
+ --summary Z
+ EOF
+ )
+'
+
test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
test_completion "git checkout " <<-\EOF
HEAD Z
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH v6 7/7] completion: bisect: recognize but do not complete view subcommand
2024-02-06 21:50 ` [PATCH v6 " Britton Leo Kerin
` (5 preceding siblings ...)
2024-02-06 21:50 ` [PATCH v6 6/7] completion: bisect: complete log opts for visualize subcommand Britton Leo Kerin
@ 2024-02-06 21:50 ` Britton Leo Kerin
2024-02-06 22:58 ` [PATCH v6 0/7] completion: improvements for git-bisect Junio C Hamano
7 siblings, 0 replies; 58+ messages in thread
From: Britton Leo Kerin @ 2024-02-06 21:50 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Britton Leo Kerin
The "view" alias for the visualize subcommand is neither completed nor
recognized. It's undesirable to complete it because it's first letters
are the same as for visualize, making completion less rather than more
efficient without adding much in the way of interface discovery.
However, it needs to be recognized in order to enable log option
completion for it.
Recognize but do not complete the view command by creating and using
separate lists of completable_subcommands and all_subcommands. Add
tests.
Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
contrib/completion/git-completion.bash | 15 +++++++++++----
t/t9902-completion.sh | 24 ++++++++++++++++++++++++
2 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 5337ae4ce2..0734debc11 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1462,12 +1462,19 @@ _git_bisect ()
# more usual bad/new/good/old because git bisect gives a good error
# message if these are given when not in use, and that's better than
# silent refusal to complete if the user is confused.
- local subcommands="start bad new $term_bad good old $term_good terms skip reset visualize replay log run help"
- local subcommand="$(__git_find_on_cmdline "$subcommands")"
+ #
+ # We want to recognize 'view' but not complete it, because it overlaps
+ # with 'visualize' too much and is just an alias for it.
+ #
+ local completable_subcommands="start bad new $term_bad good old $term_good terms skip reset visualize replay log run help"
+ local all_subcommands="$completable_subcommands view"
+
+ local subcommand="$(__git_find_on_cmdline "$all_subcommands")"
+
if [ -z "$subcommand" ]; then
__git_find_repo_path
if [ -f "$__git_repo_path"/BISECT_START ]; then
- __gitcomp "$subcommands"
+ __gitcomp "$completable_subcommands"
else
__gitcomp "replay start"
fi
@@ -1490,7 +1497,7 @@ _git_bisect ()
__gitcomp "--term-good --term-old --term-bad --term-new"
return
;;
- visualize)
+ visualize|view)
__git_complete_log_opts
return
;;
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index b989388e7e..70557eb684 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1376,6 +1376,30 @@ test_expect_success 'git-bisect - git-log options to visualize subcommand are ca
)
'
+test_expect_success 'git-bisect - view subcommand is not a candidate' '
+ (
+ cd git-bisect &&
+ test_completion "git bisect vi" <<-\EOF
+ visualize Z
+ EOF
+ )
+'
+
+test_expect_success 'git-bisect - existing view subcommand is recognized and enables completion of git-log options' '
+ (
+ cd git-bisect &&
+ # The completion used for git-log and here does not complete
+ # every git-log option, so rather than hope to stay in sync
+ # with exactly what it does we will just spot-test here.
+ test_completion "git bisect view --sta" <<-\EOF &&
+ --stat Z
+ EOF
+ test_completion "git bisect view --summar" <<-\EOF
+ --summary Z
+ EOF
+ )
+'
+
test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
test_completion "git checkout " <<-\EOF
HEAD Z
--
2.43.0
^ permalink raw reply related [flat|nested] 58+ messages in thread
* Re: [PATCH v6 0/7] completion: improvements for git-bisect
2024-02-06 21:50 ` [PATCH v6 " Britton Leo Kerin
` (6 preceding siblings ...)
2024-02-06 21:50 ` [PATCH v6 7/7] completion: bisect: recognize but do not complete view subcommand Britton Leo Kerin
@ 2024-02-06 22:58 ` Junio C Hamano
2024-02-07 5:26 ` Patrick Steinhardt
7 siblings, 1 reply; 58+ messages in thread
From: Junio C Hamano @ 2024-02-06 22:58 UTC (permalink / raw)
To: Britton Leo Kerin; +Cc: git, Patrick Steinhardt
Britton Leo Kerin <britton.kerin@gmail.com> writes:
> Relative to v5 this makes the following actual changes:
>
> * Treat COMPREPLY as an array on assignment and test, rather than
> relying on the bash mechanism of implicitly acting on the first
> element of the array.
>
> * Whitespace fixes.
>
> The commit message about __git_complete_log_opts has also been changed
> to indicate that COMPREPLY is emptied and why, and a broken
> Signed-off-by line fixed.
Thanks. Let's queue this version and mark it for 'next' by -rc0.
^ permalink raw reply [flat|nested] 58+ messages in thread
* Re: [PATCH v6 0/7] completion: improvements for git-bisect
2024-02-06 22:58 ` [PATCH v6 0/7] completion: improvements for git-bisect Junio C Hamano
@ 2024-02-07 5:26 ` Patrick Steinhardt
0 siblings, 0 replies; 58+ messages in thread
From: Patrick Steinhardt @ 2024-02-07 5:26 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Britton Leo Kerin, git
[-- Attachment #1: Type: text/plain, Size: 748 bytes --]
On Tue, Feb 06, 2024 at 02:58:06PM -0800, Junio C Hamano wrote:
> Britton Leo Kerin <britton.kerin@gmail.com> writes:
>
> > Relative to v5 this makes the following actual changes:
> >
> > * Treat COMPREPLY as an array on assignment and test, rather than
> > relying on the bash mechanism of implicitly acting on the first
> > element of the array.
> >
> > * Whitespace fixes.
> >
> > The commit message about __git_complete_log_opts has also been changed
> > to indicate that COMPREPLY is emptied and why, and a broken
> > Signed-off-by line fixed.
>
> Thanks. Let's queue this version and mark it for 'next' by -rc0.
The range-diff looks good to me indeed, so I agree that this can be
queued. Thanks!
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 58+ messages in thread