zsh-workers
 help / color / mirror / code / Atom feed
* [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...)
@ 2023-03-09 12:33 eliasghafari
  2023-03-09 17:12 ` Bart Schaefer
  2023-03-09 19:27 ` Oliver Kiddle
  0 siblings, 2 replies; 12+ messages in thread
From: eliasghafari @ 2023-03-09 12:33 UTC (permalink / raw)
  To: zsh-workers

Hello,

I'm using a git bare repo to manage my files with this alias: "alias config='git --git-dir=$HOME/.local/share/dotfiles --work-tree=$HOME'",
completion for the commands works perfectly, e.g:
config ad<tab>
config add

config rm --ca<tab>
config rm --cached

But when it comes to filenames the autocompletion e.g:
in a normal git repo:
git rm --cached <tab> will show all the files that could be removed from
the index. And
git add <tab> will show all the files that were modified or created.

While using git bare repo:
config rm --cached <tab> doesn't show anything.
config add <tab> also shows nothing

So after investigating a bit, I found that the problem lied in the
expansion of the address of the git-dir and I found that by modifying
this line:
(( $+opt_args[--git-dir] )) && local -x GIT_DIR=${(Q)${~opt_args[--git-dir]}} && printf("\n${(Q)${~opt_args[--git-dir]}}\n")
which shows that the address passed to GIT_DIR is "$HOME/.local/share/dotfiles" without the "$HOME" being expanded to "/home/user".

I fixed this by replacing the Q modifier with e, but please note that I
have no idea how the zsh completion system works and I fixed this by
simply trying every modifier and seeing which one works.

After making that replacement,
config rm --cached <tab> shows what can be removed from the index, and
config add <tab> works too.


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

* Re: [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...)
  2023-03-09 12:33 [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...) eliasghafari
@ 2023-03-09 17:12 ` Bart Schaefer
  2023-03-09 19:27 ` Oliver Kiddle
  1 sibling, 0 replies; 12+ messages in thread
From: Bart Schaefer @ 2023-03-09 17:12 UTC (permalink / raw)
  To: eliasghafari; +Cc: zsh-workers

On Thu, Mar 9, 2023 at 4:42 AM eliasghafari <eliasghafari@disroot.org> wrote:
>
> I'm using a git bare repo to manage my files with this alias: "alias config='git --git-dir=$HOME/.local/share/dotfiles --work-tree=$HOME'",
> [...]
> (( $+opt_args[--git-dir] )) && local -x GIT_DIR=${(Q)${~opt_args[--git-dir]}} && printf("\n${(Q)${~opt_args[--git-dir]}}\n")
> which shows that the address passed to GIT_DIR is "$HOME/.local/share/dotfiles" without the "$HOME" being expanded to "/home/user".
>
> I fixed this by replacing the Q modifier with e

The Q modifier is just cleaning up quotes, so you probably don't want
to remove that.  I think the right thing would be to change
${(Q)${~opt_args[--git-dir]}} to ${(Q)${(e)~opt_args[--git-dir]}} but
I would defer to Daniel or Oliver to confirm.


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

* Re: [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...)
  2023-03-09 12:33 [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...) eliasghafari
  2023-03-09 17:12 ` Bart Schaefer
@ 2023-03-09 19:27 ` Oliver Kiddle
  2023-03-09 23:54   ` The (e) parameter flag and side-effects Bart Schaefer
  2023-03-10 10:07   ` [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...) Elias Ghafari
  1 sibling, 2 replies; 12+ messages in thread
From: Oliver Kiddle @ 2023-03-09 19:27 UTC (permalink / raw)
  To: eliasghafari; +Cc: zsh-workers

eliasghafari wrote:
> I'm using a git bare repo to manage my files with this alias: "alias config='git --git-dir=$HOME/.local/share/dotfiles --work-tree=$HOME'",

> While using git bare repo:
> config rm --cached <tab> doesn't show anything.

> So after investigating a bit, I found that the problem lied in the
> expansion of the address of the git-dir and I found that by modifying
> this line:
> (( $+opt_args[--git-dir] )) && local -x GIT_DIR=${(Q)${~opt_args[--git-dir]}} && printf("\n${(Q)${~opt_args[--git-dir]}}\n")
> which shows that the address passed to GIT_DIR is "$HOME/.local/share/dotfiles" without the "$HOME" being expanded to "/home/user".
>
> I fixed this by replacing the Q modifier with e, but please note that I

I would suggest you try using ~ instead of $HOME in your alias:

  alias config='git --git-dir=~/.local/share/dotfiles --work-tree=~'

