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

Merge pull request #2479 from stefanhaller/fix-you-are-here-issues

This commit is contained in:
Jesse Duffield 2023-03-01 19:21:26 +11:00 committed by GitHub
commit 48acf3818f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 62 additions and 17 deletions

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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)

View File

@ -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)
}

View File

@ -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