mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-12 08:36:25 -04:00
add Gh version check
This commit is contained in:
parent
4fead59416
commit
2b8c959cb0
|
|
@ -142,9 +142,26 @@ func NewApp(config config.AppConfigurer, filterPath string) (*App, error) {
|
|||
if err != nil {
|
||||
return app, err
|
||||
}
|
||||
|
||||
return app, nil
|
||||
}
|
||||
|
||||
func (app *App) validateGhVersion() error {
|
||||
output, err := app.OSCommand.RunCommandWithOutput("gh --version")
|
||||
// if we get an error anywhere here we'll show the same status
|
||||
minVersionError := errors.New(app.Tr.MinGhVersionError)
|
||||
if err != nil {
|
||||
return minVersionError
|
||||
}
|
||||
|
||||
if isGhVersionValid(output) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return minVersionError
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
|
|
@ -181,6 +198,29 @@ func isGitVersionValid(versionStr string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func isGhVersionValid(versionStr string) bool {
|
||||
// output should be something like:
|
||||
// gh version 2.0.0 (2021-08-23)
|
||||
// https://github.com/cli/cli/releases/tag/v2.0.0
|
||||
re := regexp.MustCompile(`[^\d]+([\d\.]+)`)
|
||||
matches := re.FindStringSubmatch(versionStr)
|
||||
|
||||
if len(matches) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
ghVersion := matches[1]
|
||||
majorVersion, err := strconv.Atoi(ghVersion[0:1])
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if majorVersion < 2 {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (app *App) setupRepo() (bool, error) {
|
||||
if err := app.validateGitVersion(); err != nil {
|
||||
return false, err
|
||||
|
|
@ -236,6 +276,10 @@ func (app *App) setupRepo() (bool, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if err := app.validateGhVersion(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,3 +42,34 @@ func TestIsGitVersionValid(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsValidGhVersion(t *testing.T) {
|
||||
type scenario struct {
|
||||
versionStr string
|
||||
expectedResult bool
|
||||
}
|
||||
|
||||
scenarios := []scenario{
|
||||
{
|
||||
"",
|
||||
false,
|
||||
},
|
||||
{
|
||||
`gh version 1.0.0 (2020-08-23)
|
||||
https://github.com/cli/cli/releases/tag/v1.0.0`,
|
||||
false,
|
||||
},
|
||||
{
|
||||
`gh version 2.0.0 (2021-08-23)
|
||||
https://github.com/cli/cli/releases/tag/v2.0.0`,
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
t.Run(s.versionStr, func(t *testing.T) {
|
||||
result := isGhVersionValid(s.versionStr)
|
||||
assert.Equal(t, result, s.expectedResult)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -388,6 +388,7 @@ func chineseTranslationSet() TranslationSet {
|
|||
LcBuildingPatch: "正在构建补丁",
|
||||
LcViewCommits: "查看提交",
|
||||
MinGitVersionError: "Git 版本必须至少为 2.0(即从 2014 年开始)。请升级您的 git 版本。或者在 https://github.com/jesseduffield/lazygit/issues 上提出一个问题,以使 lazygit 更加向后兼容。",
|
||||
MinGhVersionError: "GH版本必须至少是2.0 请升级您的gh版本。或者在https://github.com/jesseduffield/lazygit/issues 提出一个问题,以使lazygit更加向后兼容。",
|
||||
LcRunningCustomCommandStatus: "正在运行自定义命令",
|
||||
LcSubmoduleStashAndReset: "存放未提交的子模块更改和更新",
|
||||
LcAndResetSubmodules: "和重置子模块",
|
||||
|
|
|
|||
|
|
@ -373,6 +373,7 @@ type TranslationSet struct {
|
|||
LcBuildingPatch string
|
||||
LcViewCommits string
|
||||
MinGitVersionError string
|
||||
MinGhVersionError string
|
||||
LcRunningCustomCommandStatus string
|
||||
LcSubmoduleStashAndReset string
|
||||
LcAndResetSubmodules string
|
||||
|
|
@ -906,6 +907,7 @@ func englishTranslationSet() TranslationSet {
|
|||
LcBuildingPatch: "building patch",
|
||||
LcViewCommits: "view commits",
|
||||
MinGitVersionError: "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.",
|
||||
MinGhVersionError: "GH version must be at least 2.0. Please upgrade your gh version. Alternatively raise an issue at https://github.com/jesseduffield/lazygit/issues for lazygit to be more backwards compatible.",
|
||||
LcRunningCustomCommandStatus: "running custom command",
|
||||
LcSubmoduleStashAndReset: "stash uncommitted submodule changes and update",
|
||||
LcAndResetSubmodules: "and reset submodules",
|
||||
|
|
|
|||
Loading…
Reference in a new issue