The tilde in ${~opt_args[--git-dir]}} ensures that tildes are expanded.
While using (e) is arguably the right thing to do, it will expand things
like command-substitution and we've always intentionally shied away
from expanding anything that could have side-effects when parsing the
command-line for completion.

The modifiers don't allow you to pick-and-choose expansions so there
isn't a trivial way to expand variable references without expanding more
problematic things.

Oliver


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

* The (e) parameter flag and side-effects
  2023-03-09 19:27 ` Oliver Kiddle
@ 2023-03-09 23:54   ` Bart Schaefer
  2023-03-10 10:07   ` [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...) Elias Ghafari
  1 sibling, 0 replies; 12+ messages in thread
From: Bart Schaefer @ 2023-03-09 23:54 UTC (permalink / raw)
  To: Zsh hackers list

On Thu, Mar 9, 2023 at 11:28 AM Oliver Kiddle <opk@zsh.org> wrote:
>
> While using (e) is arguably the right thing to do, it will expand things
> like command-substitution and we've always intentionally shied away
> from expanding anything that could have side-effects when parsing the
> command-line for completion.

We could add a flag for that, though, I think; it would just need to
do the same trick I applied to subscript values in named references,
that is, toggle the EXECOPT flag off and back on around (or in) the
call to subst_parse_str().


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

* Re: [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...)
  2023-03-09 19:27 ` Oliver Kiddle
  2023-03-09 23:54   ` The (e) parameter flag and side-effects Bart Schaefer
@ 2023-03-10 10:07   ` Elias Ghafari
  2023-03-10 10:12     ` Roman Perepelitsa
  1 sibling, 1 reply; 12+ messages in thread
From: Elias Ghafari @ 2023-03-10 10:07 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: zsh-workers

On 23/03/09 08:27PM, Oliver Kiddle wrote:
> 
> I would suggest you try using ~ instead of $HOME in your alias:
> 
>   alias config='git --git-dir=~/.local/share/dotfiles --work-tree=~'
> 
> The tilde in ${~opt_args[--git-dir]}} ensures that tildes are expanded.

I have actually tried that before and i noticed that the completion
works as if i had put the (e), but the problem is, while the completion
works the command itself doesn't and returns an error saying that
'~/.local/share/dotfiles` isn't a git repo:
fatal: not a git repository: '~/.local/share/dotfiles'


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

* Re: [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...)
  2023-03-10 10:07   ` [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...) Elias Ghafari
@ 2023-03-10 10:12     ` Roman Perepelitsa
  2023-09-11 15:05       ` Elias Ghafari
  0 siblings, 1 reply; 12+ messages in thread
From: Roman Perepelitsa @ 2023-03-10 10:12 UTC (permalink / raw)
  To: Elias Ghafari; +Cc: Oliver Kiddle, zsh-workers

On Fri, Mar 10, 2023 at 11:08 AM Elias Ghafari <eliasghafari@disroot.org> wrote:
>
> On 23/03/09 08:27PM, Oliver Kiddle wrote:
> >
> > I would suggest you try using ~ instead of $HOME in your alias:
> >
> >   alias config='git --git-dir=~/.local/share/dotfiles --work-tree=~'
> >
> > The tilde in ${~opt_args[--git-dir]}} ensures that tildes are expanded.
>
> I have actually tried that before and i noticed that the completion
> works as if i had put the (e), but the problem is, while the completion
> works the command itself doesn't and returns an error saying that
> '~/.local/share/dotfiles` isn't a git repo:
> fatal: not a git repository: '~/.local/share/dotfiles'

You can either replace `--work-tree=~` with `--work-tree ~` or set
magic_equal_subst. I'd do the former.

Roman.


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

* Re: [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...)
  2023-03-10 10:12     ` Roman Perepelitsa
@ 2023-09-11 15:05       ` Elias Ghafari
  2023-09-12  2:26         ` Jun T
  0 siblings, 1 reply; 12+ messages in thread
From: Elias Ghafari @ 2023-09-11 15:05 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Oliver Kiddle, zsh-workers

On 23/03/10 11:12AM, Roman Perepelitsa wrote:
> You can either replace `--work-tree=~` with `--work-tree ~` or set
> magic_equal_subst. I'd do the former.

Hello again,

This solution worked perfectly until a month or so ago, but then it
stopped working.
I still use the same alias:
config='git --git-dir=$HOME/.local/share/dotfiles --work-tree ~' 

I don't know what has changed but $HOME is not expanding and executing
`zsh 2>log` returns this after trying `config diff <Tab>`:
fatal: not a git repository: '$HOME/.local/share/dotfiles'

Which is weird this error happened the last time on git's side saying
that '~/.local/share/dotfiles' is not a git repo when I replaced $HOME
with ~. But as you can see this resulted from Zsh.
Any idea of what has changed to cause this, and if this can be solved ?

Thanks,
Elias.


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

* Re: [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...)
  2023-09-11 15:05       ` Elias Ghafari
