mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-17 00:18:05 +02:00
Don't show branch marker for head commit unless updateRefs config is on
This commit is contained in:
@ -107,3 +107,7 @@ func (self *ConfigCommands) GetCoreCommentChar() byte {
|
|||||||
|
|
||||||
return '#'
|
return '#'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *ConfigCommands) GetRebaseUpdateRefs() bool {
|
||||||
|
return self.gitConfig.GetBool("rebase.updateRefs")
|
||||||
|
}
|
||||||
|
@ -38,12 +38,14 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
showYouAreHereLabel := c.Model().WorkingTreeStateAtLastCommitRefresh == enums.REBASE_MODE_REBASING
|
showYouAreHereLabel := c.Model().WorkingTreeStateAtLastCommitRefresh == enums.REBASE_MODE_REBASING
|
||||||
|
showBranchMarkerForHeadCommit := c.Git().Config.GetRebaseUpdateRefs()
|
||||||
|
|
||||||
return presentation.GetCommitListDisplayStrings(
|
return presentation.GetCommitListDisplayStrings(
|
||||||
c.Common,
|
c.Common,
|
||||||
c.Model().Commits,
|
c.Model().Commits,
|
||||||
c.Model().Branches,
|
c.Model().Branches,
|
||||||
c.Model().CheckedOutBranch,
|
c.Model().CheckedOutBranch,
|
||||||
|
showBranchMarkerForHeadCommit,
|
||||||
c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
|
c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
|
||||||
c.Modes().CherryPicking.SelectedShaSet(),
|
c.Modes().CherryPicking.SelectedShaSet(),
|
||||||
c.Modes().Diffing.Ref,
|
c.Modes().Diffing.Ref,
|
||||||
|
@ -55,11 +55,13 @@ func NewSubCommitsContext(
|
|||||||
if viewModel.GetShowBranchHeads() {
|
if viewModel.GetShowBranchHeads() {
|
||||||
branches = c.Model().Branches
|
branches = c.Model().Branches
|
||||||
}
|
}
|
||||||
|
showBranchMarkerForHeadCommit := c.Git().Config.GetRebaseUpdateRefs()
|
||||||
return presentation.GetCommitListDisplayStrings(
|
return presentation.GetCommitListDisplayStrings(
|
||||||
c.Common,
|
c.Common,
|
||||||
c.Model().SubCommits,
|
c.Model().SubCommits,
|
||||||
branches,
|
branches,
|
||||||
viewModel.GetRef().RefName(),
|
viewModel.GetRef().RefName(),
|
||||||
|
showBranchMarkerForHeadCommit,
|
||||||
c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
|
c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
|
||||||
c.Modes().CherryPicking.SelectedShaSet(),
|
c.Modes().CherryPicking.SelectedShaSet(),
|
||||||
c.Modes().Diffing.Ref,
|
c.Modes().Diffing.Ref,
|
||||||
|
@ -41,6 +41,7 @@ func GetCommitListDisplayStrings(
|
|||||||
commits []*models.Commit,
|
commits []*models.Commit,
|
||||||
branches []*models.Branch,
|
branches []*models.Branch,
|
||||||
currentBranchName string,
|
currentBranchName string,
|
||||||
|
showBranchMarkerForHeadCommit bool,
|
||||||
fullDescription bool,
|
fullDescription bool,
|
||||||
cherryPickedCommitShaSet *set.Set[string],
|
cherryPickedCommitShaSet *set.Set[string],
|
||||||
diffName string,
|
diffName string,
|
||||||
@ -106,6 +107,9 @@ func GetCommitListDisplayStrings(
|
|||||||
// that are not the current branch, and not any of the main branches. The
|
// that are not the current branch, and not any of the main branches. The
|
||||||
// goal is to visualize stacks of local branches, so anything that doesn't
|
// goal is to visualize stacks of local branches, so anything that doesn't
|
||||||
// contribute to a branch stack shouldn't show a marker.
|
// contribute to a branch stack shouldn't show a marker.
|
||||||
|
//
|
||||||
|
// If there are other branches pointing to the current head commit, we only
|
||||||
|
// want to show the marker if the rebase.updateRefs config is on.
|
||||||
branchHeadsToVisualize := set.NewFromSlice(lo.FilterMap(branches,
|
branchHeadsToVisualize := set.NewFromSlice(lo.FilterMap(branches,
|
||||||
func(b *models.Branch, index int) (string, bool) {
|
func(b *models.Branch, index int) (string, bool) {
|
||||||
return b.CommitHash,
|
return b.CommitHash,
|
||||||
@ -116,7 +120,10 @@ func GetCommitListDisplayStrings(
|
|||||||
// Don't show a marker for the current branch
|
// Don't show a marker for the current branch
|
||||||
b.Name != currentBranchName &&
|
b.Name != currentBranchName &&
|
||||||
// Don't show a marker for main branches
|
// Don't show a marker for main branches
|
||||||
!lo.Contains(common.UserConfig.Git.MainBranches, b.Name)
|
!lo.Contains(common.UserConfig.Git.MainBranches, b.Name) &&
|
||||||
|
// Don't show a marker for the head commit unless the
|
||||||
|
// rebase.updateRefs config is on
|
||||||
|
(showBranchMarkerForHeadCommit || b.CommitHash != commits[0].Sha)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
lines := make([][]string, 0, len(filteredCommits))
|
lines := make([][]string, 0, len(filteredCommits))
|
||||||
|
@ -30,6 +30,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
|||||||
commits []*models.Commit
|
commits []*models.Commit
|
||||||
branches []*models.Branch
|
branches []*models.Branch
|
||||||
currentBranchName string
|
currentBranchName string
|
||||||
|
hasUpdateRefConfig bool
|
||||||
fullDescription bool
|
fullDescription bool
|
||||||
cherryPickedCommitShaSet *set.Set[string]
|
cherryPickedCommitShaSet *set.Set[string]
|
||||||
diffName string
|
diffName string
|
||||||
@ -106,6 +107,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
|||||||
{Name: "old-branch", CommitHash: "sha4", Head: false},
|
{Name: "old-branch", CommitHash: "sha4", Head: false},
|
||||||
},
|
},
|
||||||
currentBranchName: "current-branch",
|
currentBranchName: "current-branch",
|
||||||
|
hasUpdateRefConfig: true,
|
||||||
startIdx: 0,
|
startIdx: 0,
|
||||||
length: 4,
|
length: 4,
|
||||||
showGraph: false,
|
showGraph: false,
|
||||||
@ -119,6 +121,52 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
|||||||
sha4 commit4
|
sha4 commit4
|
||||||
`),
|
`),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
testName: "show local branch head for head commit if updateRefs is on",
|
||||||
|
commits: []*models.Commit{
|
||||||
|
{Name: "commit1", Sha: "sha1"},
|
||||||
|
{Name: "commit2", Sha: "sha2"},
|
||||||
|
},
|
||||||
|
branches: []*models.Branch{
|
||||||
|
{Name: "current-branch", CommitHash: "sha1", Head: true},
|
||||||
|
{Name: "other-branch", CommitHash: "sha1", Head: false},
|
||||||
|
},
|
||||||
|
currentBranchName: "current-branch",
|
||||||
|
hasUpdateRefConfig: true,
|
||||||
|
startIdx: 0,
|
||||||
|
length: 2,
|
||||||
|
showGraph: false,
|
||||||
|
bisectInfo: git_commands.NewNullBisectInfo(),
|
||||||
|
cherryPickedCommitShaSet: set.New[string](),
|
||||||
|
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||||
|
expected: formatExpected(`
|
||||||
|
sha1 * commit1
|
||||||
|
sha2 commit2
|
||||||
|
`),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "don't show local branch head for head commit if updateRefs is off",
|
||||||
|
commits: []*models.Commit{
|
||||||
|
{Name: "commit1", Sha: "sha1"},
|
||||||
|
{Name: "commit2", Sha: "sha2"},
|
||||||
|
},
|
||||||
|
branches: []*models.Branch{
|
||||||
|
{Name: "current-branch", CommitHash: "sha1", Head: true},
|
||||||
|
{Name: "other-branch", CommitHash: "sha1", Head: false},
|
||||||
|
},
|
||||||
|
currentBranchName: "current-branch",
|
||||||
|
hasUpdateRefConfig: false,
|
||||||
|
startIdx: 0,
|
||||||
|
length: 2,
|
||||||
|
showGraph: false,
|
||||||
|
bisectInfo: git_commands.NewNullBisectInfo(),
|
||||||
|
cherryPickedCommitShaSet: set.New[string](),
|
||||||
|
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||||
|
expected: formatExpected(`
|
||||||
|
sha1 commit1
|
||||||
|
sha2 commit2
|
||||||
|
`),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
testName: "show local branch head and tag if both exist",
|
testName: "show local branch head and tag if both exist",
|
||||||
commits: []*models.Commit{
|
commits: []*models.Commit{
|
||||||
@ -356,6 +404,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
|||||||
s.commits,
|
s.commits,
|
||||||
s.branches,
|
s.branches,
|
||||||
s.currentBranchName,
|
s.currentBranchName,
|
||||||
|
s.hasUpdateRefConfig,
|
||||||
s.fullDescription,
|
s.fullDescription,
|
||||||
s.cherryPickedCommitShaSet,
|
s.cherryPickedCommitShaSet,
|
||||||
s.diffName,
|
s.diffName,
|
||||||
|
Reference in New Issue
Block a user