summaryrefslogtreecommitdiffstats
path: root/pkg/commands
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/commands
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/commands')
-rw-r--r--pkg/commands/git_commands/commit_loader.go2
-rw-r--r--pkg/commands/git_commands/commit_loader_test.go16
-rw-r--r--pkg/commands/git_commands/rebase.go5
-rw-r--r--pkg/commands/models/commit.go11
4 files changed, 21 insertions, 13 deletions
diff --git a/pkg/commands/git_commands/commit_loader.go b/pkg/commands/git_commands/commit_loader.go
index 8c85de402..3b2e52ec4 100644
--- a/pkg/commands/git_commands/commit_loader.go
+++ b/pkg/commands/git_commands/commit_loader.go
@@ -313,7 +313,7 @@ func (self *CommitLoader) getInteractiveRebasingCommits() ([]*models.Commit, err
Sha: t.Commit,
Name: t.Msg,
Status: models.StatusRebasing,
- Action: t.Command.String(),
+ Action: t.Command,
})
}
diff --git a/pkg/commands/git_commands/commit_loader_test.go b/pkg/commands/git_commands/commit_loader_test.go
index dab321753..140541545 100644
--- a/pkg/commands/git_commands/commit_loader_test.go
+++ b/pkg/commands/git_commands/commit_loader_test.go
@@ -79,7 +79,7 @@ func TestGetCommits(t *testing.T) {
Sha: "0eea75e8c631fba6b58135697835d58ba4c18dbc",
Name: "better typing for rebase mode",
Status: models.StatusUnpushed,
- Action: "",
+ Action: models.ActionNone,
Tags: []string{},
ExtraInfo: "(HEAD -> better-tests)",
AuthorName: "Jesse Duffield",
@@ -93,7 +93,7 @@ func TestGetCommits(t *testing.T) {
Sha: "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164",
Name: "fix logging",
Status: models.StatusPushed,
- Action: "",
+ Action: models.ActionNone,
Tags: []string{},
ExtraInfo: "(origin/better-tests)",
AuthorName: "Jesse Duffield",
@@ -107,7 +107,7 @@ func TestGetCommits(t *testing.T) {
Sha: "e94e8fc5b6fab4cb755f29f1bdb3ee5e001df35c",
Name: "refactor",
Status: models.StatusPushed,
- Action: "",
+ Action: models.ActionNone,
Tags: []string{},
ExtraInfo: "",
AuthorName: "Jesse Duffield",
@@ -121,7 +121,7 @@ func TestGetCommits(t *testing.T) {
Sha: "d8084cd558925eb7c9c38afeed5725c21653ab90",
Name: "WIP",
Status: models.StatusPushed,
- Action: "",
+ Action: models.ActionNone,
Tags: []string{},
ExtraInfo: "",
AuthorName: "Jesse Duffield",
@@ -135,7 +135,7 @@ func TestGetCommits(t *testing.T) {
Sha: "65f910ebd85283b5cce9bf67d03d3f1a9ea3813a",
Name: "WIP",
Status: models.StatusPushed,
- Action: "",
+ Action: models.ActionNone,
Tags: []string{},
ExtraInfo: "",
AuthorName: "Jesse Duffield",
@@ -149,7 +149,7 @@ func TestGetCommits(t *testing.T) {
Sha: "26c07b1ab33860a1a7591a0638f9925ccf497ffa",
Name: "WIP",
Status: models.StatusMerged,
- Action: "",
+ Action: models.ActionNone,
Tags: []string{},
ExtraInfo: "",
AuthorName: "Jesse Duffield",
@@ -163,7 +163,7 @@ func TestGetCommits(t *testing.T) {
Sha: "3d4470a6c072208722e5ae9a54bcb9634959a1c5",
Name: "WIP",
Status: models.StatusMerged,
- Action: "",
+ Action: models.ActionNone,
Tags: []string{},
ExtraInfo: "",
AuthorName: "Jesse Duffield",
@@ -177,7 +177,7 @@ func TestGetCommits(t *testing.T) {
Sha: "053a66a7be3da43aacdc7aa78e1fe757b82c4dd2",
Name: "refactoring the config struct",
Status: models.StatusMerged,
- Action: "",
+ Action: models.ActionNone,
Tags: []string{},
ExtraInfo: "",
AuthorName: "Jesse Duffield",
diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go
index 6af83a27f..1207bdd56 100644
--- a/pkg/commands/git_commands/rebase.go
+++ b/pkg/commands/git_commands/rebase.go
@@ -6,6 +6,7 @@ import (
"path/filepath"
"strings"
+ "github.com/fsmiamoto/git-todo-parser/todo"
"github.com/go-errors/errors"
"github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/app/daemon"
@@ -202,7 +203,7 @@ func (self *RebaseCommands) AmendTo(commit *models.Commit) error {
}
// EditRebaseTodo sets the action at a given index in the git-rebase-todo file
-func (self *RebaseCommands) EditRebaseTodo(index int, action string) error {
+func (self *RebaseCommands) EditRebaseTodo(index int, action todo.TodoCommand) error {
fileName := filepath.Join(self.dotGitDir, "rebase-merge/git-rebase-todo")
bytes, err := os.ReadFile(fileName)
if err != nil {
@@ -216,7 +217,7 @@ func (self *RebaseCommands) EditRebaseTodo(index int, action string) error {
// it at the bottom, so we need to subtract our index from the commit count
contentIndex := commitCount - 1 - index
splitLine := strings.Split(content[contentIndex], " ")
- content[contentIndex] = action + " " + strings.Join(splitLine[1:], " ")
+ content[contentIndex] = action.String() + " " + strings.Join(splitLine[1:], " ")
result := strings.Join(content, "\n")
return os.WriteFile(fileName, []byte(result), 0o644)
diff --git a/pkg/commands/models/commit.go b/pkg/commands/models/commit.go
index adc7a5a51..e0ff875a0 100644
--- a/pkg/commands/models/commit.go
+++ b/pkg/commands/models/commit.go
@@ -3,6 +3,7 @@ package models
import (
"fmt"
+ "github.com/fsmiamoto/git-todo-parser/todo"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@@ -21,12 +22,18 @@ const (
StatusReflog
)
+const (
+ // Conveniently for us, the todo package starts the enum at 1, and given
+ // that it doesn't have a "none" value, we're setting ours to 0
+ ActionNone todo.TodoCommand = 0
+)
+
// Commit : A git commit
type Commit struct {
Sha string
Name string
Status CommitStatus
- Action string // one of "", "pick", "edit", "squash", "reword", "drop", "fixup"
+ Action todo.TodoCommand
Tags []string
ExtraInfo string // something like 'HEAD -> master, tag: v0.15.2'
AuthorName string // something like 'Jesse Duffield'
@@ -75,7 +82,7 @@ func (c *Commit) IsMerge() bool {
// returns true if this commit is not actually in the git log but instead
// is from a TODO file for an interactive rebase.
func (c *Commit) IsTODO() bool {
- return c.Action != ""
+ return c.Action != ActionNone
}
func IsHeadCommit(commits []*Commit, index int) bool {