@ 2023-09-12  2:26         ` Jun T
  0 siblings, 0 replies; 12+ messages in thread
From: Jun T @ 2023-09-12  2:26 UTC (permalink / raw)
  To: zsh-workers


> 2023/09/12 0:05, Elias Ghafari <eliasghafari@disroot.org> wrote:
> 
> This solution worked perfectly until a month or so ago,

I have no idea why it was working, but are there any reasons that you
want to use '...' instead of "..."? Or am I missing something?

alias config="git --git-dir=$HOME/.local/share/dotfiles --work-tree $HOME"


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

* Re: [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...)
  2023-09-12 19:25   ` eliasghafari
@ 2023-09-12 19:33     ` Roman Perepelitsa
  0 siblings, 0 replies; 12+ messages in thread
From: Roman Perepelitsa @ 2023-09-12 19:33 UTC (permalink / raw)
  To: eliasghafari; +Cc: zsh-workers

On Tue, Sep 12, 2023 at 9:25 PM eliasghafari <eliasghafari@disroot.org> wrote:
>
> On 23/09/12 11:34AM, Roman Perepelitsa wrote:
> > Given these two definitions that differ only in quotes:
> >
> >     alias c1="git --git-dir=$HOME/.local/share/dotfiles --work-tree $HOME"
> >     alias c2='git --git-dir=$HOME/.local/share/dotfiles --work-tree $HOME'
> >
> > Can you confirm that the following two commands work as expected?
> >
> >     c1 diff
> >     c2 diff
> Yes they both work and give the info they're supposed to give.
>
> > Can you furthermore confirm that only the first of the following works
> > as expected while the second does not?
> >
> >     c1 diff <TAB>
> >     c2 diff <TAB>
> Also yes c1 autocompletion works perfectly, while c2 doesn't.

So there is indeed a bug in the git completer. I won't be debugging or
fixing this but someone else on this list might.

> For further info during my reading of the log produced by `config diff
> <C-x ?>` I noticed a couple of things, which if you want to investigate
> this, it might help you out.
> Using this alias: 'git --git-dir=$HOME/.local/share/dotfiles --work-tree ~'
>
> +_git:64> local -x GIT_DIR='$HOME/.local/share/dotfiles'

Yep, that's the culprit.

Everything else you mentioned below is as expected and not surprising.

> Using this alias: 'git --git-dir=~/.local/share/dotfiles --work-tree ~'
>
> [...] the command doesn't work it gives this error:
> warning: Not a git repository. Use --no-index to compare two paths outside a working tree

This is working as intended. The tilde isn't supposed to be expanded
and it isn't.

> And like I said 'git --git-dir ~/.local/share/dotfiles --work-tree ~'
> both works with autocompletion and the command line.

Of course.

> One last thing with config='git --git-dir ~/.local/share/dotfiles --work-tree ~'
> if I do `alias config` to show what the alias is set to, the output is
> exactly the same as above config=...

Right. This is as expected.

> But with config="git --git-dir=$HOME/.local/share/dotfiles --work-tree $HOME"
> alias config outputs:
> config='git --git-dir=/home/elias/.local/share/dotfiles --work-tree /home/elias'

Also as expected.

Roman.


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

* Re: [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...)
  2023-09-12  9:34 ` Roman Perepelitsa
@ 2023-09-12 19:25   ` eliasghafari
  2023-09-12 19:33     ` Roman Perepelitsa
  0 siblings, 1 reply; 12+ messages in thread
From: eliasghafari @ 2023-09-12 19:25 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: zsh-workers

On 23/09/12 11:34AM, Roman Perepelitsa wrote:
> Given these two definitions that differ only in quotes:
> 
>     alias c1="git --git-dir=$HOME/.local/share/dotfiles --work-tree $HOME"
>     alias c2='git --git-dir=$HOME/.local/share/dotfiles --work-tree $HOME'
> 
> Can you confirm that the following two commands work as expected?
> 
>     c1 diff
>     c2 diff
Yes they both work and give the info they're supposed to give.

> Can you furthermore confirm that only the first of the following works
> as expected while the second does not?
> 
>     c1 diff <TAB>
>     c2 diff <TAB>
Also yes c1 autocompletion works perfectly, while c2 doesn't.

