1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

Support both Sha and Hash on commits in custom commands

We achieve this by wrapping the model Commit in a custom struct that provides
both.
This commit is contained in:
Stefan Haller
2024-04-11 18:39:21 +02:00
parent e6a07b3f03
commit 7e14d88dc9
2 changed files with 45 additions and 8 deletions

View File

@ -1,6 +1,7 @@
package custom_commands
import (
"github.com/fsmiamoto/git-todo-parser/todo"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
)
@ -19,11 +20,47 @@ func NewSessionStateLoader(c *helpers.HelperCommon, refsHelper *helpers.RefsHelp
}
}
type Commit struct {
Hash string
Sha string
Name string
Status models.CommitStatus
Action todo.TodoCommand
Tags []string
ExtraInfo string
AuthorName string
AuthorEmail string
UnixTimestamp int64
Divergence models.Divergence
Parents []string
}
func commitWrapperFromModelCommit(commit *models.Commit) *Commit {
if commit == nil {
return nil
}
return &Commit{
Hash: commit.Hash,
Sha: commit.Hash,
Name: commit.Name,
Status: commit.Status,
Action: commit.Action,
Tags: commit.Tags,
ExtraInfo: commit.ExtraInfo,
AuthorName: commit.AuthorName,
AuthorEmail: commit.AuthorEmail,
UnixTimestamp: commit.UnixTimestamp,
Divergence: commit.Divergence,
Parents: commit.Parents,
}
}
// SessionState captures the current state of the application for use in custom commands
type SessionState struct {
SelectedLocalCommit *models.Commit
SelectedReflogCommit *models.Commit
SelectedSubCommit *models.Commit
SelectedLocalCommit *Commit
SelectedReflogCommit *Commit
SelectedSubCommit *Commit
SelectedFile *models.File
SelectedPath string
SelectedLocalBranch *models.Branch
@ -41,8 +78,8 @@ func (self *SessionStateLoader) call() *SessionState {
return &SessionState{
SelectedFile: self.c.Contexts().Files.GetSelectedFile(),
SelectedPath: self.c.Contexts().Files.GetSelectedPath(),
SelectedLocalCommit: self.c.Contexts().LocalCommits.GetSelected(),
SelectedReflogCommit: self.c.Contexts().ReflogCommits.GetSelected(),
SelectedLocalCommit: commitWrapperFromModelCommit(self.c.Contexts().LocalCommits.GetSelected()),
SelectedReflogCommit: commitWrapperFromModelCommit(self.c.Contexts().ReflogCommits.GetSelected()),
SelectedLocalBranch: self.c.Contexts().Branches.GetSelected(),
SelectedRemoteBranch: self.c.Contexts().RemoteBranches.GetSelected(),
SelectedRemote: self.c.Contexts().Remotes.GetSelected(),
@ -50,7 +87,7 @@ func (self *SessionStateLoader) call() *SessionState {
SelectedStashEntry: self.c.Contexts().Stash.GetSelected(),
SelectedCommitFile: self.c.Contexts().CommitFiles.GetSelectedFile(),
SelectedCommitFilePath: self.c.Contexts().CommitFiles.GetSelectedPath(),
SelectedSubCommit: self.c.Contexts().SubCommits.GetSelected(),
SelectedSubCommit: commitWrapperFromModelCommit(self.c.Contexts().SubCommits.GetSelected()),
SelectedWorktree: self.c.Contexts().Worktrees.GetSelected(),
CheckedOutBranch: self.refsHelper.GetCheckedOutRef(),
}