From 27be716454cc962b1c790fc845cb2d2f46a078eb Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Thu, 13 Aug 2026 21:05:02 +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 | 45 ++++++++++++++++++++++++++ t/t9902-completion.sh | 30 +++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index e875787710..1727768487 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -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 diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 9ae3c48ebd..d0d8f2ba4a 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -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 && From 8231551929aa7fa2043c18753c736829c88df8d7 Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Thu, 13 Aug 2026 21:05:03 +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 for the documented --empty= form. While parse-options also accepts the split --empty form, it is not documented. Omit it from completion as a trade-off for code simplicity. Signed-off-by: Vincent Mailhol Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 9 +++++++++ t/t9902-completion.sh | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 1727768487..7f3cabd595 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2169,6 +2169,15 @@ _git_history () if ! __git_has_doubledash; then case "$cur" in + --empty=*) + case "$subcommand" in + drop|fixup) + __gitcomp "drop keep abort" "" \ + "${cur##--empty=}" + ;; + esac + return + ;; --*) __gitcomp_builtin "history_$subcommand" return diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index d0d8f2ba4a..851be383e1 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -3127,7 +3127,11 @@ 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 fixup --empty=drop" "drop " && + test_completion "git history drop --empty=ab" "abort " && + test_completion "git history reword --empty=ke" "" ' test_expect_success 'git history revisions' ' From 5bda733b18e838557d8956a6f5d25c5c6f7e3b34 Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Thu, 13 Aug 2026 21:05:04 +0200 Subject: [PATCH 3/4] completion: complete 'git history --update-refs' values The "--update-refs" option accepts either "branches" or "head". Complete these values for the documented --update-refs= form. While parse-options also accepts the split --update-refs form, it is not documented. Omit it from completion as a trade-off for code simplicity. Signed-off-by: Vincent Mailhol Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 5 +++++ t/t9902-completion.sh | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 7f3cabd595..19600940dc 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2178,6 +2178,11 @@ _git_history () esac return ;; + --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 851be383e1..b225dd3800 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -3131,7 +3131,10 @@ test_expect_success 'git history subcommand options' ' test_completion "git history fixup --empty=ke" "keep " && test_completion "git history fixup --empty=drop" "drop " && 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=branch" "branches " && + test_completion "git history split --update-refs=he" "head " && + test_completion "git history reword main -- --update-refs=he" "" ' test_expect_success 'git history revisions' ' From 328b3b9d6288b68fdabad2e8b8b38bd7492b6228 Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Thu, 13 Aug 2026 21:05:05 +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 19600940dc..6172b6182f 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2194,6 +2194,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 b225dd3800..194bca8d6c 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -3144,6 +3144,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 &&