* [PATCH] completion: add 'git history' subcommands @ 2026-08-04 19:56 Vincent Mailhol 2026-08-05 6:19 ` Patrick Steinhardt 0 siblings, 1 reply; 6+ messages in thread From: Vincent Mailhol @ 2026-08-04 19:56 UTC (permalink / raw) To: git; +Cc: Junio C Hamano, Philippe Blain, Patrick Steinhardt, Vincent Mailhol 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(+) 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 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] completion: add 'git history' subcommands 2026-08-04 19:56 [PATCH] completion: add 'git history' subcommands Vincent Mailhol @ 2026-08-05 6:19 ` Patrick Steinhardt 2026-08-05 11:56 ` D. Ben Knoble 2026-08-05 16:15 ` Junio C Hamano 0 siblings, 2 replies; 6+ messages in thread From: Patrick Steinhardt @ 2026-08-05 6:19 UTC (permalink / raw) To: Vincent Mailhol; +Cc: git, Junio C Hamano, Philippe Blain 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. 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] completion: add 'git history' subcommands 2026-08-05 6:19 ` Patrick Steinhardt @ 2026-08-05 11:56 ` D. Ben Knoble 2026-08-05 16:15 ` Junio C Hamano 1 sibling, 0 replies; 6+ messages in thread From: D. Ben Knoble @ 2026-08-05 11:56 UTC (permalink / raw) To: Patrick Steinhardt; +Cc: Vincent Mailhol, git, Junio C Hamano, Philippe Blain 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: > > 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! > 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] completion: add 'git history' subcommands 2026-08-05 6:19 ` Patrick Steinhardt 2026-08-05 11:56 ` D. Ben Knoble @ 2026-08-05 16:15 ` Junio C Hamano 2026-08-05 21:20 ` Vincent Mailhol 1 sibling, 1 reply; 6+ messages in thread From: Junio C Hamano @ 2026-08-05 16:15 UTC (permalink / raw) To: Patrick Steinhardt; +Cc: Vincent Mailhol, git, Philippe Blain 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? Thanks. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] completion: add 'git history' subcommands 2026-08-05 16:15 ` Junio C Hamano @ 2026-08-05 21:20 ` Vincent Mailhol 2026-08-06 5:18 ` Patrick Steinhardt 0 siblings, 1 reply; 6+ messages in thread From: Vincent Mailhol @ 2026-08-05 21:20 UTC (permalink / raw) To: Junio C Hamano, Patrick Steinhardt; +Cc: git, Philippe Blain On 05/08/2026 at 18:15, Junio C Hamano wrote: > 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] completion: add 'git history' subcommands 2026-08-05 21:20 ` Vincent Mailhol @ 2026-08-06 5:18 ` Patrick Steinhardt 0 siblings, 0 replies; 6+ messages in thread From: Patrick Steinhardt @ 2026-08-06 5:18 UTC (permalink / raw) To: Vincent Mailhol; +Cc: Junio C Hamano, git, Philippe Blain On Wed, Aug 05, 2026 at 11:20:58PM +0200, Vincent Mailhol wrote: > 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-08-06 5:18 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-08-04 19:56 [PATCH] completion: add 'git history' subcommands Vincent Mailhol 2026-08-05 6:19 ` Patrick Steinhardt 2026-08-05 11:56 ` D. Ben Knoble 2026-08-05 16:15 ` Junio C Hamano 2026-08-05 21:20 ` Vincent Mailhol 2026-08-06 5:18 ` Patrick Steinhardt
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox