1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-28 16:02:01 +03:00

Remove git version specific code for versions we no longer support

This commit is contained in:
Stefan Haller
2025-07-09 11:48:23 +02:00
parent 93c5849c86
commit c739357eb9
9 changed files with 27 additions and 53 deletions

View File

@ -249,8 +249,7 @@ func (self *CommitLoader) extractCommitFromLine(hashPool *utils.StringPool, line
} }
func (self *CommitLoader) getHydratedRebasingCommits(hashPool *utils.StringPool, addConflictingCommit bool) ([]*models.Commit, error) { func (self *CommitLoader) getHydratedRebasingCommits(hashPool *utils.StringPool, addConflictingCommit bool) ([]*models.Commit, error) {
todoFileHasShortHashes := self.version.IsOlderThan(2, 25, 2) return self.getHydratedTodoCommits(hashPool, self.getRebasingCommits(hashPool, addConflictingCommit), false)
return self.getHydratedTodoCommits(hashPool, self.getRebasingCommits(hashPool, addConflictingCommit), todoFileHasShortHashes)
} }
func (self *CommitLoader) getHydratedSequencerCommits(hashPool *utils.StringPool, workingTreeState models.WorkingTreeState) ([]*models.Commit, error) { func (self *CommitLoader) getHydratedSequencerCommits(hashPool *utils.StringPool, workingTreeState models.WorkingTreeState) ([]*models.Commit, error) {

View File

@ -218,7 +218,7 @@ func (self *RebaseCommands) PrepareInteractiveRebaseCommand(opts PrepareInteract
Arg("--interactive"). Arg("--interactive").
Arg("--autostash"). Arg("--autostash").
Arg("--keep-empty"). Arg("--keep-empty").
ArgIf(opts.keepCommitsThatBecomeEmpty && self.version.IsAtLeast(2, 26, 0), "--empty=keep"). ArgIf(opts.keepCommitsThatBecomeEmpty, "--empty=keep").
Arg("--no-autosquash"). Arg("--no-autosquash").
Arg("--rebase-merges"). Arg("--rebase-merges").
ArgIf(opts.onto != "", "--onto", opts.onto). ArgIf(opts.onto != "", "--onto", opts.onto).

View File

@ -21,8 +21,6 @@ type RepoPaths struct {
isBareRepo bool isBareRepo bool
} }
var gitPathFormatVersion = GitVersion{2, 31, 0, ""}
// Path to the current worktree. If we're in the main worktree, this will // Path to the current worktree. If we're in the main worktree, this will
// be the same as RepoPath() // be the same as RepoPath()
func (self *RepoPaths) WorktreePath() string { func (self *RepoPaths) WorktreePath() string {
@ -79,15 +77,14 @@ func GetRepoPaths(
if err != nil { if err != nil {
return nil, err return nil, err
} }
return GetRepoPathsForDir(cwd, cmd, version) return GetRepoPathsForDir(cwd, cmd)
} }
func GetRepoPathsForDir( func GetRepoPathsForDir(
dir string, dir string,
cmd oscommands.ICmdObjBuilder, cmd oscommands.ICmdObjBuilder,
version *GitVersion,
) (*RepoPaths, error) { ) (*RepoPaths, error) {
gitDirOutput, err := callGitRevParseWithDir(cmd, version, dir, "--show-toplevel", "--absolute-git-dir", "--git-common-dir", "--is-bare-repository", "--show-superproject-working-tree") gitDirOutput, err := callGitRevParseWithDir(cmd, dir, "--show-toplevel", "--absolute-git-dir", "--git-common-dir", "--is-bare-repository", "--show-superproject-working-tree")
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -96,12 +93,6 @@ func GetRepoPathsForDir(
worktreePath := gitDirResults[0] worktreePath := gitDirResults[0]
worktreeGitDirPath := gitDirResults[1] worktreeGitDirPath := gitDirResults[1]
repoGitDirPath := gitDirResults[2] repoGitDirPath := gitDirResults[2]
if version.IsOlderThanVersion(&gitPathFormatVersion) {
repoGitDirPath, err = filepath.Abs(repoGitDirPath)
if err != nil {
return nil, err
}
}
isBareRepo := gitDirResults[3] == "true" isBareRepo := gitDirResults[3] == "true"
// If we're in a submodule, --show-superproject-working-tree will return // If we're in a submodule, --show-superproject-working-tree will return
@ -131,11 +122,10 @@ func GetRepoPathsForDir(
func callGitRevParseWithDir( func callGitRevParseWithDir(
cmd oscommands.ICmdObjBuilder, cmd oscommands.ICmdObjBuilder,
version *GitVersion,
dir string, dir string,
gitRevArgs ...string, gitRevArgs ...string,
) (string, error) { ) (string, error) {
gitRevParse := NewGitCmd("rev-parse").ArgIf(version.IsAtLeastVersion(&gitPathFormatVersion), "--path-format=absolute").Arg(gitRevArgs...) gitRevParse := NewGitCmd("rev-parse").Arg("--path-format=absolute").Arg(gitRevArgs...)
if dir != "" { if dir != "" {
gitRevParse.Dir(dir) gitRevParse.Dir(dir)
} }

View File

@ -194,22 +194,13 @@ func TestGetRepoPaths(t *testing.T) {
runner := oscommands.NewFakeRunner(t) runner := oscommands.NewFakeRunner(t)
cmd := oscommands.NewDummyCmdObjBuilder(runner) cmd := oscommands.NewDummyCmdObjBuilder(runner)
version, err := GetGitVersion(oscommands.NewDummyOSCommand())
if err != nil {
t.Fatal(err)
}
getRevParseArgs := func() []string { getRevParseArgs := func() []string {
args := []string{"rev-parse"} return []string{"rev-parse", "--path-format=absolute"}
if version.IsAtLeast(2, 31, 0) {
args = append(args, "--path-format=absolute")
}
return args
} }
// prepare the filesystem for the scenario // prepare the filesystem for the scenario
s.BeforeFunc(runner, getRevParseArgs) s.BeforeFunc(runner, getRevParseArgs)
repoPaths, err := GetRepoPathsForDir("", cmd, version) repoPaths, err := GetRepoPathsForDir("", cmd)
// check the error and the paths // check the error and the paths
if s.Err != nil { if s.Err != nil {

View File

@ -59,7 +59,7 @@ func (self *SyncCommands) fetchCommandBuilder(fetchAll bool) *GitCommandBuilder
ArgIf(fetchAll, "--all"). ArgIf(fetchAll, "--all").
// avoid writing to .git/FETCH_HEAD; this allows running a pull // avoid writing to .git/FETCH_HEAD; this allows running a pull
// concurrently without getting errors // concurrently without getting errors
ArgIf(self.version.IsAtLeast(2, 29, 0), "--no-write-fetch-head") Arg("--no-write-fetch-head")
} }
func (self *SyncCommands) FetchCmdObj(task gocui.Task) *oscommands.CmdObj { func (self *SyncCommands) FetchCmdObj(task gocui.Task) *oscommands.CmdObj {

View File

@ -119,7 +119,7 @@ func TestSyncFetch(t *testing.T) {
test: func(cmdObj *oscommands.CmdObj) { test: func(cmdObj *oscommands.CmdObj) {
assert.True(t, cmdObj.ShouldLog()) assert.True(t, cmdObj.ShouldLog())
assert.Equal(t, cmdObj.GetCredentialStrategy(), oscommands.PROMPT) assert.Equal(t, cmdObj.GetCredentialStrategy(), oscommands.PROMPT)
assert.Equal(t, cmdObj.Args(), []string{"git", "fetch"}) assert.Equal(t, cmdObj.Args(), []string{"git", "fetch", "--no-write-fetch-head"})
}, },
}, },
{ {
@ -128,7 +128,7 @@ func TestSyncFetch(t *testing.T) {
test: func(cmdObj *oscommands.CmdObj) { test: func(cmdObj *oscommands.CmdObj) {
assert.True(t, cmdObj.ShouldLog()) assert.True(t, cmdObj.ShouldLog())
assert.Equal(t, cmdObj.GetCredentialStrategy(), oscommands.PROMPT) assert.Equal(t, cmdObj.GetCredentialStrategy(), oscommands.PROMPT)
assert.Equal(t, cmdObj.Args(), []string{"git", "fetch", "--all"}) assert.Equal(t, cmdObj.Args(), []string{"git", "fetch", "--all", "--no-write-fetch-head"})
}, },
}, },
} }
@ -157,7 +157,7 @@ func TestSyncFetchBackground(t *testing.T) {
test: func(cmdObj *oscommands.CmdObj) { test: func(cmdObj *oscommands.CmdObj) {
assert.False(t, cmdObj.ShouldLog()) assert.False(t, cmdObj.ShouldLog())
assert.Equal(t, cmdObj.GetCredentialStrategy(), oscommands.FAIL) assert.Equal(t, cmdObj.GetCredentialStrategy(), oscommands.FAIL)
assert.Equal(t, cmdObj.Args(), []string{"git", "fetch"}) assert.Equal(t, cmdObj.Args(), []string{"git", "fetch", "--no-write-fetch-head"})
}, },
}, },
{ {
@ -166,7 +166,7 @@ func TestSyncFetchBackground(t *testing.T) {
test: func(cmdObj *oscommands.CmdObj) { test: func(cmdObj *oscommands.CmdObj) {
assert.False(t, cmdObj.ShouldLog()) assert.False(t, cmdObj.ShouldLog())
assert.Equal(t, cmdObj.GetCredentialStrategy(), oscommands.FAIL) assert.Equal(t, cmdObj.GetCredentialStrategy(), oscommands.FAIL)
assert.Equal(t, cmdObj.Args(), []string{"git", "fetch", "--all"}) assert.Equal(t, cmdObj.Args(), []string{"git", "fetch", "--all", "--no-write-fetch-head"})
}, },
}, },
} }

View File

@ -82,7 +82,7 @@ func (self *WorktreeLoader) GetWorktrees() ([]*models.Worktree, error) {
if worktree.IsPathMissing { if worktree.IsPathMissing {
return return
} }
gitDir, err := callGitRevParseWithDir(self.cmd, self.version, worktree.Path, "--absolute-git-dir") gitDir, err := callGitRevParseWithDir(self.cmd, worktree.Path, "--absolute-git-dir")
if err != nil { if err != nil {
self.Log.Warnf("Could not find git dir for worktree %s: %v", worktree.Path, err) self.Log.Warnf("Could not find git dir for worktree %s: %v", worktree.Path, err)
return return

View File

@ -190,11 +190,7 @@ branch refs/heads/mybranch-worktree
} }
getRevParseArgs := func() []string { getRevParseArgs := func() []string {
args := []string{"rev-parse"} return []string{"rev-parse", "--path-format=absolute"}
if version.IsAtLeast(2, 31, 0) {
args = append(args, "--path-format=absolute")
}
return args
} }
s.before(runner, fs, getRevParseArgs) s.before(runner, fs, getRevParseArgs)

View File

@ -41,20 +41,18 @@ var CreateAmendCommit = NewIntegrationTest(NewIntegrationTestArgs{
Contains("commit 01"), Contains("commit 01"),
) )
if t.Git().Version().IsAtLeast(2, 32, 0) { // Support for auto-squashing "amend!" commits was added in git 2.32.0 t.Views().Commits().
t.Views().Commits(). Press(keys.Commits.SquashAboveCommits).
Press(keys.Commits.SquashAboveCommits). Tap(func() {
Tap(func() { t.ExpectPopup().Menu().
t.ExpectPopup().Menu(). Title(Equals("Apply fixup commits")).
Title(Equals("Apply fixup commits")). Select(Contains("Above the selected commit")).
Select(Contains("Above the selected commit")). Confirm()
Confirm() }).
}). Lines(
Lines( Contains("commit 03"),
Contains("commit 03"), Contains("commit 02 amended").IsSelected(),
Contains("commit 02 amended").IsSelected(), Contains("commit 01"),
Contains("commit 01"), )
)
}
}, },
}) })