Skip to content

Commit 068fbf3

Browse files
committed
Don't show branch marker for head commit unless updateRefs config is on
1 parent 71cddf4 commit 068fbf3

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

pkg/commands/git_commands/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,7 @@ func (self *ConfigCommands) GetCoreCommentChar() byte {
107107

108108
return '#'
109109
}
110+
111+
func (self *ConfigCommands) GetRebaseUpdateRefs() bool {
112+
return self.gitConfig.GetBool("rebase.updateRefs")
113+
}

pkg/gui/context/local_commits_context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
3838
}
3939

4040
showYouAreHereLabel := c.Model().WorkingTreeStateAtLastCommitRefresh == enums.REBASE_MODE_REBASING
41+
showBranchMarkerForHeadCommit := c.Git().Config.GetRebaseUpdateRefs()
4142

4243
return presentation.GetCommitListDisplayStrings(
4344
c.Common,
4445
c.Model().Commits,
4546
c.Model().Branches,
4647
c.Model().CheckedOutBranch,
48+
showBranchMarkerForHeadCommit,
4749
c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
4850
c.Modes().CherryPicking.SelectedShaSet(),
4951
c.Modes().Diffing.Ref,

pkg/gui/context/sub_commits_context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ func NewSubCommitsContext(
5555
if viewModel.GetShowBranchHeads() {
5656
branches = c.Model().Branches
5757
}
58+
showBranchMarkerForHeadCommit := c.Git().Config.GetRebaseUpdateRefs()
5859
return presentation.GetCommitListDisplayStrings(
5960
c.Common,
6061
c.Model().SubCommits,
6162
branches,
6263
viewModel.GetRef().RefName(),
64+
showBranchMarkerForHeadCommit,
6365
c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
6466
c.Modes().CherryPicking.SelectedShaSet(),
6567
c.Modes().Diffing.Ref,

pkg/gui/presentation/commits.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func GetCommitListDisplayStrings(
4141
commits []*models.Commit,
4242
branches []*models.Branch,
4343
currentBranchName string,
44+
showBranchMarkerForHeadCommit bool,
4445
fullDescription bool,
4546
cherryPickedCommitShaSet *set.Set[string],
4647
diffName string,
@@ -106,6 +107,9 @@ func GetCommitListDisplayStrings(
106107
// that are not the current branch, and not any of the main branches. The
107108
// goal is to visualize stacks of local branches, so anything that doesn't
108109
// contribute to a branch stack shouldn't show a marker.
110+
//
111+
// If there are other branches pointing to the current head commit, we only
112+
// want to show the marker if the rebase.updateRefs config is on.
109113
branchHeadsToVisualize := set.NewFromSlice(lo.FilterMap(branches,
110114
func(b *models.Branch, index int) (string, bool) {
111115
return b.CommitHash,
@@ -116,7 +120,10 @@ func GetCommitListDisplayStrings(
116120
// Don't show a marker for the current branch
117121
b.Name != currentBranchName &&
118122
// Don't show a marker for main branches
119-
!lo.Contains(common.UserConfig.Git.MainBranches, b.Name)
123+
!lo.Contains(common.UserConfig.Git.MainBranches, b.Name) &&
124+
// Don't show a marker for the head commit unless the
125+
// rebase.updateRefs config is on
126+
(showBranchMarkerForHeadCommit || b.CommitHash != commits[0].Sha)
120127
}))
121128

122129
lines := make([][]string, 0, len(filteredCommits))

pkg/gui/presentation/commits_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
3030
commits []*models.Commit
3131
branches []*models.Branch
3232
currentBranchName string
33+
hasUpdateRefConfig bool
3334
fullDescription bool
3435
cherryPickedCommitShaSet *set.Set[string]
3536
diffName string
@@ -106,6 +107,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
106107
{Name: "old-branch", CommitHash: "sha4", Head: false},
107108
},
108109
currentBranchName: "current-branch",
110+
hasUpdateRefConfig: true,
109111
startIdx: 0,
110112
length: 4,
111113
showGraph: false,
@@ -119,6 +121,52 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
119121
sha4 commit4
120122
`),
121123
},
124+
{
125+
testName: "show local branch head for head commit if updateRefs is on",
126+
commits: []*models.Commit{
127+
{Name: "commit1", Sha: "sha1"},
128+
{Name: "commit2", Sha: "sha2"},
129+
},
130+
branches: []*models.Branch{
131+
{Name: "current-branch", CommitHash: "sha1", Head: true},
132+
{Name: "other-branch", CommitHash: "sha1", Head: false},
133+
},
134+
currentBranchName: "current-branch",
135+
hasUpdateRefConfig: true,
136+
startIdx: 0,
137+
length: 2,
138+
showGraph: false,
139+
bisectInfo: git_commands.NewNullBisectInfo(),
140+
cherryPickedCommitShaSet: set.New[string](),
141+
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
142+
expected: formatExpected(`
143+
sha1 * commit1
144+
sha2 commit2
145+
`),
146+
},
147+
{
148+
testName: "don't show local branch head for head commit if updateRefs is off",
149+
commits: []*models.Commit{
150+
{Name: "commit1", Sha: "sha1"},
151+
{Name: "commit2", Sha: "sha2"},
152+
},
153+
branches: []*models.Branch{
154+
{Name: "current-branch", CommitHash: "sha1", Head: true},
155+
{Name: "other-branch", CommitHash: "sha1", Head: false},
156+
},
157+
currentBranchName: "current-branch",
158+
hasUpdateRefConfig: false,
159+
startIdx: 0,
160+
length: 2,
161+
showGraph: false,
162+
bisectInfo: git_commands.NewNullBisectInfo(),
163+
cherryPickedCommitShaSet: set.New[string](),
164+
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
165+
expected: formatExpected(`
166+
sha1 commit1
167+
sha2 commit2
168+
`),
169+
},
122170
{
123171
testName: "show local branch head and tag if both exist",
124172
commits: []*models.Commit{
@@ -356,6 +404,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
356404
s.commits,
357405
s.branches,
358406
s.currentBranchName,
407+
s.hasUpdateRefConfig,
359408
s.fullDescription,
360409
s.cherryPickedCommitShaSet,
361410
s.diffName,

0 commit comments

Comments
 (0)