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

[PATCH v2 0/4] completion: add support for 'git history'

From
Vincent Mailhol <mailhol@kernel.org>
Date
Aug 6, 2026, 20:27 UTC
Message-ID
<20260806-history_autocompletion-v2-0-7e60f52a1c20@kernel.org>

This series adds Bash completion for the subcommands of "git history" and their options.

Patch #1 adds the basic subcommand and options completion. Patch #2 and #3 take care of the value of the --empty and --update-refs options. Finally, Patch #4 adds completion for pathspecs accepted by "split".

For each of the completions, add a set of relevant test cases.
Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
---
Changes in v2:
  - Complete exactly one required revision and leave subsequent
    arguments to subcommand-specific completion.
  - Do not complete options after "--".
  - Complete values for "--empty" and "--update-refs".
  - Complete pathspecs for "git history split".
  - Expand the test coverage for options, revisions, and pathspecs.
Link to v1: https://lore.kernel.org/r/20260804-history_autocompletion-v1-1-6f7459ffb677@kernel.org
---
Vincent Mailhol (4):
      completion: add 'git history' subcommands
      completion: complete 'git history --empty' values
      completion: complete 'git history --update-refs' values
      completion: complete 'git history split' pathspecs
 contrib/completion/git-completion.bash | 68 ++++++++++++++++++++++++++++++++++
 t/t9902-completion.sh                  | 49 ++++++++++++++++++++++++
 2 files changed, 117 insertions(+)
Range-diff versus v1:
1:  d0574dca8c ! 1:  6625c7ac29 completion: add 'git history' subcommands
    @@ Metadata
      ## Commit message ##
         completion: add 'git history' subcommands
     
    -    Use the parse-options completion helpers for the "git history"
    -    subcommands and their options. Complete positional arguments as
    -    revisions, and add coverage for each kind of completion.
    +    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 v2:
    +
    +      - Test options before and after revisions.
    +      - Do not complete options after "--".
    +      - Stop revision completion after the first required
     
      ## contrib/completion/git-completion.bash ##
     @@ contrib/completion/git-completion.bash: _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
    @@ contrib/completion/git-completion.bash: _git_help ()
     +		return
     +	fi
     +
    -+	case "$cur" in
    -+	--*)
    -+		__gitcomp_builtin "history_$subcommand"
    -+		;;
    -+	*)
    ++	if ! __git_has_doubledash; then
    ++		case "$cur" in
    ++		--*)
    ++			__gitcomp_builtin "history_$subcommand"
    ++			return
    ++			;;
    ++		esac
    ++	fi
    ++
    ++	if ! __git_history_has_revision; then
     +		__git_complete_refs
    -+		;;
    -+	esac
    ++		return
    ++	fi
     +}
     +
      _git_init ()
    @@ t/t9902-completion.sh: test_expect_success 'git clone --config= - value' '
     +'
     +
     +test_expect_success 'git history subcommand options' '
    -+	test_completion "git history fixup --upd" "--update-refs="
    ++	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 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' '
-:  ---------- > 2:  f618f35153 completion: complete 'git history --empty' values
-:  ---------- > 3:  abae09f208 completion: complete 'git history --update-refs' values
-:  ---------- > 4:  7bfb6664dc completion: complete 'git history split' pathspecs

--- base-commit: c56d675cccfbcf71406c4a6806c7745e4a756294 change-id: 20260804-history_autocompletion-84620c2f8500

Next: Vincent Mailhol
Message 1 of 17 in “completion: add support for 'git history'”
  1. 0/4 completion: add support for 'git history'Vincent Mailhol, Aug 6, 2026
  2. 1/4 completion: add 'git history' subcommandsVincent Mailhol, Aug 6, 2026
  3. Patrick SteinhardtAug 7, 2026
  4. Vincent MailholAug 7, 2026
  5. Patrick SteinhardtAug 7, 2026
  6. Vincent MailholAug 7, 2026
  7. D. Ben KnobleAug 10, 2026
  8. 2/4 completion: complete 'git history --empty' valuesVincent Mailhol, Aug 6, 2026
  9. D. Ben KnobleAug 10, 2026
  10. D. Ben KnobleAug 10, 2026
  11. Vincent MailholAug 13, 2026
  12. Ben KnobleAug 13, 2026
  13. Vincent MailholAug 13, 2026
  14. 3/4 completion: complete 'git history --update-refs' valuesVincent Mailhol, Aug 6, 2026
  15. D. Ben KnobleAug 10, 2026
  16. 4/4 completion: complete 'git history split' pathspecsVincent Mailhol, Aug 6, 2026
  17. D. Ben KnobleAug 10, 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.