Skip to content

Section headers for rebase todos and actual commits #4463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: revert-range-selection-of-commits
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/commands/git_commands/commit_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func (self *CommitLoader) getSequencerCommits() []*models.Commit {
commits = utils.Prepend(commits, &models.Commit{
Hash: t.Commit,
Name: t.Msg,
Status: models.StatusRebasing,
Status: models.StatusCherryPickingOrReverting,
Action: t.Command,
})
}
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/models/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
StatusPushed
StatusMerged
StatusRebasing
StatusCherryPickingOrReverting
StatusConflicted
StatusReflog
)
Expand Down
2 changes: 2 additions & 0 deletions pkg/gui/context/list_context_trait.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type ListContextTrait struct {
func (self *ListContextTrait) IsListContext() {}

func (self *ListContextTrait) FocusLine() {
self.Context.FocusLine()

// Doing this at the end of the layout function because we need the view to be
// resized before we focus the line, otherwise if we're in accordion mode
// the view could be squashed and won't how to adjust the cursor/origin.
Expand Down
49 changes: 47 additions & 2 deletions pkg/gui/context/local_commits_context.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package context

import (
"fmt"
"log"
"strings"
"time"
Expand Down Expand Up @@ -40,7 +41,6 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
}
}

showYouAreHereLabel := c.Model().WorkingTreeStateAtLastCommitRefresh.CanShowTodos()
hasRebaseUpdateRefsConfig := c.Git().Config.GetRebaseUpdateRefs()

return presentation.GetCommitListDisplayStrings(
Expand All @@ -62,10 +62,54 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
endIdx,
shouldShowGraph(c),
c.Model().BisectInfo,
showYouAreHereLabel,
)
}

getNonModelItems := func() []*NonModelItem {
result := []*NonModelItem{}
if c.Model().WorkingTreeStateAtLastCommitRefresh.CanShowTodos() {
if c.Model().WorkingTreeStateAtLastCommitRefresh.Rebasing {
result = append(result, &NonModelItem{
Index: 0,
Content: fmt.Sprintf("--- %s ---", c.Tr.PendingRebaseTodosSectionHeader),
})
}

if c.Model().WorkingTreeStateAtLastCommitRefresh.CherryPicking ||
c.Model().WorkingTreeStateAtLastCommitRefresh.Reverting {
_, firstCherryPickOrRevertTodo, found := lo.FindIndexOf(
c.Model().Commits, func(c *models.Commit) bool {
return c.Status == models.StatusCherryPickingOrReverting ||
c.Status == models.StatusConflicted
})
if !found {
firstCherryPickOrRevertTodo = 0
}
label := lo.Ternary(c.Model().WorkingTreeStateAtLastCommitRefresh.CherryPicking,
c.Tr.PendingCherryPicksSectionHeader,
c.Tr.PendingRevertsSectionHeader)
result = append(result, &NonModelItem{
Index: firstCherryPickOrRevertTodo,
Content: fmt.Sprintf("--- %s ---", label),
})
}

_, firstRealCommit, found := lo.FindIndexOf(
c.Model().Commits, func(c *models.Commit) bool {
return !c.IsTODO()
})
if !found {
firstRealCommit = 0
}
result = append(result, &NonModelItem{
Index: firstRealCommit,
Content: fmt.Sprintf("--- %s ---", c.Tr.CommitsSectionHeader),
})
}

return result
}

ctx := &LocalCommitsContext{
LocalCommitsViewModel: viewModel,
SearchTrait: NewSearchTrait(c),
Expand All @@ -82,6 +126,7 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
ListRenderer: ListRenderer{
list: viewModel,
getDisplayStrings: getDisplayStrings,
getNonModelItems: getNonModelItems,
},
c: c,
refreshViewportOnChange: true,
Expand Down
3 changes: 3 additions & 0 deletions pkg/gui/context/simple_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func (self *SimpleContext) HandleFocusLost(opts types.OnFocusLostOpts) {
}
}

func (self *SimpleContext) FocusLine() {
}

