Volume XXII, number 279Tuesday, October 6, 2026Latest message 13 minutes ago

The Git List

News and archive of git@vger.kernel.org, since April 2005

patchcompletion: add 'git history' subcommands

18 messages between Aug 4, 2026 and Aug 19, 2026, from Vincent Mailhol, Patrick Steinhardt, D. Ben Knoble, Junio C Hamano, Kristoffer Haugsbakk.

Plain Markdown or JSON for tools and agents. Diffs are folded; open one to read it.

Vincent MailholAug 4, 2026, 19:56 UTC on lore

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.

Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
---
 contrib/completion/git-completion.bash | 24 ++++++++++++++++++++++++
 t/t9902-completion.sh                  | 17 +++++++++++++++++
 2 files changed, 41 insertions(+)
Show changes to 2 files +41 −0

contrib/completion/git-completion.bash, t/t9902-completion.sh

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index e875787710..f10813c8d7 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2137,6 +2137,30 @@ _git_help ()
 	fi
 }
 
+_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
+
+	case "$cur" in
+	--*)
+		__gitcomp_builtin "history_$subcommand"
+		;;
+	*)
+		__git_complete_refs
+		;;
+	esac
+}
+
 _git_init ()
 {
 	case "$cur" in
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 9ae3c48ebd..08ecf682ed 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -3107,6 +3107,23 @@ 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 fixup --upd" "--update-refs="
+'
+
+test_expect_success 'git history revisions' '
+	test_completion "git history split ma" "main "
+'
+
 test_expect_success 'git reflog show' '
 	test_when_finished "git checkout - && git branch -d shown" &&
 	git checkout -b shown &&

---
base-commit: 5b2471720c93ee30e5764a19f3d3b3ae9ec9712a
change-id: 20260804-history_autocompletion-84620c2f8500
Patrick SteinhardtAug 5, 2026, 06:19 UTC in reply to Vincent Mailhol on lore

Re: [PATCH] completion: add 'git history' subcommands

On Tue, Aug 04, 2026 at 09:56:32PM +0200, Vincent Mailhol wrote:
> 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.

Ah, great! I wanted to write shell completion for git-history(1) for a while but never really found the time to actually do it.

Show 21 quoted lines
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index e875787710..f10813c8d7 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -2137,6 +2137,30 @@ _git_help ()
>  	fi
>  }
>  
> +_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

Okay. We first try to figure out whether there is any subcommand passed by the user already. If not, we complete available subcommands.

Show 9 quoted lines
> +	case "$cur" in
> +	--*)
> +		__gitcomp_builtin "history_$subcommand"
> +		;;
> +	*)
> +		__git_complete_refs
> +		;;
> +	esac
> +}

Otherwise we try to either complete available options if we see a leading "--", or alternatively we complete references. This works well for "drop", "fixup" and "reword".

The one command where this falls flat a bit is `git history split`. While the first non-option argument is indeed a reference, subsequent arguments are pathspecs. So ideally, we'd notice that we already have a reference there and, if so, complete file paths.

But that being said, I think this is a good-enough first iteration and a strict improvement over the status quo -- we don't have to be perfect right from the start. So if you want to also make that case work then great, but I won't insist on it.

Show 16 quoted lines
> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
> index 9ae3c48ebd..08ecf682ed 100755
> --- a/t/t9902-completion.sh
> +++ b/t/t9902-completion.sh
> @@ -3107,6 +3107,23 @@ 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
> +'

This will cause conflicts with "seen", as there's a new upcoming "squash" command that's currently cooking there. That's fine though, nothing you can do about that.

Thanks!
Patrick
D. Ben KnobleAug 5, 2026, 11:56 UTC in reply to Patrick Steinhardt on lore

Re: [PATCH] completion: add 'git history' subcommands

Hi all,
I agree with Patrick's review below, this looks good to me! One note…
On Wed, Aug 5, 2026 at 2:25 AM Patrick Steinhardt <ps@pks.im> wrote:
Show 52 quoted lines
>
> On Tue, Aug 04, 2026 at 09:56:32PM +0200, Vincent Mailhol wrote:
> > 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.
>
> Ah, great! I wanted to write shell completion for git-history(1) for a
> while but never really found the time to actually do it.
>
> > diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> > index e875787710..f10813c8d7 100644
> > --- a/contrib/completion/git-completion.bash
> > +++ b/contrib/completion/git-completion.bash
> > @@ -2137,6 +2137,30 @@ _git_help ()
> >       fi
> >  }
> >
> > +_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
>
> Okay. We first try to figure out whether there is any subcommand passed
> by the user already. If not, we complete available subcommands.
>
> > +     case "$cur" in
> > +     --*)
> > +             __gitcomp_builtin "history_$subcommand"
> > +             ;;
> > +     *)
> > +             __git_complete_refs
> > +             ;;
> > +     esac
> > +}
>
> Otherwise we try to either complete available options if we see a
> leading "--", or alternatively we complete references. This works well
> for "drop", "fixup" and "reword".
>
> The one command where this falls flat a bit is `git history split`.
> While the first non-option argument is indeed a reference, subsequent
> arguments are pathspecs. So ideally, we'd notice that we already have a
> reference there and, if so, complete file paths.

