Skip to content

Commit

Permalink
Show a friendly error message when starting lazygit from a non-existe…
Browse files Browse the repository at this point in the history
…nt cwd (#3192)

Closes #3187

- **PR Description**

#3187 observes that lazygit crashes with a stack trace if it's run from
a non-existent current working directory. The steps to reproduce are:

```
mkdir test
cd test
rm -r ../test
lazygit
```

(Note: I can repro this on Ubuntu, but not on macOS Sonoma, where
lazygit starts regardless of whether the current working directory
exists or not.)

Here's how the repro steps look on Ubuntu with this PR applied:

```
simon@ubuntu:/Users/simon/src/3p/lazygit$ go build .
simon@ubuntu:/Users/simon/src/3p/lazygit$ mkdir deleteme
simon@ubuntu:/Users/simon/src/3p/lazygit$ cd deleteme/
simon@ubuntu:/Users/simon/src/3p/lazygit/deleteme$ rm -r ../deleteme
simon@ubuntu:/Users/simon/src/3p/lazygit/deleteme$ ../lazygit
2024/01/02 18:40:15 Error: the current working directory does not exist
```

- **Please check if the PR fulfills these requirements**

* [x] Cheatsheets are up-to-date (run `go generate ./...`)
* [x] Code has been formatted (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting))
* [x] Tests have been added/updated (see
[here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md)
for the integration test guide)
* [x] Text is internationalised (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation))
* [x] Docs (specifically `docs/Config.md`) have been updated if
necessary
* [x] You've read through your own file changes for silly mistakes etc

<!--
Be sure to name your PR with an imperative e.g. 'Add worktrees view'
see https://github.com/jesseduffield/lazygit/releases/tag/v0.40.0 for
examples
-->
  • Loading branch information
jesseduffield authored Jan 9, 2024
2 parents d97b37a + 0cdca9a commit 6e6fe6a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/app/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func knownError(tr *i18n.TranslationSet, err error) (string, bool) {
originalError: "fatal: not a git repository",
newError: tr.NotARepository,
},
{
originalError: "getwd: no such file or directory",
newError: tr.WorkingDirectoryDoesNotExist,
},
}

if mapping, ok := lo.Find(mappings, func(mapping errorMapping) bool {
Expand Down
2 changes: 2 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ type TranslationSet struct {
StashIncludeUntrackedChanges string
StashOptions string
NotARepository string
WorkingDirectoryDoesNotExist string
Jump string
ScrollLeftRight string
ScrollLeft string
Expand Down Expand Up @@ -1153,6 +1154,7 @@ func EnglishTranslationSet() TranslationSet {
StashIncludeUntrackedChanges: "Stash all changes including untracked files",
StashOptions: "Stash options",
NotARepository: "Error: must be run inside a git repository",
WorkingDirectoryDoesNotExist: "Error: the current working directory does not exist",
Jump: "Jump to panel",
ScrollLeftRight: "Scroll left/right",
ScrollLeft: "Scroll left",
Expand Down

0 comments on commit 6e6fe6a

Please sign in to comment.