func (self *SimpleContext) HandleRender() {
if self.handleRenderFunc != nil {
self.handleRenderFunc()
Expand Down
1 change: 0 additions & 1 deletion pkg/gui/context/sub_commits_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func NewSubCommitsContext(
endIdx,
shouldShowGraph(c),
git_commands.NewNullBisectInfo(),
false,
)
}

Expand Down
20 changes: 3 additions & 17 deletions pkg/gui/presentation/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func GetCommitListDisplayStrings(
endIdx int,
showGraph bool,
bisectInfo *git_commands.BisectInfo,
showYouAreHereLabel bool,
) [][]string {
mutex.Lock()
defer mutex.Unlock()
Expand Down Expand Up @@ -185,11 +184,6 @@ func GetCommitListDisplayStrings(
for i, commit := range filteredCommits {
unfilteredIdx := i + startIdx
bisectStatus = getBisectStatus(unfilteredIdx, commit.Hash, bisectInfo, bisectBounds)
isYouAreHereCommit := false
if showYouAreHereLabel && (commit.Status == models.StatusConflicted || unfilteredIdx == rebaseOffset) {
isYouAreHereCommit = true
showYouAreHereLabel = false
}
isMarkedBaseCommit := commit.Hash != "" && commit.Hash == markedBaseCommit
if isMarkedBaseCommit {
willBeRebased = true
Expand All @@ -211,7 +205,6 @@ func GetCommitListDisplayStrings(
fullDescription,
bisectStatus,
bisectInfo,
isYouAreHereCommit,
))
}
return lines
Expand Down Expand Up @@ -364,7 +357,6 @@ func displayCommit(
fullDescription bool,
bisectStatus BisectStatus,
bisectInfo *git_commands.BisectInfo,
isYouAreHereCommit bool,
) []string {
bisectString := getBisectStatusText(bisectStatus, bisectInfo)

Expand Down Expand Up @@ -427,14 +419,8 @@ func displayCommit(
}

mark := ""
if isYouAreHereCommit {
color := style.FgYellow
text := common.Tr.YouAreHere
if commit.Status == models.StatusConflicted {
color = style.FgRed
text = common.Tr.ConflictLabel
}
youAreHere := color.Sprintf("<-- %s ---", text)
if commit.Status == models.StatusConflicted {
youAreHere := style.FgRed.Sprintf("<-- %s ---", common.Tr.ConflictLabel)
mark = fmt.Sprintf("%s ", youAreHere)
} else if isMarkedBaseCommit {
rebaseFromHere := style.FgYellow.Sprint(common.Tr.MarkedCommitMarker)
Expand Down Expand Up @@ -505,7 +491,7 @@ func getHashColor(
hashColor = style.FgYellow
case models.StatusMerged:
hashColor = style.FgGreen
case models.StatusRebasing, models.StatusConflicted:
case models.StatusRebasing, models.StatusCherryPickingOrReverting, models.StatusConflicted:
hashColor = style.FgBlue
case models.StatusReflog:
hashColor = style.FgBlue
Expand Down
39 changes: 2 additions & 37 deletions pkg/gui/presentation/commits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
endIdx int
showGraph bool
bisectInfo *git_commands.BisectInfo
showYouAreHereLabel bool
expected string
focus bool
}{
Expand Down Expand Up @@ -223,12 +222,11 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: true,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
hash1 pick commit1
hash2 pick commit2
hash3 ◯ <-- YOU ARE HERE --- commit3
hash3 ◯ commit3
hash4 ◯ commit4
hash5 ◯ commit5
`),
Expand All @@ -247,11 +245,10 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: true,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
hash2 pick commit2
hash3 ◯ <-- YOU ARE HERE --- commit3
hash3 ◯ commit3
hash4 ◯ commit4
hash5 ◯ commit5
`),
Expand All @@ -270,7 +267,6 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: true,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
hash4 ◯ commit4
Expand All @@ -291,7 +287,6 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: true,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
hash1 pick commit1
Expand All @@ -312,7 +307,6 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: true,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
hash5 ◯ commit5
Expand All @@ -332,33 +326,12 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: true,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
hash1 pick commit1
hash2 pick commit2
`),
},
{
testName: "don't show YOU ARE HERE label when not asked for (e.g. in branches panel)",
commits: []*models.Commit{
{Name: "commit1", Hash: "hash1", Parents: []string{"hash2"}, Action: todo.Pick},
{Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}},
{Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}},
},
startIdx: 0,
endIdx: 3,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: false,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
hash1 pick commit1
hash2 ◯ commit2
hash3 ◯ commit3
`),
},
{
testName: "graph in divergence view - all commits visible",
commits: []*models.Commit{
Expand All @@ -376,7 +349,6 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: false,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
↓ hash1r ◯ commit1
Expand Down Expand Up @@ -406,7 +378,6 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: false,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
↓ hash3r ◯ │ commit3
Expand Down Expand Up @@ -434,7 +405,6 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: false,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
↓ hash1r ◯ commit1
Expand All @@ -461,7 +431,6 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: false,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
↑ hash2l ⏣─╮ commit2
Expand All @@ -487,7 +456,6 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: false,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
↓ hash1r ◯ commit1
Expand All @@ -508,7 +476,6 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: false,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
↑ hash1l ◯ commit1
Expand All @@ -530,7 +497,6 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
showYouAreHereLabel: false,
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
↓ hash1r ◯ commit1
Expand Down Expand Up @@ -596,7 +562,6 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
s.endIdx,
s.showGraph,
s.bisectInfo,
s.showYouAreHereLabel,
)

renderedLines, _ := utils.RenderDisplayStrings(result, nil)
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ type Context interface {

HandleFocus(opts OnFocusOpts)
HandleFocusLost(opts OnFocusLostOpts)
FocusLine()
HandleRender()
HandleRenderToMain()
}
Expand Down Expand Up @@ -173,7 +174,6 @@ type IListContext interface {
ViewIndexToModelIndex(int) int
ModelIndexToViewIndex(int) int

FocusLine()
IsListContext() // used for type switch
RangeSelectEnabled() bool
RenderOnlyVisibleLines() bool
Expand Down
7 changes: 7 additions & 0 deletions pkg/gui/view_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,12 @@ func (gui *Gui) postRefreshUpdate(c types.Context) {

if gui.currentViewName() == c.GetViewName() {
c.HandleFocus(types.OnFocusOpts{})
} else {
// The FocusLine call is included in the HandleFocus method which we
// call for focused views above; but we need to call it here for
// non-focused views to ensure that an inactive selection is painted
// correctly, and that integration tests see the up to date selection
// state.
c.FocusLine()
}
}
10 changes: 8 additions & 2 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,11 @@ type TranslationSet struct {
PullRequestNoUpstream string
ErrorOccurred string
NoRoom string
YouAreHere string
ConflictLabel string
PendingRebaseTodosSectionHeader string
PendingCherryPicksSectionHeader string
PendingRevertsSectionHeader string
CommitsSectionHeader string
YouDied string
RewordNotSupported string
ChangingThisActionIsNotAllowed string
Expand Down Expand Up @@ -1417,8 +1420,11 @@ func EnglishTranslationSet() *TranslationSet {
PullRequestNoUpstream: "Cannot open a pull request for a branch with no upstream",
ErrorOccurred: "An error occurred! Please create an issue at",
NoRoom: "Not enough room",
YouAreHere: "YOU ARE HERE",
ConflictLabel: "CONFLICT",
PendingRebaseTodosSectionHeader: "Pending rebase todos",
PendingCherryPicksSectionHeader: "Pending cherry-picks",
PendingRevertsSectionHeader: "Pending reverts",
CommitsSectionHeader: "Commits",
YouDied: "YOU DIED!",
RewordNotSupported: "Rewording commits while interactively rebasing is not currently supported",
ChangingThisActionIsNotAllowed: "Changing this kind of rebase todo entry is not allowed",
Expand Down
Loading