From a867582d6e8a225c54e6a82e85a60e283483426d Mon Sep 17 00:00:00 2001 From: Britton Leo Kerin Date: Thu, 18 Jan 2024 11:43:19 -0900 Subject: completion: complete new old actions, start opts Signed-off-by: Britton Leo Kerin Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 185b47d802..15d22ff7d9 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 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 +1462,20 @@ _git_bisect () fi case "$subcommand" in - bad|good|reset|skip|start) + start) + case "$cur" in + --*) + __gitcomp "--term-new --term-bad --term-old --term-good --first-parent --no-checkout" + return + ;; + *) + ;; + esac + ;; + esac + + case "$subcommand" in + bad|new|good|old|reset|skip|start) __git_complete_refs ;; *) -- cgit v1.2.3 From 3d453c8a71e0cfc2745d41f6d923fbe9978b629c Mon Sep 17 00:00:00 2001 From: Britton Leo Kerin Date: Thu, 18 Jan 2024 11:43:20 -0900 Subject: completion: git-log opts to bisect visualize To do this the majority of _git_log has been factored out into the new __git_complete_log_opts. This is needed because the visualize command accepts git-log options but not rev arguments (they are fixed to the commits under bisection). __git_complete_log_opts has a precondition that COMPREPLY be empty. In a completion context it doesn't seem advisable to implement preconditions as noisy or hard failures, so instead it becomes a no-op on violation. This should be detectable and quick to debug for devels, without ever aggravating a user (besides completion failure). Signed-off-by: Britton Leo Kerin Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 15d22ff7d9..c16aded36c 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1472,6 +1472,16 @@ _git_bisect () ;; esac ;; + visualize) + case "$cur" in + -*) + __git_complete_log_opts + return + ;; + *) + ;; + esac + ;; esac case "$subcommand" in @@ -2074,10 +2084,14 @@ __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 () + +# Check for only porcelain (i.e. not git-rev-list) option (not argument) +# and selected option argument completions for git-log options and if any +# are found put them in COMPREPLY. COMPREPLY must be empty at the start, +# and will be empty on return if no candidates are found. +__git_complete_log_opts () { - __git_has_doubledash && return - __git_find_repo_path + [ -z "$COMPREPLY" ] || return 1 # Precondition local merge="" if [ -f "$__git_repo_path/MERGE_HEAD" ]; then @@ -2171,6 +2185,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 } -- cgit v1.2.3 From 330bc391945b847918ce6e747141617d50fc969d Mon Sep 17 00:00:00 2001 From: Britton Leo Kerin Date: Thu, 18 Jan 2024 11:43:21 -0900 Subject: completion: move to maintain define-before-use Signed-off-by: Britton Leo Kerin Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 269 ++++++++++++++++----------------- 1 file changed, 134 insertions(+), 135 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index c16aded36c..63ca8082a4 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1445,6 +1445,140 @@ _git_archive () __git_complete_file } +# Options that go well for log, shortlog and gitk +__git_log_common_options=" + --not --all + --branches --tags --remotes + --first-parent --merges --no-merges + --max-count= + --max-age= --since= --after= + --min-age= --until= --before= + --min-parents= --max-parents= + --no-min-parents --no-max-parents +" +# Options that go well for log and gitk (not shortlog) +__git_log_gitk_options=" + --dense --sparse --full-history + --simplify-merges --simplify-by-decoration + --left-right --notes --no-notes +" +# Options that go well for log and shortlog (not gitk) +__git_log_shortlog_options=" + --author= --committer= --grep= + --all-match --invert-grep +" +# Options accepted by log and show +__git_log_show_options=" + --diff-merges --diff-merges= --no-diff-merges --dd --remerge-diff +" + +__git_diff_merges_opts="off none on first-parent 1 separate m combined c dense-combined cc remerge r" + +__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:" + +# Check for only porcelain (i.e. not git-rev-list) option (not argument) +# and selected option argument completions for git-log options and if any +# are found put them in COMPREPLY. COMPREPLY must be empty at the start, +# and will be empty on return if no candidates are found. +__git_complete_log_opts () +{ + [ -z "$COMPREPLY" ] || return 1 # Precondition + + 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_bisect () { __git_has_doubledash && return @@ -2052,141 +2186,6 @@ _git_ls_tree () __git_complete_file } -# Options that go well for log, shortlog and gitk -__git_log_common_options=" - --not --all - --branches --tags --remotes - --first-parent --merges --no-merges - --max-count= - --max-age= --since= --after= - --min-age= --until= --before= - --min-parents= --max-parents= - --no-min-parents --no-max-parents -" -# Options that go well for log and gitk (not shortlog) -__git_log_gitk_options=" - --dense --sparse --full-history - --simplify-merges --simplify-by-decoration - --left-right --notes --no-notes -" -# Options that go well for log and shortlog (not gitk) -__git_log_shortlog_options=" - --author= --committer= --grep= - --all-match --invert-grep -" -# Options accepted by log and show -__git_log_show_options=" - --diff-merges --diff-merges= --no-diff-merges --dd --remerge-diff -" - -__git_diff_merges_opts="off none on first-parent 1 separate m combined c dense-combined cc remerge r" - -__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:" - - -# Check for only porcelain (i.e. not git-rev-list) option (not argument) -# and selected option argument completions for git-log options and if any -# are found put them in COMPREPLY. COMPREPLY must be empty at the start, -# and will be empty on return if no candidates are found. -__git_complete_log_opts () -{ - [ -z "$COMPREPLY" ] || return 1 # Precondition - - 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 -- cgit v1.2.3 From 016474e930ecdcb8689d9035cbc1131cf2e08bd7 Mon Sep 17 00:00:00 2001 From: Britton Leo Kerin Date: Thu, 18 Jan 2024 11:43:22 -0900 Subject: completion: custom git-bisect terms Signed-off-by: Britton Leo Kerin Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 63ca8082a4..ad80df6630 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1583,10 +1583,19 @@ _git_bisect () { __git_has_doubledash && return - local subcommands="start bad new good old terms skip reset visualize replay log run help" + __git_find_repo_path + + 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 + + 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 if [ -f "$__git_repo_path"/BISECT_START ]; then __gitcomp "$subcommands" else @@ -1619,7 +1628,7 @@ _git_bisect () esac case "$subcommand" in - bad|new|good|old|reset|skip|start) + bad|new|"$term_bad"|good|old|"$term_good"|reset|skip|start) __git_complete_refs ;; *) -- cgit v1.2.3 From 8d0f9d0a83f9cec9abede45cd28a39ecd2cc1f83 Mon Sep 17 00:00:00 2001 From: Britton Leo Kerin Date: Thu, 18 Jan 2024 11:43:23 -0900 Subject: completion: git-bisect view recognized but not completed This allows the git-log options to be completed but avoids completion ambiguity between visualize and view. Signed-off-by: Britton Leo Kerin Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index ad80df6630..87cf7b2561 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1591,13 +1591,22 @@ _git_bisect () term_good=`__git bisect terms --term-good` fi - local subcommands="start bad new $term_bad good old $term_good terms skip reset visualize replay log run help" + # 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. + # + # 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 "$subcommands")" + local subcommand="$(__git_find_on_cmdline "$all_subcommands")" if [ -z "$subcommand" ]; then if [ -f "$__git_repo_path"/BISECT_START ]; then - __gitcomp "$subcommands" + __gitcomp "$completable_subcommands" else __gitcomp "replay start" fi @@ -1615,7 +1624,7 @@ _git_bisect () ;; esac ;; - visualize) + visualize|view) case "$cur" in -*) __git_complete_log_opts -- cgit v1.2.3