diff --git a/pkg/commands/git_commands/commit_loader.go b/pkg/commands/git_commands/commit_loader.go index 03fe4e1b2..7ce3f05f7 100644 --- a/pkg/commands/git_commands/commit_loader.go +++ b/pkg/commands/git_commands/commit_loader.go @@ -15,7 +15,6 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/commands/types/enums" "github.com/jesseduffield/lazygit/pkg/common" - "github.com/jesseduffield/lazygit/pkg/gui/style" ) // context: @@ -68,10 +67,6 @@ type GetCommitsOptions struct { func (self *CommitLoader) GetCommits(opts GetCommitsOptions) ([]*models.Commit, error) { commits := []*models.Commit{} var rebasingCommits []*models.Commit - rebaseMode, err := self.getRebaseMode() - if err != nil { - return nil, err - } if opts.IncludeRebaseCommits && opts.FilterPath == "" { var err error @@ -106,12 +101,6 @@ func (self *CommitLoader) GetCommits(opts GetCommitsOptions) ([]*models.Commit, return commits, nil } - if rebaseMode != enums.REBASE_MODE_NONE { - currentCommit := commits[len(rebasingCommits)] - youAreHere := style.FgYellow.Sprintf("<-- %s ---", self.Tr.YouAreHere) - currentCommit.Name = fmt.Sprintf("%s %s", youAreHere, currentCommit.Name) - } - commits, err = self.setCommitMergedStatuses(opts.RefName, commits) if err != nil { return nil, err diff --git a/pkg/gui/list_context_config.go b/pkg/gui/list_context_config.go index d463c2ac5..71308f90d 100644 --- a/pkg/gui/list_context_config.go +++ b/pkg/gui/list_context_config.go @@ -6,6 +6,7 @@ import ( "github.com/jesseduffield/generics/slices" "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" + "github.com/jesseduffield/lazygit/pkg/commands/types/enums" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/presentation" "github.com/jesseduffield/lazygit/pkg/gui/style" @@ -118,7 +119,11 @@ func (gui *Gui) branchCommitsListContext() *context.LocalCommitsContext { selectedCommitSha = selectedCommit.Sha } } + + showYouAreHereLabel := gui.State.Model.WorkingTreeStateAtLastCommitRefresh == enums.REBASE_MODE_REBASING + return presentation.GetCommitListDisplayStrings( + gui.Common, gui.State.Model.Commits, gui.State.ScreenMode != SCREEN_NORMAL, gui.helpers.CherryPick.CherryPickedCommitShaSet(), @@ -130,6 +135,7 @@ func (gui *Gui) branchCommitsListContext() *context.LocalCommitsContext { length, gui.shouldShowGraph(), gui.State.Model.BisectInfo, + showYouAreHereLabel, ) }, OnFocusWrapper(gui.onCommitFocus), @@ -152,6 +158,7 @@ func (gui *Gui) subCommitsListContext() *context.SubCommitsContext { } } return presentation.GetCommitListDisplayStrings( + gui.Common, gui.State.Model.SubCommits, gui.State.ScreenMode != SCREEN_NORMAL, gui.helpers.CherryPick.CherryPickedCommitShaSet(), @@ -163,6 +170,7 @@ func (gui *Gui) subCommitsListContext() *context.SubCommitsContext { length, gui.shouldShowGraph(), git_commands.NewNullBisectInfo(), + false, ) }, nil, diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go index f9bdaee47..77b946a64 100644 --- a/pkg/gui/presentation/commits.go +++ b/pkg/gui/presentation/commits.go @@ -1,11 +1,13 @@ package presentation import ( + "fmt" "strings" "github.com/jesseduffield/generics/set" "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" + "github.com/jesseduffield/lazygit/pkg/common" "github.com/jesseduffield/lazygit/pkg/gui/presentation/authors" "github.com/jesseduffield/lazygit/pkg/gui/presentation/graph" "github.com/jesseduffield/lazygit/pkg/gui/presentation/icons" @@ -32,6 +34,7 @@ type bisectBounds struct { } func GetCommitListDisplayStrings( + common *common.Common, commits []*models.Commit, fullDescription bool, cherryPickedCommitShaSet *set.Set[string], @@ -43,6 +46,7 @@ func GetCommitListDisplayStrings( length int, showGraph bool, bisectInfo *git_commands.BisectInfo, + showYouAreHereLabel bool, ) [][]string { mutex.Lock() defer mutex.Unlock() @@ -95,7 +99,9 @@ func GetCommitListDisplayStrings( for i, commit := range filteredCommits { unfilteredIdx := i + startIdx bisectStatus = getBisectStatus(unfilteredIdx, commit.Sha, bisectInfo, bisectBounds) + isYouAreHereCommit := showYouAreHereLabel && unfilteredIdx == rebaseOffset lines = append(lines, displayCommit( + common, commit, cherryPickedCommitShaSet, diffName, @@ -105,6 +111,7 @@ func GetCommitListDisplayStrings( fullDescription, bisectStatus, bisectInfo, + isYouAreHereCommit, )) } return lines @@ -240,6 +247,7 @@ func getBisectStatusText(bisectStatus BisectStatus, bisectInfo *git_commands.Bis } func displayCommit( + common *common.Common, commit *models.Commit, cherryPickedCommitShaSet *set.Set[string], diffName string, @@ -249,6 +257,7 @@ func displayCommit( fullDescription bool, bisectStatus BisectStatus, bisectInfo *git_commands.BisectInfo, + isYouAreHereCommit bool, ) []string { shaColor := getShaColor(commit, diffName, cherryPickedCommitShaSet, bisectStatus, bisectInfo) bisectString := getBisectStatusText(bisectStatus, bisectInfo) @@ -274,6 +283,11 @@ func displayCommit( name = emoji.Sprint(name) } + if isYouAreHereCommit { + youAreHere := style.FgYellow.Sprintf("<-- %s ---", common.Tr.YouAreHere) + name = fmt.Sprintf("%s %s", youAreHere, name) + } + authorFunc := authors.ShortAuthor if fullDescription { authorFunc = authors.LongAuthor diff --git a/pkg/gui/presentation/commits_test.go b/pkg/gui/presentation/commits_test.go index 158396c2f..4c9efbe15 100644 --- a/pkg/gui/presentation/commits_test.go +++ b/pkg/gui/presentation/commits_test.go @@ -36,6 +36,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { length int showGraph bool bisectInfo *git_commands.BisectInfo + showYouAreHereLabel bool expected string focus bool }{ @@ -101,10 +102,11 @@ func TestGetCommitListDisplayStrings(t *testing.T) { showGraph: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitShaSet: set.New[string](), + showYouAreHereLabel: true, expected: formatExpected(` sha1 pick commit1 sha2 pick commit2 - sha3 ◯ commit3 + sha3 ◯ <-- YOU ARE HERE --- commit3 sha4 ◯ commit4 sha5 ◯ commit5 `), @@ -123,15 +125,16 @@ func TestGetCommitListDisplayStrings(t *testing.T) { showGraph: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitShaSet: set.New[string](), + showYouAreHereLabel: true, expected: formatExpected(` sha2 pick commit2 - sha3 ◯ commit3 + sha3 ◯ <-- YOU ARE HERE --- commit3 sha4 ◯ commit4 sha5 ◯ commit5 `), }, { - testName: "startIdx is passed TODO commits", + testName: "startIdx is past TODO commits", commits: []*models.Commit{ {Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: "pick"}, {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: "pick"}, @@ -144,6 +147,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { showGraph: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitShaSet: set.New[string](), + showYouAreHereLabel: true, expected: formatExpected(` sha4 ◯ commit4 sha5 ◯ commit5 @@ -163,6 +167,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { showGraph: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitShaSet: set.New[string](), + showYouAreHereLabel: true, expected: formatExpected(` sha1 pick commit1 sha2 pick commit2 @@ -182,6 +187,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { showGraph: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitShaSet: set.New[string](), + showYouAreHereLabel: true, expected: formatExpected(` sha5 ◯ commit5 `), @@ -200,11 +206,31 @@ func TestGetCommitListDisplayStrings(t *testing.T) { showGraph: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitShaSet: set.New[string](), + showYouAreHereLabel: true, expected: formatExpected(` sha1 pick commit1 sha2 pick commit2 `), }, + { + testName: "don't show YOU ARE HERE label when not asked for (e.g. in branches panel)", + commits: []*models.Commit{ + {Name: "commit1", Sha: "sha1", Parents: []string{"sha2"}, Action: "pick"}, + {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}}, + {Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}}, + }, + startIdx: 0, + length: 5, + showGraph: true, + bisectInfo: git_commands.NewNullBisectInfo(), + cherryPickedCommitShaSet: set.New[string](), + showYouAreHereLabel: false, + expected: formatExpected(` + sha1 pick commit1 + sha2 ◯ commit2 + sha3 ◯ commit3 + `), + }, { testName: "custom time format", commits: []*models.Commit{ @@ -234,11 +260,14 @@ func TestGetCommitListDisplayStrings(t *testing.T) { } } + common := utils.NewDummyCommon() + for _, s := range scenarios { s := s if !focusing || s.focus { t.Run(s.testName, func(t *testing.T) { result := GetCommitListDisplayStrings( + common, s.commits, s.fullDescription, s.cherryPickedCommitShaSet, @@ -250,6 +279,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { s.length, s.showGraph, s.bisectInfo, + s.showYouAreHereLabel, ) renderedResult := utils.RenderDisplayStrings(result) diff --git a/pkg/gui/refresh.go b/pkg/gui/refresh.go index 77dea9e86..7f7dc4829 100644 --- a/pkg/gui/refresh.go +++ b/pkg/gui/refresh.go @@ -236,6 +236,7 @@ func (gui *Gui) refreshCommitsWithLimit() error { return err } gui.State.Model.Commits = commits + gui.State.Model.WorkingTreeStateAtLastCommitRefresh = gui.git.Status.WorkingTreeState() return gui.c.PostRefreshUpdate(gui.State.Contexts.LocalCommits) } @@ -264,6 +265,7 @@ func (gui *Gui) refreshRebaseCommits() error { return err } gui.State.Model.Commits = updatedCommits + gui.State.Model.WorkingTreeStateAtLastCommitRefresh = gui.git.Status.WorkingTreeState() return gui.c.PostRefreshUpdate(gui.State.Contexts.LocalCommits) } diff --git a/pkg/gui/types/common.go b/pkg/gui/types/common.go index ab8f6b2b8..a55ead4da 100644 --- a/pkg/gui/types/common.go +++ b/pkg/gui/types/common.go @@ -4,6 +4,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" + "github.com/jesseduffield/lazygit/pkg/commands/types/enums" "github.com/jesseduffield/lazygit/pkg/common" "github.com/jesseduffield/lazygit/pkg/config" "github.com/sasha-s/go-deadlock" @@ -154,9 +155,10 @@ type Model struct { // one and the same ReflogCommits []*models.Commit - BisectInfo *git_commands.BisectInfo - RemoteBranches []*models.RemoteBranch - Tags []*models.Tag + BisectInfo *git_commands.BisectInfo + WorkingTreeStateAtLastCommitRefresh enums.RebaseMode + RemoteBranches []*models.RemoteBranch + Tags []*models.Tag // for displaying suggestions while typing in a file name FilesTrie *patricia.Trie