mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 04:45:47 +02:00
Expose {{.SelectedCommitRange}} to custom commands
It has fields .To and .From (the hashes of the last and the first selected commits, respectively), and it is useful for creating git commands that act on a range of commits.
This commit is contained in:
parent
d768327814
commit
4baf008ac7
4 changed files with 72 additions and 0 deletions
|
@ -0,0 +1,41 @@
|
|||
package custom_commands
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||
)
|
||||
|
||||
var SelectedCommitRange = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
Description: "Use the {{ .SelectedCommitRange }} template variable",
|
||||
ExtraCmdArgs: []string{},
|
||||
Skip: false,
|
||||
SetupRepo: func(shell *Shell) {
|
||||
shell.CreateNCommits(3)
|
||||
},
|
||||
SetupConfig: func(cfg *config.AppConfig) {
|
||||
cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
|
||||
{
|
||||
Key: "X",
|
||||
Context: "global",
|
||||
Command: `git log --format="%s" {{.SelectedCommitRange.From}}^..{{.SelectedCommitRange.To}} > file.txt`,
|
||||
},
|
||||
}
|
||||
},
|
||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||
t.Views().Commits().Focus().
|
||||
Lines(
|
||||
Contains("commit 03").IsSelected(),
|
||||
Contains("commit 02"),
|
||||
Contains("commit 01"),
|
||||
)
|
||||
|
||||
t.GlobalPress("X")
|
||||
t.FileSystem().FileContent("file.txt", Equals("commit 03\n"))
|
||||
|
||||
t.Views().Commits().Focus().
|
||||
Press(keys.Universal.RangeSelectDown)
|
||||
|
||||
t.GlobalPress("X")
|
||||
t.FileSystem().FileContent("file.txt", Equals("commit 03\ncommit 02\n"))
|
||||
},
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue