1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-21 22:43:27 +02:00

Don't put "<--- YOU ARE HERE" in the commit model's name

Instead, derive it from context at display time (if we're rebasing, it's the
first non-todo commit). This fixes the problem that unfolding the current
commit's files in the local commits panel would show junk in the frame's title.

Along the way we make sure to only display the "<--- YOU ARE HERE" string in the
local commits panel; previously it would show for the top commit of a branch or
tag if mid-rebase.
This commit is contained in:
Stefan Haller 2023-02-25 17:12:00 +01:00
parent e3c6887e5d
commit 6af8f278d0
4 changed files with 55 additions and 14 deletions

View File

@ -15,7 +15,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/commands/types/enums" "github.com/jesseduffield/lazygit/pkg/commands/types/enums"
"github.com/jesseduffield/lazygit/pkg/common" "github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/gui/style"
) )
// context: // context:
@ -68,10 +67,6 @@ type GetCommitsOptions struct {
func (self *CommitLoader) GetCommits(opts GetCommitsOptions) ([]*models.Commit, error) { func (self *CommitLoader) GetCommits(opts GetCommitsOptions) ([]*models.Commit, error) {
commits := []*models.Commit{} commits := []*models.Commit{}
var rebasingCommits []*models.Commit var rebasingCommits []*models.Commit
rebaseMode, err := self.getRebaseMode()
if err != nil {
return nil, err
}
if opts.IncludeRebaseCommits && opts.FilterPath == "" { if opts.IncludeRebaseCommits && opts.FilterPath == "" {
var err error var err error
@ -106,12 +101,6 @@ func (self *CommitLoader) GetCommits(opts GetCommitsOptions) ([]*models.Commit,
return commits, nil 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) commits, err = self.setCommitMergedStatuses(opts.RefName, commits)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -6,6 +6,7 @@ import (
"github.com/jesseduffield/generics/slices" "github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/models" "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/context"
"github.com/jesseduffield/lazygit/pkg/gui/presentation" "github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/style"
@ -118,7 +119,11 @@ func (gui *Gui) branchCommitsListContext() *context.LocalCommitsContext {
selectedCommitSha = selectedCommit.Sha selectedCommitSha = selectedCommit.Sha
} }
} }
showYouAreHereLabel := gui.git.Status.WorkingTreeState() == enums.REBASE_MODE_REBASING
return presentation.GetCommitListDisplayStrings( return presentation.GetCommitListDisplayStrings(
gui.Common,
gui.State.Model.Commits, gui.State.Model.Commits,
gui.State.ScreenMode != SCREEN_NORMAL, gui.State.ScreenMode != SCREEN_NORMAL,
gui.helpers.CherryPick.CherryPickedCommitShaSet(), gui.helpers.CherryPick.CherryPickedCommitShaSet(),
@ -130,6 +135,7 @@ func (gui *Gui) branchCommitsListContext() *context.LocalCommitsContext {
length, length,
gui.shouldShowGraph(), gui.shouldShowGraph(),
gui.State.Model.BisectInfo, gui.State.Model.BisectInfo,
showYouAreHereLabel,
) )
}, },
OnFocusWrapper(gui.onCommitFocus), OnFocusWrapper(gui.onCommitFocus),
@ -152,6 +158,7 @@ func (gui *Gui) subCommitsListContext() *context.SubCommitsContext {
} }
} }
return presentation.GetCommitListDisplayStrings( return presentation.GetCommitListDisplayStrings(
gui.Common,
gui.State.Model.SubCommits, gui.State.Model.SubCommits,
gui.State.ScreenMode != SCREEN_NORMAL, gui.State.ScreenMode != SCREEN_NORMAL,
gui.helpers.CherryPick.CherryPickedCommitShaSet(), gui.helpers.CherryPick.CherryPickedCommitShaSet(),
@ -163,6 +170,7 @@ func (gui *Gui) subCommitsListContext() *context.SubCommitsContext {
length, length,
gui.shouldShowGraph(), gui.shouldShowGraph(),
git_commands.NewNullBisectInfo(), git_commands.NewNullBisectInfo(),
false,
) )
}, },
nil, nil,

View File

@ -1,11 +1,13 @@
package presentation package presentation
import ( import (
"fmt"
"strings" "strings"
"github.com/jesseduffield/generics/set" "github.com/jesseduffield/generics/set"
"github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/models" "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/authors"
"github.com/jesseduffield/lazygit/pkg/gui/presentation/graph" "github.com/jesseduffield/lazygit/pkg/gui/presentation/graph"
"github.com/jesseduffield/lazygit/pkg/gui/presentation/icons" "github.com/jesseduffield/lazygit/pkg/gui/presentation/icons"
@ -32,6 +34,7 @@ type bisectBounds struct {
} }
func GetCommitListDisplayStrings( func GetCommitListDisplayStrings(
common *common.Common,
commits []*models.Commit, commits []*models.Commit,
fullDescription bool, fullDescription bool,
cherryPickedCommitShaSet *set.Set[string], cherryPickedCommitShaSet *set.Set[string],
@ -43,6 +46,7 @@ func GetCommitListDisplayStrings(
length int, length int,
showGraph bool, showGraph bool,
bisectInfo *git_commands.BisectInfo, bisectInfo *git_commands.BisectInfo,
showYouAreHereLabel bool,
) [][]string { ) [][]string {
mutex.Lock() mutex.Lock()
defer mutex.Unlock() defer mutex.Unlock()
@ -95,7 +99,9 @@ func GetCommitListDisplayStrings(
for i, commit := range filteredCommits { for i, commit := range filteredCommits {
unfilteredIdx := i + startIdx unfilteredIdx := i + startIdx
bisectStatus = getBisectStatus(unfilteredIdx, commit.Sha, bisectInfo, bisectBounds) bisectStatus = getBisectStatus(unfilteredIdx, commit.Sha, bisectInfo, bisectBounds)
isYouAreHereCommit := showYouAreHereLabel && unfilteredIdx == rebaseOffset
lines = append(lines, displayCommit( lines = append(lines, displayCommit(
common,
commit, commit,
cherryPickedCommitShaSet, cherryPickedCommitShaSet,
diffName, diffName,
@ -105,6 +111,7 @@ func GetCommitListDisplayStrings(
fullDescription, fullDescription,
bisectStatus, bisectStatus,
bisectInfo, bisectInfo,
isYouAreHereCommit,
)) ))
} }
return lines return lines
@ -240,6 +247,7 @@ func getBisectStatusText(bisectStatus BisectStatus, bisectInfo *git_commands.Bis
} }
func displayCommit( func displayCommit(
common *common.Common,
commit *models.Commit, commit *models.Commit,
cherryPickedCommitShaSet *set.Set[string], cherryPickedCommitShaSet *set.Set[string],
diffName string, diffName string,
@ -249,6 +257,7 @@ func displayCommit(
fullDescription bool, fullDescription bool,
bisectStatus BisectStatus, bisectStatus BisectStatus,
bisectInfo *git_commands.BisectInfo, bisectInfo *git_commands.BisectInfo,
isYouAreHereCommit bool,
) []string { ) []string {
shaColor := getShaColor(commit, diffName, cherryPickedCommitShaSet, bisectStatus, bisectInfo) shaColor := getShaColor(commit, diffName, cherryPickedCommitShaSet, bisectStatus, bisectInfo)
bisectString := getBisectStatusText(bisectStatus, bisectInfo) bisectString := getBisectStatusText(bisectStatus, bisectInfo)
@ -274,6 +283,11 @@ func displayCommit(
name = emoji.Sprint(name) name = emoji.Sprint(name)
} }
if isYouAreHereCommit {
youAreHere := style.FgYellow.Sprintf("<-- %s ---", common.Tr.YouAreHere)
name = fmt.Sprintf("%s %s", youAreHere, name)
}
authorFunc := authors.ShortAuthor authorFunc := authors.ShortAuthor
if fullDescription { if fullDescription {
authorFunc = authors.LongAuthor authorFunc = authors.LongAuthor

View File

@ -36,6 +36,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
length int length int
showGraph bool showGraph bool
bisectInfo *git_commands.BisectInfo bisectInfo *git_commands.BisectInfo
showYouAreHereLabel bool
expected string expected string
focus bool focus bool
}{ }{
@ -101,10 +102,11 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true, showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(), bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](), cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: true,
expected: formatExpected(` expected: formatExpected(`
sha1 pick commit1 sha1 pick commit1
sha2 pick commit2 sha2 pick commit2
sha3 commit3 sha3 <-- YOU ARE HERE --- commit3
sha4 commit4 sha4 commit4
sha5 commit5 sha5 commit5
`), `),
@ -123,15 +125,16 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true, showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(), bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](), cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: true,
expected: formatExpected(` expected: formatExpected(`
sha2 pick commit2 sha2 pick commit2
sha3 commit3 sha3 <-- YOU ARE HERE --- commit3
sha4 commit4 sha4 commit4
sha5 commit5 sha5 commit5
`), `),
}, },
{ {
testName: "startIdx is passed TODO commits", testName: "startIdx is past TODO commits",
commits: []*models.Commit{ commits: []*models.Commit{
{Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: "pick"}, {Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: "pick"},
{Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: "pick"}, {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: "pick"},
@ -144,6 +147,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true, showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(), bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](), cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: true,
expected: formatExpected(` expected: formatExpected(`
sha4 commit4 sha4 commit4
sha5 commit5 sha5 commit5
@ -163,6 +167,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true, showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(), bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](), cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: true,
expected: formatExpected(` expected: formatExpected(`
sha1 pick commit1 sha1 pick commit1
sha2 pick commit2 sha2 pick commit2
@ -182,6 +187,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true, showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(), bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](), cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: true,
expected: formatExpected(` expected: formatExpected(`
sha5 commit5 sha5 commit5
`), `),
@ -200,11 +206,31 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true, showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(), bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](), cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: true,
expected: formatExpected(` expected: formatExpected(`
sha1 pick commit1 sha1 pick commit1
sha2 pick commit2 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", testName: "custom time format",
commits: []*models.Commit{ commits: []*models.Commit{
@ -234,11 +260,14 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
} }
} }
common := utils.NewDummyCommon()
for _, s := range scenarios { for _, s := range scenarios {
s := s s := s
if !focusing || s.focus { if !focusing || s.focus {
t.Run(s.testName, func(t *testing.T) { t.Run(s.testName, func(t *testing.T) {
result := GetCommitListDisplayStrings( result := GetCommitListDisplayStrings(
common,
s.commits, s.commits,
s.fullDescription, s.fullDescription,
s.cherryPickedCommitShaSet, s.cherryPickedCommitShaSet,
@ -250,6 +279,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
s.length, s.length,
s.showGraph, s.showGraph,
s.bisectInfo, s.bisectInfo,
s.showYouAreHereLabel,
) )
renderedResult := utils.RenderDisplayStrings(result) renderedResult := utils.RenderDisplayStrings(result)