1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-31 22:22:14 +02:00

gracefully fail due to git version less than 2.0

This commit is contained in:
Jesse Duffield 2020-08-27 22:19:03 +10:00 committed by github-actions[bot]
parent 40bec49de8
commit 5611d9a3ef
2 changed files with 39 additions and 0 deletions

View File

@ -2,11 +2,13 @@ package app
import (
"bufio"
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
"github.com/jesseduffield/lazygit/pkg/commands"
@ -129,7 +131,33 @@ func NewApp(config config.AppConfigurer, filterPath string) (*App, error) {
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) {
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 err := app.OSCommand.RunCommand("git status"); err != nil {
cwd, err := os.Getwd()
@ -216,6 +244,14 @@ func (app *App) Close() error {
func (app *App) KnownError(err error) (string, bool) {
errorMessage := err.Error()
knownErrorMessages := []string{app.Tr.SLocalize("minGitVersionError")}
for _, message := range knownErrorMessages {
if errorMessage == message {
return message, true
}
}
mappings := []errorMapping{
{
originalError: "fatal: not a git repository",

View File

@ -1176,6 +1176,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "viewCommits",
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.",
},
)
}