mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 04:45:47 +02: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:
parent
e6a07b3f03
commit
7e14d88dc9
2 changed files with 45 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
||||||
package custom_commands
|
package custom_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/fsmiamoto/git-todo-parser/todo"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
"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
|
// SessionState captures the current state of the application for use in custom commands
|
||||||
type SessionState struct {
|
type SessionState struct {
|
||||||
SelectedLocalCommit *models.Commit
|
SelectedLocalCommit *Commit
|
||||||
SelectedReflogCommit *models.Commit
|
SelectedReflogCommit *Commit
|
||||||
SelectedSubCommit *models.Commit
|
SelectedSubCommit *Commit
|
||||||
SelectedFile *models.File
|
SelectedFile *models.File
|
||||||
SelectedPath string
|
SelectedPath string
|
||||||
SelectedLocalBranch *models.Branch
|
SelectedLocalBranch *models.Branch
|
||||||
|
@ -41,8 +78,8 @@ func (self *SessionStateLoader) call() *SessionState {
|
||||||
return &SessionState{
|
return &SessionState{
|
||||||
SelectedFile: self.c.Contexts().Files.GetSelectedFile(),
|
SelectedFile: self.c.Contexts().Files.GetSelectedFile(),
|
||||||
SelectedPath: self.c.Contexts().Files.GetSelectedPath(),
|
SelectedPath: self.c.Contexts().Files.GetSelectedPath(),
|
||||||
SelectedLocalCommit: self.c.Contexts().LocalCommits.GetSelected(),
|
SelectedLocalCommit: commitWrapperFromModelCommit(self.c.Contexts().LocalCommits.GetSelected()),
|
||||||
SelectedReflogCommit: self.c.Contexts().ReflogCommits.GetSelected(),
|
SelectedReflogCommit: commitWrapperFromModelCommit(self.c.Contexts().ReflogCommits.GetSelected()),
|
||||||
SelectedLocalBranch: self.c.Contexts().Branches.GetSelected(),
|
SelectedLocalBranch: self.c.Contexts().Branches.GetSelected(),
|
||||||
SelectedRemoteBranch: self.c.Contexts().RemoteBranches.GetSelected(),
|
SelectedRemoteBranch: self.c.Contexts().RemoteBranches.GetSelected(),
|
||||||
SelectedRemote: self.c.Contexts().Remotes.GetSelected(),
|
SelectedRemote: self.c.Contexts().Remotes.GetSelected(),
|
||||||
|
@ -50,7 +87,7 @@ func (self *SessionStateLoader) call() *SessionState {
|
||||||
SelectedStashEntry: self.c.Contexts().Stash.GetSelected(),
|
SelectedStashEntry: self.c.Contexts().Stash.GetSelected(),
|
||||||
SelectedCommitFile: self.c.Contexts().CommitFiles.GetSelectedFile(),
|
SelectedCommitFile: self.c.Contexts().CommitFiles.GetSelectedFile(),
|
||||||
SelectedCommitFilePath: self.c.Contexts().CommitFiles.GetSelectedPath(),
|
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(),
|
SelectedWorktree: self.c.Contexts().Worktrees.GetSelected(),
|
||||||
CheckedOutBranch: self.refsHelper.GetCheckedOutRef(),
|
CheckedOutBranch: self.refsHelper.GetCheckedOutRef(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ var AccessCommitProperties = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
{
|
{
|
||||||
Key: "X",
|
Key: "X",
|
||||||
Context: "commits",
|
Context: "commits",
|
||||||
Command: "printf '%s\n%s' '{{ .SelectedLocalCommit.Name }}' '{{ .SelectedLocalCommit.Hash }}' > file.txt",
|
Command: "printf '%s\n%s\n%s' '{{ .SelectedLocalCommit.Name }}' '{{ .SelectedLocalCommit.Hash }}' '{{ .SelectedLocalCommit.Sha }}' > file.txt",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -32,6 +32,6 @@ var AccessCommitProperties = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
Press("X")
|
Press("X")
|
||||||
|
|
||||||
hash := t.Git().GetCommitHash("HEAD")
|
hash := t.Git().GetCommitHash("HEAD")
|
||||||
t.FileSystem().FileContent("file.txt", Equals(fmt.Sprintf("my change\n%s", hash)))
|
t.FileSystem().FileContent("file.txt", Equals(fmt.Sprintf("my change\n%s\n%s", hash, hash)))
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue