completion: add 'git history' subcommands
Use the parse-options completion helpers for the git history subcommands and their options. All current history subcommands take a revision as their first positional argument, so complete that argument as a revision. Once the revision is present, leave any further positional arguments to subcommand-specific completion. This allows a subcommand to complete another kind of argument, such as the pathspec accepted by git history split or another revision if a future subcommand accepts one. Signed-off-by: Vincent Mailhol <mailhol@kernel.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>main
parent
a97fcc37c2
commit
27be716454
|
|
@ -2137,6 +2137,51 @@ _git_help ()
|
|||
fi
|
||||
}
|
||||
|
||||
__git_history_has_revision ()
|
||||
{
|
||||
local i
|
||||
|
||||
for ((i = __git_cmd_idx + 2; i < cword; i++)); do
|
||||
case "${words[i]}" in
|
||||
-*)
|
||||
;;
|
||||
*)
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
_git_history ()
|
||||
{
|
||||
local subcommands subcommand
|
||||
|
||||
__git_resolve_builtins "history"
|
||||
|
||||
subcommands="$___git_resolved_builtins"
|
||||
subcommand="$(__git_find_subcommand "$subcommands")"
|
||||
|
||||
if [ -z "$subcommand" ]; then
|
||||
__gitcomp "$subcommands"
|
||||
return
|
||||
fi
|
||||
|
||||
if ! __git_has_doubledash; then
|
||||
case "$cur" in
|
||||
--*)
|
||||
__gitcomp_builtin "history_$subcommand"
|
||||
return
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if ! __git_history_has_revision; then
|
||||
__git_complete_refs
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
_git_init ()
|
||||
{
|
||||
case "$cur" in
|
||||
|
|
|
|||
|
|
@ -3107,6 +3107,36 @@ test_expect_success 'git clone --config= - value' '
|
|||
EOF
|
||||
'
|
||||
|
||||
test_expect_success 'git history subcommands' '
|
||||
test_completion "git history " <<-\EOF &&
|
||||
drop Z
|
||||
fixup Z
|
||||
reword Z
|
||||
split Z
|
||||
EOF
|
||||
test_completion "git history --" ""
|
||||
'
|
||||
|
||||
test_expect_success 'git history subcommand options' '
|
||||
test_completion "git history split main --" <<-\EOF &&
|
||||
--update-refs=Z
|
||||
--dry-run Z
|
||||
--no-dry-run Z
|
||||
EOF
|
||||
test_completion "git history fixup --upd" "--update-refs=" &&
|
||||
test_completion "git history fixup --ree" "--reedit-message " &&
|
||||
test_completion "git history split --upd" "--update-refs=" &&
|
||||
test_completion "git history split main --dry" "--dry-run " &&
|
||||
test_completion "git history reword main -- --d" ""
|
||||
'
|
||||
|
||||
test_expect_success 'git history revisions' '
|
||||
test_completion "git history split ma" "main " &&
|
||||
test_completion "git history split --update-refs=head ma" "main " &&
|
||||
test_completion "git history fixup --empty=drop ma" "main " &&
|
||||
test_completion "git history reword main m" ""
|
||||
'
|
||||
|
||||
test_expect_success 'git reflog show' '
|
||||
test_when_finished "git checkout - && git branch -d shown" &&
|
||||
git checkout -b shown &&
|
||||
|
|
|
|||
Loading…
Reference in New Issue