…here: I think it's probably going to look a bit like what _git_reflog and _git_config do, checking the subcommand and using somewhat more specific completion in that case.

BTW, I'm also reminded of <xmqqpl6g9fyu.fsf@gitster.g>, where Junio suggested we devise a way to improve _git_stash. Looking at it again with some context, I bet we can reuse the __git_resolve_builtins pattern there, too. Not for this patch, of course, just thinking aloud!

Show 29 quoted lines
> But that being said, I think this is a good-enough first iteration and a
> strict improvement over the status quo -- we don't have to be perfect
> right from the start. So if you want to also make that case work then
> great, but I won't insist on it.
>
> > diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
> > index 9ae3c48ebd..08ecf682ed 100755
> > --- a/t/t9902-completion.sh
> > +++ b/t/t9902-completion.sh
> > @@ -3107,6 +3107,23 @@ 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
> > +'
>
> This will cause conflicts with "seen", as there's a new upcoming
> "squash" command that's currently cooking there. That's fine though,
> nothing you can do about that.
>
> Thanks!
>
> Patrick
Thanks!
-- 
D. Ben Knoble
Junio C HamanoAug 5, 2026, 16:15 UTC in reply to Patrick Steinhardt on lore

Re: [PATCH] completion: add 'git history' subcommands

Patrick Steinhardt <ps@pks.im> writes:
Show 32 quoted lines
> On Tue, Aug 04, 2026 at 09:56:32PM +0200, Vincent Mailhol wrote:
>> 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.
>
> Ah, great! I wanted to write shell completion for git-history(1) for a
> while but never really found the time to actually do it.
>
>> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
>> index e875787710..f10813c8d7 100644
>> --- a/contrib/completion/git-completion.bash
>> +++ b/contrib/completion/git-completion.bash
>> @@ -2137,6 +2137,30 @@ _git_help ()
>>  	fi
>>  }
>>  
>> +_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
>
> Okay. We first try to figure out whether there is any subcommand passed
> by the user already. If not, we complete available subcommands.

This may be a tangent, but anyway. I was looking at this patch (not that I think I am capable of giving a completion patch a serious review), comparing with other completions, and the similarity of the boilerplate part above was so striking. I suspect that these were organically grown, but at some point when the tree is quiescent, can we coalesce the completion routines for subcommands that share the same pattern for better maintainability?

Thanks.
Vincent MailholAug 5, 2026, 21:20 UTC in reply to Junio C Hamano on lore

Re: [PATCH] completion: add 'git history' subcommands

On 05/08/2026 at 18:15, Junio C Hamano wrote:
Show 42 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
>> On Tue, Aug 04, 2026 at 09:56:32PM +0200, Vincent Mailhol wrote:
>>> 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.
>>
>> Ah, great! I wanted to write shell completion for git-history(1) for a
>> while but never really found the time to actually do it.
>>
>>> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
>>> index e875787710..f10813c8d7 100644
>>> --- a/contrib/completion/git-completion.bash
>>> +++ b/contrib/completion/git-completion.bash
>>> @@ -2137,6 +2137,30 @@ _git_help ()
>>>  	fi
>>>  }
>>>  
>>> +_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
>>
>> Okay. We first try to figure out whether there is any subcommand passed
>> by the user already. If not, we complete available subcommands.
> 
> This may be a tangent, but anyway.  I was looking at this patch (not
> that I think I am capable of giving a completion patch a serious
> review), comparing with other completions, and the similarity of the
> boilerplate part above was so striking.  I suspect that these were
> organically grown, but at some point when the tree is quiescent, can
> we coalesce the completion routines for subcommands that share the
> same pattern for better maintainability?
I am not sure if this would increase the maintainability.
For example, I started looking at Patrick's suggestion ※ to cover the
  git history split

special case. If we add this, we would need to dispatch this in _git_history() by adding something like:

	if [ "$subcommand" = "split" ]; then
		__git_complete_history_split
		return
	fi

but if we coalesce the completion routine for the subcommands, where should this dispatcher go?

I see this boilerplate as a skeleton waiting for extensions. Of course, maybe I am missing some points and maybe we can coalesce the code while still allowing for extensions. But currently, I am not able to depict how this should look like.

※ The fact that I started to look at the 'git history split' completion doesn't mean that I am committing myself to implement it. I will do a best effort try in my available time. If I get a decent result, I will share, if not, I would ask you to bear with the current patch!

