mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-10-29 11:15:38 +08:00
If the repo or linked worktree that lazygit has open is deleted while lazygit is running, every git command fails. lazygit no longer panics since the previous commit, but it shows empty lists, and there's nothing useful left to do in it. Check at the start of every refresh whether the worktree and its git dir still exist. If one of them is gone, quit and print its path in the terminal. The background files refresh does this check too, so lazygit quits within ten seconds even if nobody is using it. To quit from a refresh, return an error that wraps gocui.ErrQuit; this keeps it out of the error popup. Switching to another worktree or to a recent repo would be an alternative, but it would be more surprising than quitting. Also, there isn't always a main worktree to switch to. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package app
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/go-errors/errors"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
"github.com/jesseduffield/lazygit/pkg/i18n"
|
|
"github.com/samber/lo"
|
|
)
|
|
|
|
type errorMapping struct {
|
|
originalError string
|
|
newError string
|
|
}
|
|
|
|
// knownError takes an error and tells us whether it's an error that we know about where we can print a nicely formatted version of it rather than panicking with a stack trace
|
|
func knownError(tr *i18n.TranslationSet, err error) (string, bool) {
|
|
var quitWithMessage types.ErrQuitWithMessage
|
|
if errors.As(err, &quitWithMessage) {
|
|
return quitWithMessage.Message, true
|
|
}
|
|
|
|
errorMessage := err.Error()
|
|
|
|
knownErrorMessages := []string{minGitVersionErrorMessage(tr), tr.BareRepoNotSupported}
|
|
|
|
if lo.Contains(knownErrorMessages, errorMessage) {
|
|
return errorMessage, true
|
|
}
|
|
|
|
mappings := []errorMapping{
|
|
{
|
|
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 {
|
|
return strings.Contains(errorMessage, mapping.originalError)
|
|
}); ok {
|
|
return mapping.newError, true
|
|
}
|
|
|
|
return "", false
|
|
}
|