mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-15 01:34:26 +02:00
Make Commit.Hash a getter for an unexported hash field
This is in preparation for turning the hash into pointer to a string.
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
"github.com/samber/lo"
|
||||
"github.com/stefanhaller/git-todo-parser/todo"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/xo/terminfo"
|
||||
@ -23,7 +24,7 @@ func formatExpected(expected string) string {
|
||||
func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
testName string
|
||||
commits []*models.Commit
|
||||
commitOpts []models.NewCommitOpts
|
||||
branches []*models.Branch
|
||||
currentBranchName string
|
||||
hasUpdateRefConfig bool
|
||||
@ -45,7 +46,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
testName: "no commits",
|
||||
commits: []*models.Commit{},
|
||||
commitOpts: []models.NewCommitOpts{},
|
||||
startIdx: 0,
|
||||
endIdx: 1,
|
||||
showGraph: false,
|
||||
@ -56,7 +57,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "some commits",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1"},
|
||||
{Name: "commit2", Hash: "hash2"},
|
||||
},
|
||||
@ -73,7 +74,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "commit with tags",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1", Tags: []string{"tag1", "tag2"}},
|
||||
{Name: "commit2", Hash: "hash2"},
|
||||
},
|
||||
@ -90,7 +91,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "show local branch head, except the current branch, main branches, or merged branches",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1"},
|
||||
{Name: "commit2", Hash: "hash2"},
|
||||
{Name: "commit3", Hash: "hash3"},
|
||||
@ -119,7 +120,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "show local branch head for head commit if updateRefs is on",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1"},
|
||||
{Name: "commit2", Hash: "hash2"},
|
||||
},
|
||||
@ -142,7 +143,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "don't show local branch head for head commit if updateRefs is off",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1"},
|
||||
{Name: "commit2", Hash: "hash2"},
|
||||
},
|
||||
@ -165,7 +166,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "show local branch head and tag if both exist",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1"},
|
||||
{Name: "commit2", Hash: "hash2", Tags: []string{"some-tag"}},
|
||||
{Name: "commit3", Hash: "hash3"},
|
||||
@ -187,7 +188,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "showing graph",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}},
|
||||
{Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}},
|
||||
{Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}},
|
||||
@ -210,7 +211,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "showing graph, including rebase commits",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}, Action: todo.Pick},
|
||||
{Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}, Action: todo.Pick},
|
||||
{Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}},
|
||||
@ -233,7 +234,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "showing graph, including rebase commits, with offset",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}, Action: todo.Pick},
|
||||
{Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}, Action: todo.Pick},
|
||||
{Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}},
|
||||
@ -255,7 +256,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "startIdx is past TODO commits",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}, Action: todo.Pick},
|
||||
{Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}, Action: todo.Pick},
|
||||
{Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}},
|
||||
@ -275,7 +276,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "only showing TODO commits",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}, Action: todo.Pick},
|
||||
{Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}, Action: todo.Pick},
|
||||
{Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}},
|
||||
@ -295,7 +296,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "no TODO commits, towards bottom",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}},
|
||||
{Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}},
|
||||
{Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}},
|
||||
@ -314,7 +315,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "only TODO commits except last",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}, Action: todo.Pick},
|
||||
{Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}, Action: todo.Pick},
|
||||
{Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}, Action: todo.Pick},
|
||||
@ -334,7 +335,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "graph in divergence view - all commits visible",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1r", Parents: []string{"hash2r"}, Divergence: models.DivergenceRight},
|
||||
{Name: "commit2", Hash: "hash2r", Parents: []string{"hash3r", "hash5r"}, Divergence: models.DivergenceRight},
|
||||
{Name: "commit3", Hash: "hash3r", Parents: []string{"hash4r"}, Divergence: models.DivergenceRight},
|
||||
@ -363,7 +364,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "graph in divergence view - not all remote commits visible",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1r", Parents: []string{"hash2r"}, Divergence: models.DivergenceRight},
|
||||
{Name: "commit2", Hash: "hash2r", Parents: []string{"hash3r", "hash5r"}, Divergence: models.DivergenceRight},
|
||||
{Name: "commit3", Hash: "hash3r", Parents: []string{"hash4r"}, Divergence: models.DivergenceRight},
|
||||
@ -390,7 +391,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "graph in divergence view - not all local commits",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1r", Parents: []string{"hash2r"}, Divergence: models.DivergenceRight},
|
||||
{Name: "commit2", Hash: "hash2r", Parents: []string{"hash3r", "hash5r"}, Divergence: models.DivergenceRight},
|
||||
{Name: "commit3", Hash: "hash3r", Parents: []string{"hash4r"}, Divergence: models.DivergenceRight},
|
||||
@ -416,7 +417,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "graph in divergence view - no remote commits visible",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1r", Parents: []string{"hash2r"}, Divergence: models.DivergenceRight},
|
||||
{Name: "commit2", Hash: "hash2r", Parents: []string{"hash3r", "hash5r"}, Divergence: models.DivergenceRight},
|
||||
{Name: "commit3", Hash: "hash3r", Parents: []string{"hash4r"}, Divergence: models.DivergenceRight},
|
||||
@ -441,7 +442,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "graph in divergence view - no local commits visible",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1r", Parents: []string{"hash2r"}, Divergence: models.DivergenceRight},
|
||||
{Name: "commit2", Hash: "hash2r", Parents: []string{"hash3r", "hash5r"}, Divergence: models.DivergenceRight},
|
||||
{Name: "commit3", Hash: "hash3r", Parents: []string{"hash4r"}, Divergence: models.DivergenceRight},
|
||||
@ -464,7 +465,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "graph in divergence view - no remote commits present",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1l", Parents: []string{"hash2l"}, Divergence: models.DivergenceLeft},
|
||||
{Name: "commit2", Hash: "hash2l", Parents: []string{"hash3l", "hash4l"}, Divergence: models.DivergenceLeft},
|
||||
{Name: "commit3", Hash: "hash3l", Parents: []string{"hash4l"}, Divergence: models.DivergenceLeft},
|
||||
@ -487,7 +488,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "graph in divergence view - no local commits present",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1r", Parents: []string{"hash2r"}, Divergence: models.DivergenceRight},
|
||||
{Name: "commit2", Hash: "hash2r", Parents: []string{"hash3r", "hash5r"}, Divergence: models.DivergenceRight},
|
||||
{Name: "commit3", Hash: "hash3r", Parents: []string{"hash4r"}, Divergence: models.DivergenceRight},
|
||||
@ -506,7 +507,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testName: "custom time format",
|
||||
commits: []*models.Commit{
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit1", Hash: "hash1", UnixTimestamp: 1577844184, AuthorName: "Jesse Duffield"},
|
||||
{Name: "commit2", Hash: "hash2", UnixTimestamp: 1576844184, AuthorName: "Jesse Duffield"},
|
||||
},
|
||||
@ -543,9 +544,12 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
for _, s := range scenarios {
|
||||
if !focusing || s.focus {
|
||||
t.Run(s.testName, func(t *testing.T) {
|
||||
commits := lo.Map(s.commitOpts,
|
||||
func(opts models.NewCommitOpts, _ int) *models.Commit { return models.NewCommit(opts) })
|
||||
|
||||
result := GetCommitListDisplayStrings(
|
||||
common,
|
||||
s.commits,
|
||||
commits,
|
||||
s.branches,
|
||||
s.currentBranchName,
|
||||
s.hasUpdateRefConfig,
|
||||
|
Reference in New Issue
Block a user