mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-31 23:19:40 +02:00
gracefully fail due to git version less than 2.0
This commit is contained in:
parent
40bec49de8
commit
5611d9a3ef
@ -2,11 +2,13 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||||
@ -129,7 +131,33 @@ func NewApp(config config.AppConfigurer, filterPath string) (*App, error) {
|
|||||||
return app, nil
|
return app, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *App) validateGitVersion() error {
|
||||||
|
output, err := app.OSCommand.RunCommandWithOutput("git --version")
|
||||||
|
// if we get an error anywhere here we'll show the same status
|
||||||
|
minVersionError := errors.New(app.Tr.SLocalize("minGitVersionError"))
|
||||||
|
if err != nil {
|
||||||
|
return minVersionError
|
||||||
|
}
|
||||||
|
// output should be something like: 'git version 2.23.0'
|
||||||
|
// first number in the string should be greater than 0
|
||||||
|
split := strings.Split(output, " ")
|
||||||
|
gitVersion := split[len(split)-1]
|
||||||
|
majorVersion, err := strconv.Atoi(gitVersion[0:1])
|
||||||
|
if err != nil {
|
||||||
|
return minVersionError
|
||||||
|
}
|
||||||
|
if majorVersion < 2 {
|
||||||
|
return minVersionError
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (app *App) setupRepo() (bool, error) {
|
func (app *App) setupRepo() (bool, error) {
|
||||||
|
if err := app.validateGitVersion(); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
// if we are not in a git repo, we ask if we want to `git init`
|
// if we are not in a git repo, we ask if we want to `git init`
|
||||||
if err := app.OSCommand.RunCommand("git status"); err != nil {
|
if err := app.OSCommand.RunCommand("git status"); err != nil {
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
@ -216,6 +244,14 @@ func (app *App) Close() error {
|
|||||||
func (app *App) KnownError(err error) (string, bool) {
|
func (app *App) KnownError(err error) (string, bool) {
|
||||||
errorMessage := err.Error()
|
errorMessage := err.Error()
|
||||||
|
|
||||||
|
knownErrorMessages := []string{app.Tr.SLocalize("minGitVersionError")}
|
||||||
|
|
||||||
|
for _, message := range knownErrorMessages {
|
||||||
|
if errorMessage == message {
|
||||||
|
return message, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mappings := []errorMapping{
|
mappings := []errorMapping{
|
||||||
{
|
{
|
||||||
originalError: "fatal: not a git repository",
|
originalError: "fatal: not a git repository",
|
||||||
|
@ -1176,6 +1176,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "viewCommits",
|
ID: "viewCommits",
|
||||||
Other: "view commits",
|
Other: "view commits",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "minGitVersionError",
|
||||||
|
Other: "Git version must be at least 2.0 (i.e. from 2014 onwards). Please upgrade your git version. Alternatively raise an issue at https://github.com/jesseduffield/lazygit/issues for lazygit to be more backwards compatible.",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user