From 0d73fefff64e4442b257b007d06f251dcadb66fe Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Thu, 6 Aug 2026 22:27:36 +0200 Subject: [PATCH 1/4] 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 Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 48 ++++++++++++++++++++++++++ t/t9902-completion.sh | 29 ++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index e875787710..7372e2919b 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2137,6 +2137,54 @@ _git_help () fi } +__git_history_has_revision () +{ + local i + + for ((i = __git_cmd_idx + 2; i < cword; i++)); do + case "${words[i]}" in + --empty|--update-refs) + ((i++)) + ;; + -*) + ;; + *) + 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 diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 9ae3c48ebd..5ccb38c751 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -3107,6 +3107,35 @@ 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_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 && From 96b8e2f98836adde752c8193888046b508ca51b0 Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Thu, 6 Aug 2026 22:27:37 +0200 Subject: [PATCH 2/4] completion: complete 'git history --empty' values The "--empty" option accepts "drop", "keep", or "abort" for the "drop" and "fixup" subcommands. Complete these values. Although the synopsis only documents the: --empty= form, parse-options also accepts the value as a separate argument: --empty Support both forms to follow the parser. Signed-off-by: Vincent Mailhol Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 13 +++++++++++-- t/t9902-completion.sh | 5 ++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 7372e2919b..fe5223b8ec 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2171,8 +2171,17 @@ _git_history () fi if ! __git_has_doubledash; then - case "$cur" in - --*) + case "$prev,$cur" in + --empty,*|*,--empty=*) + case "$subcommand" in + drop|fixup) + __gitcomp "drop keep abort" "" \ + "${cur##--empty=}" + return + ;; + esac + ;; + *,--*) __gitcomp_builtin "history_$subcommand" return ;; diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 5ccb38c751..52a036a1ad 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -3126,7 +3126,10 @@ test_expect_success 'git history subcommand options' ' 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_completion "git history reword main -- --d" "" && + test_completion "git history fixup --empty=ke" "keep " && + test_completion "git history drop --empty ab" "abort " && + test_completion "git history reword --empty=ke" "" ' test_expect_success 'git history revisions' ' From e500dcc19286c10d7910b6e4393df91667d4de0e Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Thu, 6 Aug 2026 22:27:38 +0200 Subject: [PATCH 3/4] completion: complete 'git history --update-refs' values The "--update-refs" option accepts either "branches" or "head". Complete these values. Although the synopsis only documents the: --update-refs= form, parse-options also accepts the value as a separate argument: --update-refs Support both forms to follow the parser. Signed-off-by: Vincent Mailhol Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 5 +++++ t/t9902-completion.sh | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index fe5223b8ec..6f1ba96763 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2181,6 +2181,11 @@ _git_history () ;; esac ;; + --update-refs,*|*,--update-refs=*) + __gitcomp "branches head" "" \ + "${cur##--update-refs=}" + return + ;; *,--*) __gitcomp_builtin "history_$subcommand" return diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 52a036a1ad..ea86ecc08f 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -3129,7 +3129,11 @@ test_expect_success 'git history subcommand options' ' test_completion "git history reword main -- --d" "" && test_completion "git history fixup --empty=ke" "keep " && test_completion "git history drop --empty ab" "abort " && - test_completion "git history reword --empty=ke" "" + test_completion "git history reword --empty=ke" "" && + test_completion "git history fixup --update-refs=he" "head " && + test_completion "git history split --update-refs he" "head " && + test_completion "git history reword main -- --update-refs=he" "" && + test_completion "git history reword main -- --update-refs he" "" ' test_expect_success 'git history revisions' ' From c956ef35850cafca22e93226b2a432de01518b8d Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Thu, 6 Aug 2026 22:27:39 +0200 Subject: [PATCH 4/4] completion: complete 'git history split' pathspecs Arguments following the required revision of "git history split" are pathspecs. Complete them from tracked paths, including after an explicit "--". Signed-off-by: Vincent Mailhol Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 6 ++++++ t/t9902-completion.sh | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 6f1ba96763..d313780d8b 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2197,6 +2197,12 @@ _git_history () __git_complete_refs return fi + + case "$subcommand" in + split) + __git_complete_index_file "--cached" + ;; + esac } _git_init () diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index ea86ecc08f..391cc849a8 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -3143,6 +3143,19 @@ test_expect_success 'git history revisions' ' test_completion "git history reword main m" "" ' +test_expect_success 'git history split pathspecs' ' + test_completion "git history split main -- --update-refs=h" "" && + test_completion "git history split main -- --update-refs h" "" && + test_completion "git history split --dry-run main file" <<-\EOF && + file1Z + file2Z + EOF + test_completion "git history split main -- file" <<-\EOF + file1Z + file2Z + EOF +' + test_expect_success 'git reflog show' ' test_when_finished "git checkout - && git branch -d shown" && git checkout -b shown &&