Yours sincerely, Vincent Mailhol

Patrick SteinhardtAug 6, 2026, 05:18 UTC in reply to Vincent Mailhol on lore

Re: [PATCH] completion: add 'git history' subcommands

On Wed, Aug 05, 2026 at 11:20:58PM +0200, Vincent Mailhol wrote:
Show 5 quoted lines
> On 05/08/2026 at 18:15, Junio C Hamano wrote:
> ※ The fact that I started to look at the 'git history split' completion
> doesn't mean that I am committing myself to implement it. I will do a
> best effort try in my available time. If I get a decent result, I will
> share, if not, I would ask you to bear with the current patch!

Works for me. Would be great if you could give us an update though over the next days to say whether you will or will not submit a v2 with `git history split`.

Thanks!
Patrick
Vincent MailholAug 13, 2026, 19:05 UTC in reply to Vincent Mailhol on lore

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

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

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 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.
Link to v2: https://lore.kernel.org/r/20260806-history_autocompletion-v2-0-7e60f52a1c20@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 | 65 ++++++++++++++++++++++++++++++++++
 t/t9902-completion.sh                  | 50 ++++++++++++++++++++++++++
 2 files changed, 115 insertions(+)
Range-diff versus v2:
1:  529ecbe28c ! 1:  5764875d09 completion: add 'git history' subcommands
    @@ Commit message
     
         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
    +      - Stop revision completion after the first required revision.
     
      ## contrib/completion/git-completion.bash ##
     @@ contrib/completion/git-completion.bash: _git_help ()
    @@ contrib/completion/git-completion.bash: _git_help ()
     +
     +	for ((i = __git_cmd_idx + 2; i < cword; i++)); do
     +		case "${words[i]}" in
    -+		--empty|--update-refs)
    -+			((i++))
    -+			;;
     +		-*)
     +			;;
     +		*)
    @@ t/t9902-completion.sh: test_expect_success 'git clone --config= - value' '
      '
      
     +test_expect_success 'git history subcommands' '
    -+	test_completion "git history " <<-\EOF
    ++	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' '
    @@ t/t9902-completion.sh: test_expect_success 'git clone --config= - value' '
     +
     +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 split --update-refs=head ma" "main " &&
    ++	test_completion "git history fixup --empty=drop ma" "main " &&
     +	test_completion "git history reword main m" ""
     +'
     +
2:  691965330f < -:  ---------- completion: complete 'git history --empty' values
3:  02303a7762 < -:  ---------- completion: complete 'git history --update-refs' values
-:  ---------- > 2:  224fb8dc32 completion: complete 'git history --empty' values
-:  ---------- > 3:  60a54d5a8b completion: complete 'git history --update-refs' values
4:  39823df359 ! 4:  c895589110 completion: complete 'git history split' pathspecs
    @@ Commit message
     
         Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
         ---
    +    Changes in v3:
    +
    +      - No changes.
    +
         Changes in v2:
     
           - New patch.

--- base-commit: 4f2b99511996c64e58c74e2b8bd3d7ec33452a47 change-id: 20260804-history_autocompletion-84620c2f8500

Vincent MailholAug 13, 2026, 19:05 UTC in reply to Vincent Mailhol on lore

