Skip to content

Commit 85452a1

Browse files
rjustogitster
authored andcommitted
completion: reflog with implicit "show"
When no subcommand is specified to "reflog", we assume "show" [1]: $ git reflog -h usage: git reflog [show] [<log-options>] [<ref>] ... This implicit "show" is not being completed correctly: $ git checkout -b default $ git reflog def<TAB><TAB> ... no completion options ... The expected result is: $ 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 The expected result is: $ git reflog default explore 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. cf39f54 (git reflog show, 2007-02-08) Signed-off-by: Rubén Justo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e02ecfc commit 85452a1

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

contrib/completion/git-completion.bash

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,12 +2407,11 @@ _git_rebase ()
24072407
_git_reflog ()
24082408
{
24092409
local subcommands="show delete expire"
2410-
local subcommand="$(__git_find_on_cmdline "$subcommands")"
24112410

2412-
if [ -z "$subcommand" ]; then
2413-
__gitcomp "$subcommands"
2414-
else
2415-
__git_complete_refs
2411+
__git_complete_refs
2412+
2413+
if [ $((cword - __git_cmd_idx)) -eq 1 ]; then
2414+
__gitcompappend "$subcommands" "" "$cur" " "
24162415
fi
24172416
}
24182417

t/t9902-completion.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,6 +2618,17 @@ test_expect_success 'git clone --config= - value' '
26182618
EOF
26192619
'
26202620

2621+
test_expect_success 'git reflog show' '
2622+
test_when_finished "git checkout - && git branch -d shown" &&
2623+
git checkout -b shown &&
2624+
test_completion "git reflog sho" <<-\EOF &&
2625+
show Z
2626+
shown Z
2627+
EOF
2628+
test_completion "git reflog show sho" "shown " &&
2629+
test_completion "git reflog shown sho" "shown "
2630+
'
2631+
26212632
test_expect_success 'options with value' '
26222633
test_completion "git merge -X diff-algorithm=" <<-\EOF
26232634

0 commit comments

Comments
 (0)