1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-13 13:59:06 +02:00

Revert "fix: improve backward compatibility"

Since we now require git 2.20, we don't need this any more.

This reverts commit 7c5f33980f541472aa29e4e072ace63358983308.
This commit is contained in:
Stefan Haller 2023-02-19 11:36:06 +01:00
parent 67b8ef449c
commit ac9515d8c7
3 changed files with 11 additions and 48 deletions

View File

@ -133,7 +133,7 @@ func NewGitCommandAux(
reflogCommitLoader := git_commands.NewReflogCommitLoader(cmn, cmd) reflogCommitLoader := git_commands.NewReflogCommitLoader(cmn, cmd)
remoteLoader := git_commands.NewRemoteLoader(cmn, cmd, repo.Remotes) remoteLoader := git_commands.NewRemoteLoader(cmn, cmd, repo.Remotes)
stashLoader := git_commands.NewStashLoader(cmn, cmd) stashLoader := git_commands.NewStashLoader(cmn, cmd)
tagLoader := git_commands.NewTagLoader(cmn, version, cmd) tagLoader := git_commands.NewTagLoader(cmn, cmd)
return &GitCommand{ return &GitCommand{
Branch: branchCommands, Branch: branchCommands,

View File

@ -1,8 +1,6 @@
package git_commands package git_commands
import ( import (
"fmt"
"github.com/jesseduffield/generics/slices" "github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
@ -12,31 +10,23 @@ import (
type TagLoader struct { type TagLoader struct {
*common.Common *common.Common
version *GitVersion cmd oscommands.ICmdObjBuilder
cmd oscommands.ICmdObjBuilder
} }
func NewTagLoader( func NewTagLoader(
common *common.Common, common *common.Common,
version *GitVersion,
cmd oscommands.ICmdObjBuilder, cmd oscommands.ICmdObjBuilder,
) *TagLoader { ) *TagLoader {
return &TagLoader{ return &TagLoader{
Common: common, Common: common,
version: version, cmd: cmd,
cmd: cmd,
} }
} }
func (self *TagLoader) GetTags() ([]*models.Tag, error) { func (self *TagLoader) GetTags() ([]*models.Tag, error) {
// get remote branches, sorted by creation date (descending) // get remote branches, sorted by creation date (descending)
// see: https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---sortltkeygt // see: https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---sortltkeygt
sortKey := "-creatordate" tagsOutput, err := self.cmd.New(`git tag --list --sort=-creatordate`).DontLog().RunWithOutput()
if self.version.IsOlderThan(2, 7, 0) {
sortKey = "-v:refname"
}
tagsOutput, err := self.cmd.New(fmt.Sprintf(`git tag --list --sort=%s`, sortKey)).DontLog().RunWithOutput()
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -20,7 +20,6 @@ testtag
func TestGetTags(t *testing.T) { func TestGetTags(t *testing.T) {
type scenario struct { type scenario struct {
testName string testName string
gitVersion *GitVersion
runner *oscommands.FakeCmdObjRunner runner *oscommands.FakeCmdObjRunner
expectedTags []*models.Tag expectedTags []*models.Tag
expectedError error expectedError error
@ -28,24 +27,14 @@ func TestGetTags(t *testing.T) {
scenarios := []scenario{ scenarios := []scenario{
{ {
testName: "should return no tags if there are none", testName: "should return no tags if there are none",
gitVersion: &GitVersion{2, 7, 0, ""},
runner: oscommands.NewFakeRunner(t). runner: oscommands.NewFakeRunner(t).
Expect(`git tag --list --sort=-creatordate`, "", nil), Expect(`git tag --list --sort=-creatordate`, "", nil),
expectedTags: []*models.Tag{}, expectedTags: []*models.Tag{},
expectedError: nil, expectedError: nil,
}, },
{ {
testName: "should return no tags if there are none (< 2.7.0)", testName: "should return tags if present",
gitVersion: &GitVersion{2, 6, 7, ""},
runner: oscommands.NewFakeRunner(t).
Expect(`git tag --list --sort=-v:refname`, "", nil),
expectedTags: []*models.Tag{},
expectedError: nil,
},
{
testName: "should return tags if present",
gitVersion: &GitVersion{2, 7, 0, ""},
runner: oscommands.NewFakeRunner(t). runner: oscommands.NewFakeRunner(t).
Expect(`git tag --list --sort=-creatordate`, tagsOutput, nil), Expect(`git tag --list --sort=-creatordate`, tagsOutput, nil),
expectedTags: []*models.Tag{ expectedTags: []*models.Tag{
@ -58,31 +47,15 @@ func TestGetTags(t *testing.T) {
}, },
expectedError: nil, expectedError: nil,
}, },
{
testName: "should return tags if present (< 2.7.0)",
gitVersion: &GitVersion{2, 6, 7, ""},
runner: oscommands.NewFakeRunner(t).
Expect(`git tag --list --sort=-v:refname`, tagsOutput, nil),
expectedTags: []*models.Tag{
{Name: "v0.34"},
{Name: "v0.33"},
{Name: "v0.32.2"},
{Name: "v0.32.1"},
{Name: "v0.32"},
{Name: "testtag"},
},
expectedError: nil,
},
} }
for _, scenario := range scenarios { for _, scenario := range scenarios {
scenario := scenario scenario := scenario
t.Run(scenario.testName, func(t *testing.T) { t.Run(scenario.testName, func(t *testing.T) {
loader := NewTagLoader( loader := &TagLoader{
utils.NewDummyCommon(), Common: utils.NewDummyCommon(),
scenario.gitVersion, cmd: oscommands.NewDummyCmdObjBuilder(scenario.runner),
oscommands.NewDummyCmdObjBuilder(scenario.runner), }
)
tags, err := loader.GetTags() tags, err := loader.GetTags()