All of lore.kernel.org
 help / color / mirror / Atom feed
* Error in bash completion
@ 2021-06-16 15:44 Harrison McCullough
  2021-06-16 17:40 ` Denton Liu
  2021-06-17  2:06 ` Felipe Contreras
  0 siblings, 2 replies; 6+ messages in thread
From: Harrison McCullough @ 2021-06-16 15:44 UTC (permalink / raw)
  To: git

What did you do before the bug happened? (Steps to reproduce your issue)

1. Create a Bash function, e.g. `ga() { git add "${@:-.}"; }`
2. Use the `__git_complete` function to add Bash tab completion for your custom
   Bash function, e.g. `__git_complete ga git_add`
3. Attempt to tab complete a file path, e.g. `ga my-incomplete-file-path<TAB>`


What did you expect to happen? (Expected behavior)

Bash tab-completes the file path.


What happened instead? (Actual behavior)

Bash tab-completes the file path but also displays an error:

$ ga fi-bash: [: -lt: unary operator expected
le3.txt

(This is when I was using tab completion to add a file called `file3.txt`).


What's different between what you expected and what actually happened?

I do not expect using tab completion to display an error.


Anything else you want to add:

I have tested this with a minial setup with Bash version 5.1.8(1)-release with
no other files sourced at startup except
/usr/local/Cellar/git/2.32.0/etc/bash_completion.d/git-completion.bash

[System Info]
git version:
git version 2.32.0
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Darwin 20.5.0 Darwin Kernel Version 20.5.0: Sat May  8 05:10:33
PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 x86_64
compiler info: clang: 12.0.5 (clang-1205.0.22.9)
libc info: no libc information available
$SHELL (typically, interactive shell): /usr/local/bin/bash


[Enabled Hooks]

-Harrison McCullough

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Error in bash completion
  2021-06-16 15:44 Error in bash completion Harrison McCullough
@ 2021-06-16 17:40 ` Denton Liu
  2021-06-16 18:05   ` Harrison McCullough
  2021-06-16 19:19   ` Felipe Contreras
  2021-06-17  2:06 ` Felipe Contreras
  1 sibling, 2 replies; 6+ messages in thread
From: Denton Liu @ 2021-06-16 17:40 UTC (permalink / raw)
  To: Harrison McCullough; +Cc: git

Hi Harrison,

On Wed, Jun 16, 2021 at 09:44:38AM -0600, Harrison McCullough wrote:
> What did you do before the bug happened? (Steps to reproduce your issue)
> 
> 1. Create a Bash function, e.g. `ga() { git add "${@:-.}"; }`
> 2. Use the `__git_complete` function to add Bash tab completion for your custom
>    Bash function, e.g. `__git_complete ga git_add`
> 3. Attempt to tab complete a file path, e.g. `ga my-incomplete-file-path<TAB>`
> 
> 
> What did you expect to happen? (Expected behavior)
> 
> Bash tab-completes the file path.
> 
> 
> What happened instead? (Actual behavior)
> 
> Bash tab-completes the file path but also displays an error:
> 
> $ ga fi-bash: [: -lt: unary operator expected
> le3.txt

This happened as a result of my changes at e94fb44042
(git-completion.bash: pass $__git_subcommand_idx from __git_main(),
2021-03-24) and 87e629756f (git-completion.bash: rename to
$__git_cmd_idx, 2021-04-22).

The tl;dr is that $__git_cmd_idx must be set to the index of the
git command you're executing (e.g. for `git add`, the index of `add`).
As a workaround for you, try setting __git_cmd_idx=0 where you define
ga().

Now, a question to the wider list: does git-completion.bash have a
public interface? I've been working off the assumption that any time a
user uses the internals, it's at their own risk. Is this a valid
assumption to make?

-Denton

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Error in bash completion
  2021-06-16 17:40 ` Denton Liu
@ 2021-06-16 18:05   ` Harrison McCullough
  2021-06-16 19:19   ` Felipe Contreras
  1 sibling, 0 replies; 6+ messages in thread
From: Harrison McCullough @ 2021-06-16 18:05 UTC (permalink / raw)
  To: Denton Liu; +Cc: git

I don't have any knowledge of the expectations regarding Git internals, but I
think it would be good to note that lines 32-33 of `git-completion.bash` say
this:

    If you have a command that is not part of git, but you would still
    like completion, you can use __git_complete:

For me that would imply that the `__git_complete` function is intended to be a
"public interface", but maybe I'm reading it wrong.

-Harrison McCullough

On Wed, Jun 16, 2021 at 11:40 AM Denton Liu <liu.denton@gmail.com> wrote:
>
> Hi Harrison,
>
> On Wed, Jun 16, 2021 at 09:44:38AM -0600, Harrison McCullough wrote:
> > What did you do before the bug happened? (Steps to reproduce your issue)
> >
> > 1. Create a Bash function, e.g. `ga() { git add "${@:-.}"; }`
> > 2. Use the `__git_complete` function to add Bash tab completion for your custom
> >    Bash function, e.g. `__git_complete ga git_add`
> > 3. Attempt to tab complete a file path, e.g. `ga my-incomplete-file-path<TAB>`
> >
> >
> > What did you expect to happen? (Expected behavior)
> >
> > Bash tab-completes the file path.
> >
> >
> > What happened instead? (Actual behavior)
> >
> > Bash tab-completes the file path but also displays an error:
> >
> > $ ga fi-bash: [: -lt: unary operator expected
> > le3.txt
>
> This happened as a result of my changes at e94fb44042
> (git-completion.bash: pass $__git_subcommand_idx from __git_main(),
> 2021-03-24) and 87e629756f (git-completion.bash: rename to
> $__git_cmd_idx, 2021-04-22).
>
> The tl;dr is that $__git_cmd_idx must be set to the index of the
> git command you're executing (e.g. for `git add`, the index of `add`).
> As a workaround for you, try setting __git_cmd_idx=0 where you define
> ga().
>
> Now, a question to the wider list: does git-completion.bash have a
> public interface? I've been working off the assumption that any time a
> user uses the internals, it's at their own risk. Is this a valid
> assumption to make?
>
> -Denton

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Error in bash completion
  2021-06-16 17:40 ` Denton Liu
  2021-06-16 18:05   ` Harrison McCullough
@ 2021-06-16 19:19   ` Felipe Contreras
  1 sibling, 0 replies; 6+ messages in thread
From: Felipe Contreras @ 2021-06-16 19:19 UTC (permalink / raw)
  To: Denton Liu, Harrison McCullough; +Cc: git

Denton Liu wrote:
> Hi Harrison,
> 
> On Wed, Jun 16, 2021 at 09:44:38AM -0600, Harrison McCullough wrote:
> > What did you do before the bug happened? (Steps to reproduce your issue)
> > 
> > 1. Create a Bash function, e.g. `ga() { git add "${@:-.}"; }`
> > 2. Use the `__git_complete` function to add Bash tab completion for your custom
> >    Bash function, e.g. `__git_complete ga git_add`
> > 3. Attempt to tab complete a file path, e.g. `ga my-incomplete-file-path<TAB>`
> > 
> > 
> > What did you expect to happen? (Expected behavior)
> > 
> > Bash tab-completes the file path.
> > 
> > 
> > What happened instead? (Actual behavior)
> > 
> > Bash tab-completes the file path but also displays an error:
> > 
> > $ ga fi-bash: [: -lt: unary operator expected
> > le3.txt
> 
> This happened as a result of my changes at e94fb44042
> (git-completion.bash: pass $__git_subcommand_idx from __git_main(),
> 2021-03-24) and 87e629756f (git-completion.bash: rename to
> $__git_cmd_idx, 2021-04-22).
> 
> The tl;dr is that $__git_cmd_idx must be set to the index of the
> git command you're executing (e.g. for `git add`, the index of `add`).
> As a workaround for you, try setting __git_cmd_idx=0 where you define
> ga().
> 
> Now, a question to the wider list: does git-completion.bash have a
> public interface? I've been working off the assumption that any time a
> user uses the internals, it's at their own risk. Is this a valid
> assumption to make?

Traditionally that was a valid assumption, although in reality people
have been using __git_complete for many years.

Since 5a067ba9d0 (completion: add proper public __git_complete,
2020-12-30) __git_complete became officially public, and the internal
one is ___git_complete.

Perhaps we could set __git_cmd_idx in __git_complete, but we would also
need to consider the zsh equivalent of __git_complete, which is compdef.

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Error in bash completion
  2021-06-16 15:44 Error in bash completion Harrison McCullough
  2021-06-16 17:40 ` Denton Liu
@ 2021-06-17  2:06 ` Felipe Contreras
  2021-06-17  2:15   ` Harrison McCullough
  1 sibling, 1 reply; 6+ messages in thread
From: Felipe Contreras @ 2021-06-17  2:06 UTC (permalink / raw)
  To: Harrison McCullough, git

Harrison McCullough wrote:
> What did you do before the bug happened? (Steps to reproduce your issue)
> 
> 1. Create a Bash function, e.g. `ga() { git add "${@:-.}"; }`
> 2. Use the `__git_complete` function to add Bash tab completion for your custom
>    Bash function, e.g. `__git_complete ga git_add`
> 3. Attempt to tab complete a file path, e.g. `ga my-incomplete-file-path<TAB>`

I can reproduce this issue; it's caused by 59d85a2a05
(git-completion.bash: use $__git_cmd_idx in more places, 2021-04-22)
which is present in v2.32.

The problem is that __git_find_on_cmdline now relies on __git_cmd_idx,
which is not defined when you do __git_complete.

The solution is to add __git_cmd_idx=1 to __git_func_wrap.

zsh is also broken by the same change, and the fix is to do the same in
the _git service.

I've fixed this in git-completion's master branch [1].

You are welcome to trying the fix.

Cheers.

[1] https://github.com/felipec/git-completion/commit/95b3b49
[2] https://github.com/git/git/commit/59d85a2a05

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Error in bash completion
  2021-06-17  2:06 ` Felipe Contreras
@ 2021-06-17  2:15   ` Harrison McCullough
  0 siblings, 0 replies; 6+ messages in thread
From: Harrison McCullough @ 2021-06-17  2:15 UTC (permalink / raw)
  To: Felipe Contreras; +Cc: git

I can verify that this fix works. Thank you for the quick response!

-Harrison McCullough

On Wed, Jun 16, 2021 at 8:06 PM Felipe Contreras
<felipe.contreras@gmail.com> wrote:
>
> Harrison McCullough wrote:
> > What did you do before the bug happened? (Steps to reproduce your issue)
> >
> > 1. Create a Bash function, e.g. `ga() { git add "${@:-.}"; }`
> > 2. Use the `__git_complete` function to add Bash tab completion for your custom
> >    Bash function, e.g. `__git_complete ga git_add`
> > 3. Attempt to tab complete a file path, e.g. `ga my-incomplete-file-path<TAB>`
>
> I can reproduce this issue; it's caused by 59d85a2a05
> (git-completion.bash: use $__git_cmd_idx in more places, 2021-04-22)
> which is present in v2.32.
>
> The problem is that __git_find_on_cmdline now relies on __git_cmd_idx,
> which is not defined when you do __git_complete.
>
> The solution is to add __git_cmd_idx=1 to __git_func_wrap.
>
> zsh is also broken by the same change, and the fix is to do the same in
> the _git service.
>
> I've fixed this in git-completion's master branch [1].
>
> You are welcome to trying the fix.
>
> Cheers.
>
> [1] https://github.com/felipec/git-completion/commit/95b3b49
> [2] https://github.com/git/git/commit/59d85a2a05
>
> --
> Felipe Contreras

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-06-17  2:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-16 15:44 Error in bash completion Harrison McCullough
2021-06-16 17:40 ` Denton Liu
2021-06-16 18:05   ` Harrison McCullough
2021-06-16 19:19   ` Felipe Contreras
2021-06-17  2:06 ` Felipe Contreras
2021-06-17  2:15   ` Harrison McCullough

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.