mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-19 17:02:18 +03:00
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.
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
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"))
|
|
},
|
|
})
|