git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v5 3/7] completion: bisect: complete custom terms and related options

From
Patrick Steinhardt <ps@pks.im>
Date
Feb 6, 2024, 07:40 UTC
Message-ID
<ZcHidsY0X5-7rw2V@tanuki>
In-Reply-To
<20240206020930.312164-4-britton.kerin@gmail.com>
On Mon, Feb 05, 2024 at 05:09:26PM -0900, Britton Leo Kerin wrote:
Show 84 quoted lines
> 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...
Show 13 quoted lines
> +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
Show 5 quoted lines
>  test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
>  	test_completion "git checkout " <<-\EOF
> -- 
> 2.43.0
> 
Previous: Britton Leo KerinNext: Britton Leo Kerin
Message 37 of 58 in “completion: improvements for git-bisect”
  1. 0/6 completion: improvements for git-bisectBritton Leo Kerin, Jan 2, 2024
  2. 0/5 completion: improvements for git-bisectBritton Leo Kerin, Jan 10, 2024
  3. 0/5 completion: improvements for git-bisectBritton Leo Kerin, Jan 18, 2024
  4. 1/5 completion: complete new old actions, start optsBritton Leo Kerin, Jan 18, 2024
  5. Patrick SteinhardtJan 19, 2024
  6. 2/5 completion: git-log opts to bisect visualizeBritton Leo Kerin, Jan 18, 2024
  7. Patrick SteinhardtJan 19, 2024
  8. 3/5 completion: move to maintain define-before-useBritton Leo Kerin, Jan 18, 2024
  9. Patrick SteinhardtJan 19, 2024
  10. 4/5 completion: custom git-bisect termsBritton Leo Kerin, Jan 18, 2024
  11. Patrick SteinhardtJan 19, 2024
  12. 5/5 completion: git-bisect view recognized but not completedBritton Leo Kerin, Jan 18, 2024
  13. Patrick SteinhardtJan 19, 2024
  14. Patrick SteinhardtJan 19, 2024
  15. Junio C HamanoJan 19, 2024
  16. Britton KerinJan 26, 2024
  17. 0/8 completion: improvements for git-bisectBritton Leo Kerin, Jan 28, 2024
  18. 2/8 completion: bisect: complete custom terms and related optionsBritton Leo Kerin, Jan 28, 2024
  19. Patrick SteinhardtFeb 1, 2024
  20. 4/8 completion: new function __git_complete_log_optsBritton Leo Kerin, Jan 28, 2024
  21. 3/8 completion: bisect: complete missing --first-parent and --no-checkout optionsBritton Leo Kerin, Jan 28, 2024
  22. 1/8 completion: bisect: complete bad, new, old, and help subcommandsBritton Leo Kerin, Jan 28, 2024
  23. Patrick SteinhardtFeb 1, 2024
  24. 5/8 completion: log: use __git_complete_log_optsBritton Leo Kerin, Jan 28, 2024
  25. Patrick SteinhardtFeb 1, 2024
  26. 6/8 completion: bisect: complete log opts for visualize subcommandBritton Leo Kerin, Jan 28, 2024
  27. 7/8 completion: bisect: recognize but do not complete view subcommandBritton Leo Kerin, Jan 28, 2024
  28. 8/8 completion: add tests for git-bisectBritton Leo Kerin, Jan 28, 2024
  29. Junio C HamanoJan 30, 2024
  30. Patrick SteinhardtFeb 1, 2024
  31. Patrick SteinhardtFeb 1, 2024
  32. 0/7 completion: improvements for git-bisectBritton Leo Kerin, Feb 6, 2024
  33. 1/7 completion: tests: always use 'master' for default initial branch nameBritton Leo Kerin, Feb 6, 2024
  34. 2/7 completion: bisect: complete bad, new, old, and help subcommandsBritton Leo Kerin, Feb 6, 2024
  35. Patrick SteinhardtFeb 6, 2024
  36. 3/7 completion: bisect: complete custom terms and related optionsBritton Leo Kerin, Feb 6, 2024
  37. Patrick SteinhardtFeb 6, 2024
  38. 4/7 completion: bisect: complete missing --first-parent and --no-checkout optionsBritton Leo Kerin, Feb 6, 2024
  39. 5/7 completion: new function __git_complete_log_optsBritton Leo Kerin, Feb 6, 2024
  40. Patrick SteinhardtFeb 6, 2024
  41. 7/7 completion: bisect: recognize but do not complete view subcommandBritton Leo Kerin, Feb 6, 2024
  42. 6/7 completion: bisect: complete log opts for visualize subcommandBritton Leo Kerin, Feb 6, 2024
  43. Patrick SteinhardtFeb 6, 2024
  44. 0/7 completion: improvements for git-bisectBritton Leo Kerin, Feb 6, 2024
  45. 3/7 completion: bisect: complete custom terms and related optionsBritton Leo Kerin, Feb 6, 2024
  46. 2/7 completion: bisect: complete bad, new, old, and help subcommandsBritton Leo Kerin, Feb 6, 2024
  47. 4/7 completion: bisect: complete missing --first-parent and --no-checkout optionsBritton Leo Kerin, Feb 6, 2024
  48. 1/7 completion: tests: always use 'master' for default initial branch nameBritton Leo Kerin, Feb 6, 2024
  49. 5/7 completion: new function __git_complete_log_optsBritton Leo Kerin, Feb 6, 2024
  50. 7/7 completion: bisect: recognize but do not complete view subcommandBritton Leo Kerin, Feb 6, 2024
  51. 6/7 completion: bisect: complete log opts for visualize subcommandBritton Leo Kerin, Feb 6, 2024
  52. Junio C HamanoFeb 6, 2024
  53. Patrick SteinhardtFeb 7, 2024
  54. 4/5 completion: custom git-bisect termsBritton Leo Kerin, Jan 10, 2024
  55. 1/5 completion: complete new old actions, start optsBritton Leo Kerin, Jan 10, 2024
  56. 2/5 completion: git-log opts to bisect visualizeBritton Leo Kerin, Jan 10, 2024
  57. 3/5 completion: move to maintain define-before-useBritton Leo Kerin, Jan 10, 2024
  58. 5/5 completion: custom git-bisect termsBritton Leo Kerin, Jan 10, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.