jesseduffield / lazygit

simple terminal UI for git commands
MIT License
52.95k stars 1.85k forks source link

lazygit no longer works in a symlinked directory #2958

Closed hboetes closed 1 year ago

hboetes commented 1 year ago

Describe the bug With the current release going into the git repo via a symlink fails. This used to work fine.

To Reproduce

han@it1notebook ~ %  ln -s /usr/sports/opt/lazygit 
han@it1notebook ~ %  cd lazygit/
han@it1notebook ~/lazygit %  <main> lazygit
2023/08/23 21:55:51 An error occurred! Please create an issue at: https://github.com/jesseduffield/lazygit/issues

*errors.errorString Must open lazygit in a git repository
/usr/pkgmk/work/lazygit/src/lazygit/pkg/commands/git.go:235 (0x9bfb06)
/usr/pkgmk/work/lazygit/src/lazygit/pkg/commands/git.go:87 (0x9be4ef)
/usr/pkgmk/work/lazygit/src/lazygit/pkg/gui/gui.go:271 (0xaf4634)
/usr/pkgmk/work/lazygit/src/lazygit/pkg/gui/gui.go:656 (0xaf71d8)
/usr/pkgmk/work/lazygit/src/lazygit/pkg/gui/gui.go:675 (0xaf77ec)
/usr/pkgmk/work/lazygit/src/lazygit/pkg/utils/utils.go:108 (0x82e527)
/usr/pkgmk/work/lazygit/src/lazygit/pkg/gui/gui.go:674 (0xaf7734)
/usr/pkgmk/work/lazygit/src/lazygit/pkg/app/app.go:263 (0xb21ba9)
/usr/pkgmk/work/lazygit/src/lazygit/pkg/app/app.go:48 (0xb21b3e)
/usr/pkgmk/work/lazygit/src/lazygit/pkg/app/entry_point.go:150 (0xb23e46)
/usr/pkgmk/work/lazygit/src/lazygit/main.go:23 (0xb256de)
/usr/lib/golang/src/runtime/internal/atomic/types.go:194 (0x439767)
    (*Uint32).Load: return Load(&u.value)
/usr/lib/golang/src/runtime/asm_amd64.s:1598 (0x469b01)
    goexit: BYTE    $0x90   // NOP
han@it1notebook ~/lazygit %  <main> cd /usr/sports/opt/lazygit
han@it1notebook /usr/sports/opt/lazygit %  <main> lazygit

And lazygit works as expected. Using a helper script like this:

#!/bin/zsh
cd $(readlink -f .)
/usr/local/bin/lazygit "$@"

works around the issue.

hongcn5 commented 1 year ago

same bug

mark2185 commented 1 year ago

It's being tracked in https://github.com/jesseduffield/lazygit/issues/3015, along with the PR #3017, thanks for the workaround!

Velrok commented 8 months ago

Here is a slightly expanded workaround. The original will cd into the sym linked folder and stay there. We also need to exit with error if the cd fails, so as to not operate on the wrong folder;

function lg {
  cd "$(readlink -f .)" || exit
  lazygit "$@"
  cd - || exit
}