Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git: --work-tree not being handled properly #2480

Closed
3 of 12 tasks
wthueb opened this issue Aug 15, 2024 · 1 comment · Fixed by #2483
Closed
3 of 12 tasks

git: --work-tree not being handled properly #2480

wthueb opened this issue Aug 15, 2024 · 1 comment · Fixed by #2483
Labels
bash bug Something isn't working darwin fund Fundable with polar.sh nushell

Comments

@wthueb
Copy link

wthueb commented Aug 15, 2024

Current Behavior

With a bare repo at ~/.cfg with a worktree of ~ (happens to be my dotfiles repo), the following command gives an error:

~ > carapace git nushell "git" "--git-dir" "~/.cfg" "--work-tree" "~" "add" ""
[{"value":"ERR","display":"ERR","description":"stat /Users/wil/~: no such file or directory","style":{"fg":"red","attr":"b"}},{"value":"_","display":"_"}]

Changing the command to carapace git nushell "git" "--git-dir" "/Users/wil/.cfg" "--work-tree" "/Users/wil" "add" "" seems to avoid that error (this solution is not ideal, as I'd rather use ~ expansion for home instead of getting weird with environment variables, especially considering the nushell completer setup doesn't seem to expand environment variables/interpolate strings?):

~ > carapace git nushell "git" "--git-dir" "/Users/wil/.cfg" "--work-tree" "/Users/wil" "add" ""
[{"value":".config/nushell/config.nu ","display":".config/nushell/config.nu","description":"M"}]

However, it still doesn't quite work how it should. In my instance, if I cd to ~/.config/nushell and run the command again, it still uses paths relative to the worktree even though they should be relative to the CWD:

~/.config/nushell > carapace git nushell "git" "--git-dir" "/Users/wil/.cfg" "--work-tree" "/Users/wil" "add" ""
[{"value":".config/nushell/config.nu ","display":".config/nushell/config.nu","description":"M"}]

Expected Behavior

In the above instance, ~/.config/nushell > carapace git nushell "git" "--git-dir" "~/.cfg" "--work-tree" "~" "add" "" to output config.nu.

Steps To Reproduce

With carapace 1.0.5, run carapace git nushell "git" "--git-dir" "~/.cfg" "--work-tree" "~" "add" "" with the CWD being anything other than the worktree dir, in this case ~. Don't think this is isolated to nushell, seems to happen in bash as well.

Version

1.0.5

OS

  • Darwin
  • Linux
  • Termux
  • Windows

Shell

  • Bash
  • Elvish
  • Fish
  • Nushell
  • Oil
  • Powershell
  • Xonsh
  • Zsh

Anything else?

No response

Polar

Fund with Polar
@wthueb wthueb added bug Something isn't working fund Fundable with polar.sh labels Aug 15, 2024
@rsteube
Copy link
Member

rsteube commented Aug 15, 2024

Homedir expansion is one of the tough topics.
There's a difference between unquoted ~ (expanded) and quoted "~" (not exanded) tilde.
But the information of it being quoted or not gets lost along the way.

I think it's safe for now to simply assume expansion here if one passes the ~ prefix as argument.
But be aware that while it shows completions using carapace the git command will likely fail if quoted:

git --git-dir ~/.cfg --work-tree ~ log # works
git --git-dir "~/.cfg" --work-tree "~" log # fails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bash bug Something isn't working darwin fund Fundable with polar.sh nushell
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants