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:
parent
e3c6887e5d
commit
6af8f278d0
@ -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
|
||||
|
@ -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.git.Status.WorkingTreeState() == 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,
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user