jesseduffield / jesseduffield/lazygit

crash if opened from a .git folder

Open
#3,507 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
82.4k
Forks
3k
Avg merge
2d 18h
Merged PRs (30d)
19

Description

**Describe the bug**
Lazygit crashes when invoked from the .git folder of a regular local Git repository.

**Way to Reproduce it**
The following commands
```
$ cd /my/local/repository/
$ cd .git/
$ lazygit
```
result in the following error:
```
2024/04/20 23:57:12 An error occurred! Please create an issue at: https://github.com/jesseduffield/lazygit/issues

*errors.errorString Error getting repo paths: 'git rev-parse --path-format=absolute --show-toplevel --absolute-git-dir --git-common-dir --show-superproject-working-tree' failed: fatal: this operation must be run in a work tree

/home/federico/go/pkg/mod/github.com/jesseduffield/lazygit@v0.41.0/pkg/commands/git.go:65 (0x9a7fc9)
NewGitCommand: return nil, errors.Errorf("Error getting repo paths: %v", err)
/home/federico/go/pkg/mod/github.com/jesseduffield/lazygit@v0.41.0/pkg/gui/gui.go:300 (0xb312d5)
(*Gui).onNewRepo: gui.git, err = commands.NewGitCommand(
/home/federico/go/pkg/mod/github.com/jesseduffield/lazygit@v0.41.0/pkg/gui/gui.go:692 (0xb34078)
(*Gui).Run: if err := gui.onNewRepo(startArgs, context.NO_CONTEXT); err != nil {
/home/federico/go/pkg/mod/github.com/jesseduffield/lazygit@v0.41.0/pkg/gui/gui.go:711 (0xb34705)
(*Gui).RunAndHandleError.func1: if err := gui.Run(startArgs); err != nil {
/home/federico/go/pkg/mod/github.com/jesseduffield/lazygit@v0.41.0/pkg/utils/utils.go:117 (0x82837c)
SafeWithError: err := f()
/home/federico/go/pkg/mod/github.com/jesseduffield/lazygit@v0.41.0/pkg/gui/gui.go:710 (0xb3464e)
(*Gui).RunAndHandleError: return utils.SafeWithError(func() error {
/home/federico/go/pkg/mod/github.com/jesseduffield/lazygit@v0.41.0/pkg/app/app.go:266 (0xb62396)
Run: err := app.Gui.RunAndHandleError(startArgs)
/home/federico/go/pkg/mod/github.com/jesseduffield/lazygit@v0.41.0/pkg/app/app.go:49 (0xb62346)
Run: err = app.Run(startArgs)
/home/federico/go/pkg/mod/github.com/jesseduffield/lazygit@v0.41.0/pkg/app/entry_point.go:150 (0xb64565)
Start: Run(appConfig, common, appTypes.NewStartArgs(cliArgs.FilterPath, parsedGitArg, integrationTest))
/home/federico/go/pkg/mod/github.com/jesseduffield/lazygit@v0.41.0/main.go:23 (0xb65d98)
main: app.Start(ldFlagsBuildInfo, nil)
/home/federico/.go/go1.22.1/src/runtime/internal/atomic/types.go:194 (0x44035d)
(*Uint32).Load: return Load(&u.value)
/home/federico/.go/go1.22.1/src/runtime/asm_amd64.s:1695 (0x473501)
goexit: BYTE $0x90 // NOP

```

**Expected behavior**
Clean exit with a clear error message (like "Error: must be run inside the main folder of a git repository")

**Version info:**
```
$ lazygit --version
commit=, build date=, build source=unknown, version=unversioned, os=linux, arch=amd64, git version=2.34.1
```
```
$ git --version
git version 2.34.1
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.