-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(custom command): support multiple contexts within one command (#…
…3784) - **PR Description** For some custom commands, they can be used in multiple contexts. But for now, if we want to do this, we should copy and paste the same config times and times with just a different **context**. Related issue: #3759 This PR makes it possible to use multiple contexts in the `context` field of `customCommand`, separated by comma.
- Loading branch information
Showing
6 changed files
with
155 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package custom_commands | ||
|
||
import ( | ||
"github.com/jesseduffield/lazygit/pkg/config" | ||
. "github.com/jesseduffield/lazygit/pkg/integration/components" | ||
) | ||
|
||
var GlobalContext = NewIntegrationTest(NewIntegrationTestArgs{ | ||
Description: "Ensure global context works", | ||
ExtraCmdArgs: []string{}, | ||
Skip: false, | ||
SetupRepo: func(shell *Shell) { | ||
shell.EmptyCommit("my change") | ||
}, | ||
SetupConfig: func(cfg *config.AppConfig) { | ||
cfg.UserConfig.CustomCommands = []config.CustomCommand{ | ||
{ | ||
Key: "X", | ||
Context: "global", | ||
Command: "touch myfile", | ||
ShowOutput: false, | ||
}, | ||
} | ||
}, | ||
Run: func(t *TestDriver, keys config.KeybindingConfig) { | ||
// commits | ||
t.Views().Commits(). | ||
Focus(). | ||
Press("X") | ||
|
||
t.Views().Files(). | ||
Focus(). | ||
Lines(Contains("myfile")) | ||
|
||
t.Shell().DeleteFile("myfile") | ||
t.GlobalPress(keys.Files.RefreshFiles) | ||
|
||
// branches | ||
t.Views().Branches(). | ||
Focus(). | ||
Press("X") | ||
|
||
t.Views().Files(). | ||
Focus(). | ||
Lines(Contains("myfile")) | ||
|
||
t.Shell().DeleteFile("myfile") | ||
t.GlobalPress(keys.Files.RefreshFiles) | ||
|
||
// files | ||
t.Views().Files(). | ||
Focus(). | ||
Press("X") | ||
|
||
t.Views().Files(). | ||
Focus(). | ||
Lines(Contains("myfile")) | ||
|
||
t.Shell().DeleteFile("myfile") | ||
}, | ||
}) |
58 changes: 58 additions & 0 deletions
58
pkg/integration/tests/custom_commands/multiple_contexts.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package custom_commands | ||
|
||
import ( | ||
"github.com/jesseduffield/lazygit/pkg/config" | ||
. "github.com/jesseduffield/lazygit/pkg/integration/components" | ||
) | ||
|
||
var MultipleContexts = NewIntegrationTest(NewIntegrationTestArgs{ | ||
Description: "Test that multiple contexts works", | ||
ExtraCmdArgs: []string{}, | ||
Skip: false, | ||
SetupRepo: func(shell *Shell) { | ||
shell.EmptyCommit("my change") | ||
}, | ||
SetupConfig: func(cfg *config.AppConfig) { | ||
cfg.UserConfig.CustomCommands = []config.CustomCommand{ | ||
{ | ||
Key: "X", | ||
Context: "commits, reflogCommits", | ||
Command: "touch myfile", | ||
ShowOutput: false, | ||
}, | ||
} | ||
}, | ||
Run: func(t *TestDriver, keys config.KeybindingConfig) { | ||
// commits | ||
t.Views().Commits(). | ||
Focus(). | ||
Press("X") | ||
|
||
t.Views().Files(). | ||
Focus(). | ||
Lines(Contains("myfile")) | ||
|
||
t.Shell().DeleteFile("myfile") | ||
t.GlobalPress(keys.Files.RefreshFiles) | ||
|
||
// branches | ||
t.Views().Branches(). | ||
Focus(). | ||
Press("X") | ||
|
||
t.Views().Files(). | ||
Focus(). | ||
IsEmpty() | ||
|
||
// files | ||
t.Views().ReflogCommits(). | ||
Focus(). | ||
Press("X") | ||
|
||
t.Views().Files(). | ||
Focus(). | ||
Lines(Contains("myfile")) | ||
|
||
t.Shell().DeleteFile("myfile") | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters