diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 804a5bee0..7e6a21656 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -314,7 +314,9 @@ type CustomCommand struct { } type CustomCommandPrompt struct { - Type string `yaml:"type"` // one of 'input', 'menu', or 'confirm' + // one of 'input', 'menu', 'confirm', or 'menuFromCommand' + Type string `yaml:"type"` + Title string `yaml:"title"` // this only apply to input prompts diff --git a/pkg/integration/clients/cli.go b/pkg/integration/clients/cli.go index 76f0c9549..79bb96c4f 100644 --- a/pkg/integration/clients/cli.go +++ b/pkg/integration/clients/cli.go @@ -4,8 +4,11 @@ import ( "log" "os" "os/exec" + "regexp" "strconv" + "strings" + "github.com/jesseduffield/generics/slices" "github.com/jesseduffield/lazygit/pkg/integration/components" "github.com/jesseduffield/lazygit/pkg/integration/tests" ) @@ -47,6 +50,14 @@ func getTestsToRun(testNames []string) []*components.IntegrationTest { return tests.Tests } + testNames = slices.Map(testNames, func(name string) string { + // allowing full test paths to be passed for convenience + return strings.TrimSuffix( + regexp.MustCompile(`.*pkg/integration/tests/`).ReplaceAllString(name, ""), + ".go", + ) + }) + outer: for _, testName := range testNames { // check if our given test name actually exists diff --git a/pkg/integration/tests/custom_commands/basic.go b/pkg/integration/tests/custom_commands/basic.go new file mode 100644 index 000000000..5961dc0c5 --- /dev/null +++ b/pkg/integration/tests/custom_commands/basic.go @@ -0,0 +1,34 @@ +package custom_commands + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var Basic = components.NewIntegrationTest(components.NewIntegrationTestArgs{ + Description: "Using a custom command to create a new file", + ExtraCmdArgs: "", + Skip: false, + SetupRepo: func(shell *components.Shell) {}, + SetupConfig: func(cfg *config.AppConfig) { + cfg.UserConfig.CustomCommands = []config.CustomCommand{ + { + Key: "a", + Context: "files", + Command: "touch myfile", + }, + } + }, + Run: func( + shell *components.Shell, + input *components.Input, + assert *components.Assert, + keys config.KeybindingConfig, + ) { + assert.WorkingTreeFileCount(0) + + input.PressKeys("a") + assert.WorkingTreeFileCount(1) + assert.SelectedLineContains("myfile") + }, +}) diff --git a/pkg/integration/tests/tests.go b/pkg/integration/tests/tests.go index e9794169a..704c2fd5b 100644 --- a/pkg/integration/tests/tests.go +++ b/pkg/integration/tests/tests.go @@ -4,6 +4,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/integration/components" "github.com/jesseduffield/lazygit/pkg/integration/tests/branch" "github.com/jesseduffield/lazygit/pkg/integration/tests/commit" + "github.com/jesseduffield/lazygit/pkg/integration/tests/custom_commands" "github.com/jesseduffield/lazygit/pkg/integration/tests/interactive_rebase" ) @@ -15,4 +16,5 @@ var Tests = []*components.IntegrationTest{ commit.NewBranch, branch.Suggestions, interactive_rebase.One, + custom_commands.Basic, } diff --git a/test/integration/customCommands/config/config.yml b/test/integration/customCommands/config/config.yml deleted file mode 100644 index 33c1d684e..000000000 --- a/test/integration/customCommands/config/config.yml +++ /dev/null @@ -1,18 +0,0 @@ -disableStartupPopups: true -customCommands: - - key : 'N' - description: 'Add file' - command: "echo {{index .PromptResponses 0}} > {{index .PromptResponses 1}}" - context: 'files' - prompts: - - type: 'input' - title: 'File name:' - - type: 'input' - title: 'File content:' -gui: - theme: - activeBorderColor: - - green - - bold - SelectedRangeBgcolor: - - reverse diff --git a/test/integration/customCommands/expected/repo/.git_keep/COMMIT_EDITMSG b/test/integration/customCommands/expected/repo/.git_keep/COMMIT_EDITMSG deleted file mode 100644 index 9daeafb98..000000000 --- a/test/integration/customCommands/expected/repo/.git_keep/COMMIT_EDITMSG +++ /dev/null @@ -1 +0,0 @@ -test diff --git a/test/integration/customCommands/expected/repo/.git_keep/index b/test/integration/customCommands/expected/repo/.git_keep/index deleted file mode 100644 index 1cdf852e0..000000000 Binary files a/test/integration/customCommands/expected/repo/.git_keep/index and /dev/null differ diff --git a/test/integration/customCommands/expected/repo/.git_keep/logs/HEAD b/test/integration/customCommands/expected/repo/.git_keep/logs/HEAD deleted file mode 100644 index db58e88aa..000000000 --- a/test/integration/customCommands/expected/repo/.git_keep/logs/HEAD +++ /dev/null @@ -1 +0,0 @@ -0000000000000000000000000000000000000000 15bdb2c31c825116ad5af06ee25517d90b24f13b CI 1617684452 +1000 commit (initial): test diff --git a/test/integration/customCommands/expected/repo/.git_keep/logs/refs/heads/master b/test/integration/customCommands/expected/repo/.git_keep/logs/refs/heads/master deleted file mode 100644 index db58e88aa..000000000 --- a/test/integration/customCommands/expected/repo/.git_keep/logs/refs/heads/master +++ /dev/null @@ -1 +0,0 @@ -0000000000000000000000000000000000000000 15bdb2c31c825116ad5af06ee25517d90b24f13b CI 1617684452 +1000 commit (initial): test diff --git a/test/integration/customCommands/expected/repo/.git_keep/objects/15/bdb2c31c825116ad5af06ee25517d90b24f13b b/test/integration/customCommands/expected/repo/.git_keep/objects/15/bdb2c31c825116ad5af06ee25517d90b24f13b deleted file mode 100644 index c309d426a..000000000 Binary files a/test/integration/customCommands/expected/repo/.git_keep/objects/15/bdb2c31c825116ad5af06ee25517d90b24f13b and /dev/null differ diff --git a/test/integration/customCommands/expected/repo/.git_keep/objects/20/f11a5545b04a86ca81f7a9967d5207349052d7 b/test/integration/customCommands/expected/repo/.git_keep/objects/20/f11a5545b04a86ca81f7a9967d5207349052d7 deleted file mode 100644 index 368e30f82..000000000 Binary files a/test/integration/customCommands/expected/repo/.git_keep/objects/20/f11a5545b04a86ca81f7a9967d5207349052d7 and /dev/null differ diff --git a/test/integration/customCommands/expected/repo/.git_keep/objects/8a/2e45643093ea7cf7b06382e38470034c24e812 b/test/integration/customCommands/expected/repo/.git_keep/objects/8a/2e45643093ea7cf7b06382e38470034c24e812 deleted file mode 100644 index 78c73ed64..000000000 Binary files a/test/integration/customCommands/expected/repo/.git_keep/objects/8a/2e45643093ea7cf7b06382e38470034c24e812 and /dev/null differ diff --git a/test/integration/customCommands/expected/repo/.git_keep/refs/heads/master b/test/integration/customCommands/expected/repo/.git_keep/refs/heads/master deleted file mode 100644 index ce73a61b4..000000000 --- a/test/integration/customCommands/expected/repo/.git_keep/refs/heads/master +++ /dev/null @@ -1 +0,0 @@ -15bdb2c31c825116ad5af06ee25517d90b24f13b diff --git a/test/integration/customCommands/expected/repo/blah b/test/integration/customCommands/expected/repo/blah deleted file mode 100644 index 20f11a554..000000000 --- a/test/integration/customCommands/expected/repo/blah +++ /dev/null @@ -1 +0,0 @@ -myfile diff --git a/test/integration/customCommands/recording.json b/test/integration/customCommands/recording.json deleted file mode 100644 index f49c696e3..000000000 --- a/test/integration/customCommands/recording.json +++ /dev/null @@ -1 +0,0 @@ -{"KeyEvents":[{"Timestamp":837,"Mod":0,"Key":256,"Ch":78},{"Timestamp":1622,"Mod":0,"Key":256,"Ch":109},{"Timestamp":1798,"Mod":0,"Key":256,"Ch":121},{"Timestamp":1918,"Mod":0,"Key":256,"Ch":102},{"Timestamp":2006,"Mod":0,"Key":256,"Ch":105},{"Timestamp":2078,"Mod":0,"Key":256,"Ch":108},{"Timestamp":2174,"Mod":0,"Key":256,"Ch":101},{"Timestamp":2431,"Mod":0,"Key":13,"Ch":13},{"Timestamp":3246,"Mod":0,"Key":256,"Ch":98},{"Timestamp":3294,"Mod":0,"Key":256,"Ch":108},{"Timestamp":3398,"Mod":0,"Key":256,"Ch":97},{"Timestamp":3462,"Mod":0,"Key":256,"Ch":104},{"Timestamp":3735,"Mod":0,"Key":13,"Ch":13},{"Timestamp":4206,"Mod":0,"Key":256,"Ch":32},{"Timestamp":4421,"Mod":0,"Key":256,"Ch":99},{"Timestamp":4646,"Mod":0,"Key":256,"Ch":116},{"Timestamp":4726,"Mod":0,"Key":256,"Ch":101},{"Timestamp":4886,"Mod":0,"Key":256,"Ch":115},{"Timestamp":4918,"Mod":0,"Key":256,"Ch":116},{"Timestamp":5190,"Mod":0,"Key":13,"Ch":13},{"Timestamp":5550,"Mod":0,"Key":256,"Ch":113}],"ResizeEvents":[{"Timestamp":0,"Width":272,"Height":74}]} \ No newline at end of file diff --git a/test/integration/customCommands/setup.sh b/test/integration/customCommands/setup.sh deleted file mode 100644 index fbd02e952..000000000 --- a/test/integration/customCommands/setup.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -set -e - -cd $1 - -git init - -git config user.email "CI@example.com" -git config user.name "CI" diff --git a/test/integration/customCommands/test.json b/test/integration/customCommands/test.json deleted file mode 100644 index c5c5aaf5c..000000000 --- a/test/integration/customCommands/test.json +++ /dev/null @@ -1 +0,0 @@ -{ "description": "Invoke a custom command that creates a file, and then stage and commit that file", "speed": 5 } diff --git a/test/integration/customCommands/expected/repo/.git_keep/FETCH_HEAD b/test/integration_new/custom_commands/basic/expected/repo/.git_keep/FETCH_HEAD similarity index 100% rename from test/integration/customCommands/expected/repo/.git_keep/FETCH_HEAD rename to test/integration_new/custom_commands/basic/expected/repo/.git_keep/FETCH_HEAD diff --git a/test/integration/customCommands/expected/repo/.git_keep/HEAD b/test/integration_new/custom_commands/basic/expected/repo/.git_keep/HEAD similarity index 100% rename from test/integration/customCommands/expected/repo/.git_keep/HEAD rename to test/integration_new/custom_commands/basic/expected/repo/.git_keep/HEAD diff --git a/test/integration/customCommands/expected/repo/.git_keep/config b/test/integration_new/custom_commands/basic/expected/repo/.git_keep/config similarity index 100% rename from test/integration/customCommands/expected/repo/.git_keep/config rename to test/integration_new/custom_commands/basic/expected/repo/.git_keep/config diff --git a/test/integration/customCommands/expected/repo/.git_keep/description b/test/integration_new/custom_commands/basic/expected/repo/.git_keep/description similarity index 100% rename from test/integration/customCommands/expected/repo/.git_keep/description rename to test/integration_new/custom_commands/basic/expected/repo/.git_keep/description diff --git a/test/integration/customCommands/expected/repo/.git_keep/info/exclude b/test/integration_new/custom_commands/basic/expected/repo/.git_keep/info/exclude similarity index 100% rename from test/integration/customCommands/expected/repo/.git_keep/info/exclude rename to test/integration_new/custom_commands/basic/expected/repo/.git_keep/info/exclude diff --git a/test/integration_new/custom_commands/basic/expected/repo/myfile b/test/integration_new/custom_commands/basic/expected/repo/myfile new file mode 100644 index 000000000..e69de29bb