summaryrefslogtreecommitdiffstats
path: root/pkg/gui
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2023-04-03 12:42:29 +0200
committerStefan Haller <stefan@haller-berlin.de>2023-04-15 08:36:03 +0200
commitc53c5e47efc36c1b9bf9fa51f4840caf70ceba28 (patch)
tree1e73755450cf491271eca9653c4a2715fcd3a8c9 /pkg/gui
parent188773511e0c94a4ec338328865e824402ec8b00 (diff)
Store commit.Action as an enum instead of a string
The main reason for doing this (besides the reasons given for Status in the previous commit) is that it allows us to easily convert from TodoCommand to Action and back. This will be needed later in the branch. Fortunately, TodoCommand is one-based, so this allows us to add an ActionNone constant with the value 0.
Diffstat (limited to 'pkg/gui')
-rw-r--r--pkg/gui/controllers/local_commits_controller.go23
-rw-r--r--pkg/gui/presentation/commits.go18
-rw-r--r--pkg/gui/presentation/commits_test.go27
3 files changed, 36 insertions, 32 deletions
diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go
index 284534ffa..7afb7e0ed 100644
--- a/pkg/gui/controllers/local_commits_controller.go
+++ b/pkg/gui/controllers/local_commits_controller.go
@@ -3,6 +3,7 @@ package controllers
import (
"fmt"
+ "github.com/fsmiamoto/git-todo-parser/todo"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
"github.com/jesseduffield/lazygit/pkg/gui/context"
@@ -153,7 +154,7 @@ func (self *LocalCommitsController) squashDown(commit *models.Commit) error {
return self.c.ErrorMsg(self.c.Tr.CannotSquashOrFixupFirstCommit)
}
- applied, err := self.handleMidRebaseCommand("squash", commit)
+ applied, err := self.handleMidRebaseCommand(todo.Squash, commit)
if err != nil {
return err
}
@@ -178,7 +179,7 @@ func (self *LocalCommitsController) fixup(commit *models.Commit) error {
return self.c.ErrorMsg(self.c.Tr.CannotSquashOrFixupFirstCommit)
}
- applied, err := self.handleMidRebaseCommand("fixup", commit)
+ applied, err := self.handleMidRebaseCommand(todo.Fixup, commit)
if err != nil {
return err
}
@@ -199,7 +200,7 @@ func (self *LocalCommitsController) fixup(commit *models.Commit) error {
}
func (self *LocalCommitsController) reword(commit *models.Commit) error {
- applied, err := self.handleMidRebaseCommand("reword", commit)
+ applied, err := self.handleMidRebaseCommand(todo.Reword, commit)
if err != nil {
return err
}
@@ -248,7 +249,7 @@ func (self *LocalCommitsController) doRewordEditor() error {
}
func (self *LocalCommitsController) rewordEditor(commit *models.Commit) error {
- midRebase, err := self.handleMidRebaseCommand("reword", commit)
+ midRebase, err := self.handleMidRebaseCommand(todo.Reword, commit)
if err != nil {
return err
}
@@ -268,7 +269,7 @@ func (self *LocalCommitsController) rewordEditor(commit *models.Commit) error {
}
func (self *LocalCommitsController) drop(commit *models.Commit) error {
- applied, err := self.handleMidRebaseCommand("drop", commit)
+ applied, err := self.handleMidRebaseCommand(todo.Drop, commit)
if err != nil {
return err
}
@@ -289,7 +290,7 @@ func (self *LocalCommitsController) drop(commit *models.Commit) error {
}
func (self *LocalCommitsController) edit(commit *models.Commit) error {
- applied, err := self.handleMidRebaseCommand("edit", commit)
+ applied, err := self.handleMidRebaseCommand(todo.Edit, commit)
if err != nil {
return err
}
@@ -305,7 +306,7 @@ func (self *LocalCommitsController) edit(commit *models.Commit) error {
}
func (self *LocalCommitsController) pick(commit *models.Commit) error {
- applied, err := self.handleMidRebaseCommand("pick", commit)
+ applied, err := self.handleMidRebaseCommand(todo.Pick, commit)
if err != nil {
return err
}
@@ -326,12 +327,12 @@ func (self *LocalCommitsController) interactiveRebase(action string) error {
// handleMidRebaseCommand sees if the selected commit is in fact a rebasing
// commit meaning you are trying to edit the todo file rather than actually
// begin a rebase. It then updates the todo file with that action
-func (self *LocalCommitsController) handleMidRebaseCommand(action string, commit *models.Commit) (bool, error) {
+func (self *LocalCommitsController) handleMidRebaseCommand(action todo.TodoCommand, commit *models.Commit) (bool, error) {
if !commit.IsTODO() {
if self.git.Status.WorkingTreeState() != enums.REBASE_MODE_NONE {
// If we are in a rebase, the only action that is allowed for
// non-todo commits is rewording the current head commit
- if !(action == "reword" && self.isHeadCommit()) {
+ if !(action == todo.Reword && self.isHeadCommit()) {
return true, self.c.ErrorMsg(self.c.Tr.AlreadyRebasing)
}
}
@@ -343,13 +344,13 @@ func (self *LocalCommitsController) handleMidRebaseCommand(action string, commit
// and that means we either unconditionally wait around for the subprocess to ask for
// our input or we set a lazygit client as the EDITOR env variable and have it
// request us to edit the commit message when prompted.
- if action == "reword" {
+ if action == todo.Reword {
return true, self.c.ErrorMsg(self.c.Tr.LcRewordNotSupported)
}
self.c.LogAction("Update rebase TODO")
self.c.LogCommand(
- fmt.Sprintf("Updating rebase action of commit %s to '%s'", commit.ShortSha(), action),
+ fmt.Sprintf("Updating rebase action of commit %s to '%s'", commit.ShortSha(), action.String()),
false,
)
diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go
index f7d3e1308..7875d51da 100644
--- a/pkg/gui/presentation/commits.go
+++ b/pkg/gui/presentation/commits.go
@@ -4,6 +4,7 @@ import (
"fmt"
"strings"
+ "github.com/fsmiamoto/git-todo-parser/todo"
"github.com/jesseduffield/generics/set"
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/models"
@@ -263,8 +264,9 @@ func displayCommit(
bisectString := getBisectStatusText(bisectStatus, bisectInfo)
actionString := ""
- if commit.Action != "" {
- actionString = actionColorMap(commit.Action).Sprint(commit.Action) + " "
+ if commit.Action != models.ActionNone {
+ todoString := commit.Action.String()
+ actionString = actionColorMap(commit.Action).Sprint(todoString) + " "
}
tagString := ""
@@ -368,15 +370,15 @@ func getShaColor(
return shaColor
}
-func actionColorMap(str string) style.TextStyle {
- switch str {
- case "pick":
+func actionColorMap(action todo.TodoCommand) style.TextStyle {
+ switch action {
+ case todo.Pick:
return style.FgCyan
- case "drop":
+ case todo.Drop:
return style.FgRed
- case "edit":
+ case todo.Edit:
return style.FgGreen
- case "fixup":
+ case todo.Fixup:
return style.FgMagenta
default:
return style.FgYellow
diff --git a/pkg/gui/presentation/commits_test.go b/pkg/gui/presentation/commits_test.go
index 4c9efbe15..55155a704 100644
--- a/pkg/gui/presentation/commits_test.go
+++ b/pkg/gui/presentation/commits_test.go
@@ -5,6 +5,7 @@ import (
"strings"
"testing"
+ "github.com/fsmiamoto/git-todo-parser/todo"
"github.com/gookit/color"
"github.com/jesseduffield/generics/set"
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
@@ -91,8 +92,8 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
{
testName: "showing graph, including rebase commits",
commits: []*models.Commit{
- {Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: "pick"},
- {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: "pick"},
+ {Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick},
+ {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: todo.Pick},
{Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}},
{Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}},
{Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}},
@@ -114,8 +115,8 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
{
testName: "showing graph, including rebase commits, with offset",
commits: []*models.Commit{
- {Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: "pick"},
- {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: "pick"},
+ {Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick},
+ {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: todo.Pick},
{Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}},
{Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}},
{Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}},
@@ -136,8 +137,8 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
{
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"},
+ {Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick},
+ {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: todo.Pick},
{Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}},
{Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}},
{Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}},
@@ -156,8 +157,8 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
{
testName: "only showing TODO commits",
commits: []*models.Commit{
- {Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: "pick"},
- {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: "pick"},
+ {Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick},
+ {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: todo.Pick},
{Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}},
{Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}},
{Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}},
@@ -195,10 +196,10 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
{
testName: "only TODO commits except last",
commits: []*models.Commit{
- {Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: "pick"},
- {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: "pick"},
- {Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}, Action: "pick"},
- {Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}, Action: "pick"},
+ {Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick},
+ {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: todo.Pick},
+ {Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}, Action: todo.Pick},
+ {Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}, Action: todo.Pick},
{Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}},
},
startIdx: 0,
@@ -215,7 +216,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
{
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: "commit1", Sha: "sha1", Parents: []string{"sha2"}, Action: todo.Pick},
{Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}},
{Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}},
},