[PATCH v2 0/5] completion for git-reflog show

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This iteration has three main changes and two new commits since v2.

The changes:

 - The function __gitcomp_subcommand is no longer needed in this series.
   The patch that introduced it has been removed.
 
 - The description for the behaviour we're fixing in the patch 1/5 has
   been reworded to better explain the behaviour we're expecting.
 
 - Provide completion for both subcommands and references when the
   expectation is such that we're not sure if the implicit subcommand
   "show" is desired.

About the two new commits:

This series is described in the last "What's cooking" with:

 The command line completion script (in contrib/) learned to
 complete "git reflog" better.

So, while we're here I've included two new commits, 4/5 and 5/5, that
fit well in that description.

An important note is in the last patch, reporting the special case
needed for the <log-options> in the "show" subcommand.  This is what has
made me decide to include the new commits in this series.

Rubén Justo (5):
  completion: reflog with implicit "show"
  completion: introduce __git_find_subcommand
  completion: reflog show <log-options>
  completion: factor out __git_builtin
  completion: reflog subcommands and options

 contrib/completion/git-completion.bash | 70 ++++++++++++++++++++++----
 t/t9902-completion.sh                  | 14 ++++++
 2 files changed, 73 insertions(+), 11 deletions(-)

Range-diff against v1:
1:  1a76491362 < -:  ---------- completion: introduce __gitcomp_subcommand
3:  8defb041ac ! 1:  61b9696238 completion: reflog with implicit "show"
    @@ Commit message
             usage: git reflog [show] [<log-options>] [<ref>]
             ...
     
    -    We are not completing correctly this implicit uses of "show":
    -
    -    With ...
    +    This implicit "show" is not being completed correctly:
     
             $ git checkout -b default
    +        $ git reflog def<TAB><TAB>
    +        ... no completion options ...
     
    -    ... we are not completing "default":
    +    The expected result is:
     
    -        $ git reflog def<TAB><TAB>
    +        $ git reflog default
    +
    +    This happens because we're completing references after seeing a valid
    +    subcommand in the command line.  This prevents the implicit "show" from
    +    working properly, but also introduces a new problem: it keeps offering
    +    subcommand options when the subcommand is implicit:
    +
    +        $ git checkout -b explore
    +        $ git reflog default ex<TAB>
    +        ...
    +        $ git reflog default expire
     
    -    And we are incorrectly returning the "subcommands" when:
    +    The expected result is:
     
    -        $ git reflog default <TAB><TAB>
    -        delete expire show
    +        $ git reflog default explore
     
    -    Let's use __gitcomp_subcommand to correctly handle implicit
    -    subcommands.
    +    To fix this, complete references even if no subcommand is present, or in
    +    other words when the subcommand is implicit "show".
    +
    +    Also, only include completion options for subcommands when completing
    +    the right position in the command line.
     
           1. cf39f54efc (git reflog show, 2007-02-08)
     
    @@ contrib/completion/git-completion.bash: _git_rebase ()
     -		__gitcomp "$subcommands"
     -	else
     -		__git_complete_refs
    -+	if __gitcomp_subcommand "$subcommands"; then
    -+		return
    - 	fi
    -+
     +	__git_complete_refs
    ++
    ++	if [ $((cword - __git_cmd_idx)) -eq 1 ]; then
    ++		__gitcompappend "$subcommands" "" "$cur" " "
    + 	fi
      }
      
    - __git_send_email_confirm_options="always never auto cc compose"
     
      ## t/t9902-completion.sh ##
     @@ t/t9902-completion.sh: test_expect_success 'git clone --config= - value' '
    @@ t/t9902-completion.sh: test_expect_success 'git clone --config= - value' '
      '
      
     +test_expect_success 'git reflog show' '
    -+	test_when_finished "git checkout -" &&
    ++	test_when_finished "git checkout - && git branch -d shown" &&
     +	git checkout -b shown &&
    -+	test_completion "git reflog sho" "show " &&
    ++	test_completion "git reflog sho" <<-\EOF &&
    ++	show Z
    ++	shown Z
    ++	EOF
     +	test_completion "git reflog show sho" "shown " &&
     +	test_completion "git reflog shown sho" "shown "
     +'
2:  b1aad9a667 ! 2:  b3133c69d3 completion: introduce __git_find_subcommand
    @@ Commit message
         Signed-off-by: Rubén Justo <rjusto@xxxxxxxxx>
     
      ## contrib/completion/git-completion.bash ##
    -@@ contrib/completion/git-completion.bash: __gitcomp_subcommand ()
    - 	fi
    +@@ contrib/completion/git-completion.bash: __gitcomp_file ()
    + 	true
      }
      
     +# Find the current subcommand for commands that follow the syntax:
4:  4d3fb1d563 ! 3:  e6e526b436 completion: reflog show <log-options>
    @@ Commit message
     
      ## contrib/completion/git-completion.bash ##
     @@ contrib/completion/git-completion.bash: _git_rebase ()
    - 
      _git_reflog ()
      {
    --	local subcommands="show delete expire"
    -+	local subcommand subcommands="show delete expire"
    - 
    - 	if __gitcomp_subcommand "$subcommands"; then
    - 		return
    - 	fi
    - 
    -+	subcommand="$(__git_find_subcommand "$subcommands" "show")"
    + 	local subcommands="show delete expire"
    ++	local subcommand="$(__git_find_subcommand "$subcommands" "show")"
     +
     +	case "$subcommand,$cur" in
     +	show,--*)
    @@ contrib/completion/git-completion.bash: _git_rebase ()
     +		return
     +		;;
     +	esac
    -+
    + 
      	__git_complete_refs
    - }
      
     
      ## t/t9902-completion.sh ##
     @@ t/t9902-completion.sh: test_expect_success 'git reflog show' '
    - 	git checkout -b shown &&
    - 	test_completion "git reflog sho" "show " &&
    + 	shown Z
    + 	EOF
      	test_completion "git reflog show sho" "shown " &&
     -	test_completion "git reflog shown sho" "shown "
     +	test_completion "git reflog shown sho" "shown " &&
-:  ---------- > 4:  dfed95d495 completion: factor out __git_builtin
-:  ---------- > 5:  8193b7f4f9 completion: reflog subcommands and options
-- 
2.44.0




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux