diff mbox series

[v2,1/1] completion: don't complete revs when --no-format-patch

Message ID a718b5ee-afb0-44bd-a299-3208fac43506@smtp-relay.sendinblue.com (mailing list archive)
State New, archived
Headers show
Series [v2,1/1] completion: don't complete revs when --no-format-patch | expand

Commit Message

Britton Kerin Jan. 9, 2024, 1:08 a.m. UTC
In this case the user has specifically said they don't want send-email
to run format-patch so revs aren't valid argument completions (and it's
likely revs and dirs do have some same names or prefixes as in
Documentation/MyFirstContribution.txt 'psuh').

Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
---
 contrib/completion/git-completion.bash | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Junio C Hamano Feb. 7, 2024, 10:12 p.m. UTC | #1
"Britton Leo Kerin" <britton.kerin@gmail.com> writes:

> In this case the user has specifically said they don't want send-email
> to run format-patch so revs aren't valid argument completions (and it's
> likely revs and dirs do have some same names or prefixes as in
> Documentation/MyFirstContribution.txt 'psuh').
>
> Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
> ---
>  contrib/completion/git-completion.bash | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)

Any reviews people want to offer to this one?

Thanks.

> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 185b47d802..c983f3b2ab 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1242,10 +1242,12 @@ __git_find_last_on_cmdline ()
>  	while test $# -gt 1; do
>  		case "$1" in
>  		--show-idx)	show_idx=y ;;
> +		--)		shift && break ;;
>  		*)		return 1 ;;
>  		esac
>  		shift
>  	done
> +	[ $# -eq 1 ] || return 1   # return 1 if we got wrong # of non-opts
>  	local wordlist="$1"
>  
>  	while [ $c -gt "$__git_cmd_idx" ]; do
> @@ -2429,7 +2431,9 @@ _git_send_email ()
>  		return
>  		;;
>  	esac
> -	__git_complete_revlist
> +	if [ "$(__git_find_last_on_cmdline -- "--format-patch --no-format-patch")" != "--no-format-patch" ]; then
> +		__git_complete_revlist
> +	fi
>  }
>  
>  _git_stage ()
Patrick Steinhardt Feb. 8, 2024, 7:57 a.m. UTC | #2
On Mon, Jan 08, 2024 at 04:08:30PM -0900, Britton Leo Kerin wrote:
> In this case the user has specifically said they don't want send-email
> to run format-patch so revs aren't valid argument completions (and it's
> likely revs and dirs do have some same names or prefixes as in
> Documentation/MyFirstContribution.txt 'psuh').
> 
> Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
> ---
>  contrib/completion/git-completion.bash | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 185b47d802..c983f3b2ab 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1242,10 +1242,12 @@ __git_find_last_on_cmdline ()
>  	while test $# -gt 1; do
>  		case "$1" in
>  		--show-idx)	show_idx=y ;;
> +		--)		shift && break ;;
>  		*)		return 1 ;;
>  		esac
>  		shift
>  	done
> +	[ $# -eq 1 ] || return 1   # return 1 if we got wrong # of non-opts
>  	local wordlist="$1"
>  
>  	while [ $c -gt "$__git_cmd_idx" ]; do
> @@ -2429,7 +2431,9 @@ _git_send_email ()
>  		return
>  		;;
>  	esac
> -	__git_complete_revlist
> +	if [ "$(__git_find_last_on_cmdline -- "--format-patch --no-format-patch")" != "--no-format-patch" ]; then
> +		__git_complete_revlist
> +	fi
>  }

While this second hunk here makes perfect sense to me, there is no
explanation why we need to change `__git_find_last_on_cmdline ()`. It's
already used with "--guess --no-guess" in another place, so I would
think that it ought to work alright for this usecase, too. Or is it that
the existing callsite of this function is buggy, too? If so, we should
likely fix that in a separate patch together with a test.

Also, adding a test for git-send-email that exercises this new behaviour
would be very much welcome, too.