For further info during my reading of the log produced by `config diff
<C-x ?>` I noticed a couple of things, which if you want to investigate
this, it might help you out.
Using this alias: 'git --git-dir=$HOME/.local/share/dotfiles --work-tree ~'

+_git:64> local -x GIT_DIR='$HOME/.local/share/dotfiles'
Notice that $HOME is not expanded, notice that the path is surrounded
by ''

+(eval):1> git --no-pager rev-list -20 '--format=%h%n%d%n%s (%cr)%n%p' HEAD
fatal: not a git repository: '$HOME/.local/share/dotfiles'

GIT_DIR not being expanded makes the autocompletion error out here where
git doesn't recognize the path as a git dir, but the command itself does
work if I `config status` it will give me the expected output. So the
conclusion is that $HOME is not being expanded in GIT_DIR but is
expanded in the command line (maybe ?).

Using this alias: 'git --git-dir=~/.local/share/dotfiles --work-tree ~'

+_git:64> local -x GIT_DIR=/home/elias/.local/share/dotfiles

Notice ~ got expanded, and autocompletion works perfectly, but this time
the command doesn't work it gives this error:
warning: Not a git repository. Use --no-index to compare two paths outside a working tree
So the ~ in GIT_DIR is being expanded but in the command line it's not.

And like I said 'git --git-dir ~/.local/share/dotfiles --work-tree ~'
both works with autocompletion and the command line.

One last thing with config='git --git-dir ~/.local/share/dotfiles --work-tree ~'
if I do `alias config` to show what the alias is set to, the output is
exactly the same as above config=...

But with config="git --git-dir=$HOME/.local/share/dotfiles --work-tree $HOME"
alias config outputs:
config='git --git-dir=/home/elias/.local/share/dotfiles --work-tree /home/elias'

Which is interesting it's already expanded that might why it's working.

Anyways hope this helps!


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

* Re: [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...)
  2023-09-12  8:54 eliasghafari
@ 2023-09-12  9:34 ` Roman Perepelitsa
  2023-09-12 19:25   ` eliasghafari
  0 siblings, 1 reply; 12+ messages in thread
From: Roman Perepelitsa @ 2023-09-12  9:34 UTC (permalink / raw)
  To: eliasghafari; +Cc: zsh-workers

On Tue, Sep 12, 2023 at 10:54 AM eliasghafari <eliasghafari@disroot.org> wrote:
>
> After using <C-x ?> instead of <Tab> (Thanks Bart) and looking at the output I found
> that:
> alias config='git --git-dir ~/.local/share/dotfiles --work-tree ~'
> works perfectly.
> And Jun T's solution of:
> alias config="git --git-dir=$HOME/.local/share/dotfiles --work-tree $HOME"
> Also works I never knew that there was a difference between ' and ".

Given these two definitions that differ only in quotes:

    alias c1="git --git-dir=$HOME/.local/share/dotfiles --work-tree $HOME"
    alias c2='git --git-dir=$HOME/.local/share/dotfiles --work-tree $HOME'

Can you confirm that the following two commands work as expected?

    c1 diff
    c2 diff

Can you furthermore confirm that only the first of the following works
as expected while the second does not?

    c1 diff <TAB>
    c2 diff <TAB>

If so, this indicates a bug in the completion code.

Roman.


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

* Re: [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...)
@ 2023-09-12  8:54 eliasghafari
  2023-09-12  9:34 ` Roman Perepelitsa
  0 siblings, 1 reply; 12+ messages in thread
From: eliasghafari @ 2023-09-12  8:54 UTC (permalink / raw)
  To: zsh-workers

After using <C-x ?> instead of <Tab> (Thanks Bart) and looking at the output I found
that:
alias config='git --git-dir ~/.local/share/dotfiles --work-tree ~'
works perfectly.
And Jun T's solution of:
alias config="git --git-dir=$HOME/.local/share/dotfiles --work-tree $HOME"
Also works I never knew that there was a difference between ' and ".

Thanks for the help.


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

end of thread, other threads:[~2023-09-12 19:33 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-09 12:33 [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...) eliasghafari
2023-03-09 17:12 ` Bart Schaefer
2023-03-09 19:27 ` Oliver Kiddle
2023-03-09 23:54   ` The (e) parameter flag and side-effects Bart Schaefer
2023-03-10 10:07   ` [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...) Elias Ghafari
2023-03-10 10:12     ` Roman Perepelitsa
2023-09-11 15:05       ` Elias Ghafari
2023-09-12  2:26         ` Jun T
2023-09-12  8:54 eliasghafari
2023-09-12  9:34 ` Roman Perepelitsa
2023-09-12 19:25   ` eliasghafari
2023-09-12 19:33     ` Roman Perepelitsa

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).