[PATCH v3 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 <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(+)
Show changes to 2 files +75 −0

contrib/completion/git-completion.bash, t/t9902-completion.sh

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
Vincent MailholAug 13, 2026, 19:05 UTC in reply to Vincent Mailhol on lore

[PATCH v3 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=<value>
form.
While parse-options also accepts the split
  --empty <value>

form, it is not documented. Omit it from completion as a trade-off for code simplicity.

Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
---
Changes in v3:
  - Complete only the documented stuck form.
Changes in v2:
  - New patch.
---
 contrib/completion/git-completion.bash | 9 +++++++++
 t/t9902-completion.sh                  | 6 +++++-
 2 files changed, 14 insertions(+), 1 deletion(-)
Show changes to 2 files +14 −1

contrib/completion/git-completion.bash, t/t9902-completion.sh

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' '
-- 
2.54.0
Vincent MailholAug 13, 2026, 19:05 UTC in reply to Vincent Mailhol on lore

[PATCH v3 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=<value>
form.
While parse-options also accepts the split
  --update-refs <value>

form, it is not documented. Omit it from completion as a trade-off for code simplicity.

Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
---
Changes in v3:
  - Complete only the documented stuck form.
Changes in v2:
  - New patch.
---
 contrib/completion/git-completion.bash | 5 +++++
 t/t9902-completion.sh                  | 5 ++++-
 2 files changed, 9 insertions(+), 1 deletion(-)
Show changes to 2 files +9 −1

contrib/completion/git-completion.bash, t/t9902-completion.sh

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' '
-- 
2.54.0
Vincent MailholAug 13, 2026, 19:05 UTC in reply to Vincent Mailhol on lore

[PATCH v3 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 <mailhol@kernel.org>
---
Changes in v3:
  - No changes.
Changes in v2:
  - New patch.
---
 contrib/completion/git-completion.bash |  6 ++++++
 t/t9902-completion.sh                  | 13 +++++++++++++
 2 files changed, 19 insertions(+)
Show changes to 2 files +19 −0

contrib/completion/git-completion.bash, t/t9902-completion.sh

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 &&
-- 
2.54.0
Kristoffer HaugsbakkAug 13, 2026, 20:30 UTC in reply to Vincent Mailhol on lore

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

On Thu, Aug 13, 2026, at 21:05, Vincent Mailhol wrote:
Show 7 quoted lines
> 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
>
> options. Finally, Patch #4 adds completion for pathspecs accepted by
> "split".

It looks like one line was accidentally deleted/blanked. But I think it would say the same thing as on v2:

--- 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". ---

Was the paragraph reflowed with "#3" at the start and treated like a comment line?

>
>[snip]
sent from mobile
Vincent MailholAug 14, 2026, 06:25 UTC in reply to Kristoffer Haugsbakk on lore

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

On 13/08/2026 at 22:30, Kristoffer Haugsbakk wrote:
Show 21 quoted lines
> On Thu, Aug 13, 2026, at 21:05, Vincent Mailhol wrote:
>> 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
>>
>> options. Finally, Patch #4 adds completion for pathspecs accepted by
>> "split".
> 
> It looks like one line was accidentally deleted/blanked. But I think 
> it would say the same thing as on v2:
> 
> ---
> 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".
> ---
> 
> Was the paragraph reflowed with 
> "#3" at the start and treated like
> a comment line?
Exactly.
This is the cover letter as I intended to send it:
  completion: add support for 'git history'
  
  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, respectively, 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.

As you guessed, b4 removed the line starting with #3. I didn't see this coming. From now on, I will stop using # in the description.

Should I send a v4 with the fixed cover letter, or is it OK as-is?

Yours sincerely, Vincent Mailhol

Kristoffer HaugsbakkAug 14, 2026, 07:50 UTC in reply to Vincent Mailhol on lore

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

On Fri, Aug 14, 2026, at 08:25, Vincent Mailhol wrote:
>[snip]
> As you guessed, b4 removed the line starting with #3. I didn't see this
> coming. From now on, I will stop using # in the description.

You have a new enough Git (2.54.0) that you can use `core.commentString` if you like. And with that you can set it to a string that you would never type yourself.

That’s more of an assurance than `core.commentChar` which was limited to one ASCII character.

>
> Should I send a v4 with the fixed cover letter, or is it OK as-is?

No, no new version necessary. It wasn’t my intention to make a reroll out of a molehill.

Patrick SteinhardtAug 19, 2026, 11:13 UTC in reply to Vincent Mailhol on lore

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

On Thu, Aug 13, 2026 at 09:05:02PM +0200, Vincent Mailhol wrote:
Show 6 quoted lines
> 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.

Yeah, this version is a lot more maintainable. It will have false positives, but I think we shouldn't let perfect be the enemy of good.

Patrick
Patrick SteinhardtAug 19, 2026, 11:13 UTC in reply to Vincent Mailhol on lore

Re: [PATCH v3 2/4] completion: complete 'git history --empty' values

On Thu, Aug 13, 2026 at 09:05:03PM +0200, Vincent Mailhol wrote:
Show 17 quoted lines
> 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
> +			;;

It would've been fine to just do this for every subcommand, I guess. But this version works for me, too.

Patrick
Patrick SteinhardtAug 19, 2026, 11:13 UTC in reply to Vincent Mailhol on lore

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

On Thu, Aug 13, 2026 at 09:05:01PM +0200, Vincent Mailhol wrote:
Show 6 quoted lines
> 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.

I'm happy with this version and I think it's a good base to build on going forward. Thanks!

Patrick
Junio C HamanoAug 19, 2026, 20:18 UTC in reply to Patrick Steinhardt on lore

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

Patrick Steinhardt <ps@pks.im> writes:
Show 12 quoted lines
> On Thu, Aug 13, 2026 at 09:05:01PM +0200, Vincent Mailhol wrote:
>> 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.
>
> I'm happy with this version and I think it's a good base to build on
> going forward. Thanks!
>
> Patrick
Thanks, both.

I'll prepare an evil-merge to rewrite the test to add 'squash' to the candidatesto adjust to the subcommand addition to another topic in-flight brings in when merging these patches to 'seen'.

Vincent, this is strictly FYI. You do not need to rebase on top of the other topic, until I and/or the author of the other topic ask you.

Thanks.

Back to recent threads