Patrick
Britton Kerin Feb. 14, 2024, 8:49 p.m. UTC | #3
On Wed, Feb 7, 2024 at 10:57 PM Patrick Steinhardt <ps@pks.im> wrote:
>
> On Mon, Jan 08, 2024 at 04:08:30PM -0900, Britton Leo Kerin wrote:
> > In this case the user has specifically said they don't want send-email
> > to run format-patch so revs aren't valid argument completions (and it's
> > likely revs and dirs do have some same names or prefixes as in
> > Documentation/MyFirstContribution.txt 'psuh').
> >
> > Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
> > ---
> >  contrib/completion/git-completion.bash | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> > index 185b47d802..c983f3b2ab 100644
> > --- a/contrib/completion/git-completion.bash
> > +++ b/contrib/completion/git-completion.bash
> > @@ -1242,10 +1242,12 @@ __git_find_last_on_cmdline ()
> >       while test $# -gt 1; do
> >               case "$1" in
> >               --show-idx)     show_idx=y ;;
> > +             --)             shift && break ;;
> >               *)              return 1 ;;
> >               esac
> >               shift
> >       done
> > +     [ $# -eq 1 ] || return 1   # return 1 if we got wrong # of non-opts
> >       local wordlist="$1"
> >
> >       while [ $c -gt "$__git_cmd_idx" ]; do
> > @@ -2429,7 +2431,9 @@ _git_send_email ()
> >               return
> >               ;;
> >       esac
> > -     __git_complete_revlist
> > +     if [ "$(__git_find_last_on_cmdline -- "--format-patch --no-format-patch")" != "--no-format-patch" ]; then
> > +             __git_complete_revlist
> > +     fi
> >  }
>
> While this second hunk here makes perfect sense to me, there is no
> explanation why we need to change `__git_find_last_on_cmdline ()`. It's
> already used with "--guess --no-guess" in another place, so I would
> think that it ought to work alright for this usecase, too. Or is it that
> the existing callsite of this function is buggy, too? If so, we should
> likely fix that in a separate patch together with a test.
>
> Also, adding a test for git-send-email that exercises this new behaviour
> would be very much welcome, too.

I'll look this one over again and add some tests eventually.

Britton
Junio C Hamano Feb. 21, 2024, 1:34 a.m. UTC | #4
Britton Kerin <britton.kerin@gmail.com> writes:

>> While this second hunk here makes perfect sense to me, there is no
>> explanation why we need to change `__git_find_last_on_cmdline ()`. It's
>> already used with "--guess --no-guess" in another place, so I would
>> think that it ought to work alright for this usecase, too. Or is it that
>> the existing callsite of this function is buggy, too? If so, we should
>> likely fix that in a separate patch together with a test.
>>
>> Also, adding a test for git-send-email that exercises this new behaviour
>> would be very much welcome, too.
>
> I'll look this one over again and add some tests eventually.

Thank you, both.
Junio C Hamano March 5, 2024, 9:58 p.m. UTC | #5
Britton Kerin <britton.kerin@gmail.com> writes:

> On Wed, Feb 7, 2024 at 10:57 PM Patrick Steinhardt <ps@pks.im> wrote:
>> ...
>> Also, adding a test for git-send-email that exercises this new behaviour
>> would be very much welcome, too.
>
> I'll look this one over again and add some tests eventually.

Just pinging the thread to keep it visible in the list of recent
topics I need to keep an eye on.  No rush.

Thanks.
diff mbox series

Patch

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 185b47d802..c983f3b2ab 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1242,10 +1242,12 @@  __git_find_last_on_cmdline ()
 	while test $# -gt 1; do
 		case "$1" in
 		--show-idx)	show_idx=y ;;
+		--)		shift && break ;;
 		*)		return 1 ;;
 		esac
 		shift
 	done
+	[ $# -eq 1 ] || return 1   # return 1 if we got wrong # of non-opts
 	local wordlist="$1"
 
 	while [ $c -gt "$__git_cmd_idx" ]; do
@@ -2429,7 +2431,9 @@  _git_send_email ()
 		return
 		;;
 	esac
-	__git_complete_revlist
+	if [ "$(__git_find_last_on_cmdline -- "--format-patch --no-format-patch")" != "--no-format-patch" ]; then
+		__git_complete_revlist
+	fi
 }
 
 _git_stage ()