git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 1/4] completion: add 'git history' subcommands

From
Vincent Mailhol <mailhol@kernel.org>
Date
Aug 13, 2026, 19:05 UTC
Message-ID
<20260813-history_autocompletion-v3-1-69eed1cea93a@kernel.org>
In-Reply-To
<20260813-history_autocompletion-v3-0-69eed1cea93a@kernel.org>
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>
---
Changes in v3:
  - Ignore the split "<option> <value>" syntax for options that take
    arguments. This simplifies revision detection and avoids hard-coding
    option names.
  - Test that options are not completed before a subcommand.
Changes in v2:
  - Test options before and after revisions.
  - Do not complete options after "--".
  - Stop revision completion after the first required revision.
---
 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 &&
-- 
2.54.0
Previous: Vincent MailholNext: Patrick Steinhardt
Message 8 of 18 in “completion: add 'git history' subcommands”
  1. completion: add 'git history' subcommandsVincent Mailhol, Aug 4, 2026
  2. Patrick SteinhardtAug 5, 2026
  3. D. Ben KnobleAug 5, 2026
  4. Junio C HamanoAug 5, 2026
  5. Vincent MailholAug 5, 2026
  6. Patrick SteinhardtAug 6, 2026
  7. 0/4 completion: add support for 'git history'Vincent Mailhol, Aug 13, 2026
  8. 1/4 completion: add 'git history' subcommandsVincent Mailhol, Aug 13, 2026
  9. Patrick SteinhardtAug 19, 2026
  10. 2/4 completion: complete 'git history --empty' valuesVincent Mailhol, Aug 13, 2026
  11. Patrick SteinhardtAug 19, 2026
  12. 3/4 completion: complete 'git history --update-refs' valuesVincent Mailhol, Aug 13, 2026
  13. 4/4 completion: complete 'git history split' pathspecsVincent Mailhol, Aug 13, 2026
  14. Kristoffer HaugsbakkAug 13, 2026
  15. Vincent MailholAug 14, 2026
  16. Kristoffer HaugsbakkAug 14, 2026
  17. Patrick SteinhardtAug 19, 2026
  18. Junio C HamanoAug 19, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.