From: "Rubén Justo" <rjusto@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v2 0/5] completion for git-reflog show
Date: Sat, 2 Mar 2024 15:30:21 +0100 [thread overview]
Message-ID: <ea6c8890-9ff3-46c9-b933-6a52083b1001@gmail.com> (raw)
In-Reply-To: <98daf977-dbad-4d3b-a293-6a769895088f@gmail.com>
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@gmail.com>
## 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
next prev parent reply other threads:[~2024-03-02 14:30 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-26 12:46 [PATCH 0/4] completion for git-reflog show Rubén Justo
2024-01-26 12:51 ` [PATCH 1/4] completion: introduce __gitcomp_subcommand Rubén Justo
2024-01-26 17:26 ` Junio C Hamano
2024-01-26 20:09 ` Rubén Justo
2024-01-26 20:34 ` Junio C Hamano
2024-01-26 12:51 ` [PATCH 2/4] completion: introduce __git_find_subcommand Rubén Justo
2024-01-26 17:30 ` Junio C Hamano
2024-01-27 13:20 ` Rubén Justo
2024-01-26 12:53 ` [PATCH 3/4] completion: reflog with implicit "show" Rubén Justo
2024-01-26 17:57 ` Junio C Hamano
2024-01-26 20:20 ` Rubén Justo
2024-02-21 1:46 ` Junio C Hamano
2024-02-21 18:06 ` Rubén Justo
2024-02-29 19:00 ` Rubén Justo
2024-02-29 19:22 ` Junio C Hamano
2024-01-26 12:53 ` [PATCH 4/4] completion: reflog show <log-options> Rubén Justo
2024-03-02 14:30 ` Rubén Justo [this message]
2024-03-02 14:37 ` [PATCH v2 1/5] completion: reflog with implicit "show" Rubén Justo
2024-03-02 15:50 ` [PATCH v2 3/5] completion: reflog show <log-options> Rubén Justo
2024-03-02 15:51 ` [PATCH v2 2/5] completion: introduce __git_find_subcommand Rubén Justo
2024-03-02 15:52 ` [PATCH v2 4/5] completion: factor out __git_resolve_builtins Rubén Justo
2024-03-02 15:52 ` [PATCH v2 5/5] completion: reflog subcommands and options Rubén Justo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ea6c8890-9ff3-46c9-b933-6a52083b1001@gmail.com \
--to=rjusto@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).