diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 116f63487..a1bbe09a6 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -619,7 +619,8 @@ type CustomCommand struct { // The command to run (using Go template syntax for placeholder values) Command string `yaml:"command" jsonschema:"example=git fetch {{.Form.Remote}} {{.Form.Branch}} && git checkout FETCH_HEAD"` // If true, run the command in a subprocess (e.g. if the command requires user input) - Subprocess bool `yaml:"subprocess"` + // [dev] Pointer to bool so that we can distinguish unset (nil) from false. + Subprocess *bool `yaml:"subprocess"` // A list of prompts that will request user input before running the final command Prompts []CustomCommandPrompt `yaml:"prompts"` // Text to display while waiting for command to finish @@ -627,13 +628,16 @@ type CustomCommand struct { // Label for the custom command when displayed in the keybindings menu Description string `yaml:"description"` // If true, stream the command's output to the Command Log panel - Stream bool `yaml:"stream"` + // [dev] Pointer to bool so that we can distinguish unset (nil) from false. + Stream *bool `yaml:"stream"` // If true, show the command's output in a popup within Lazygit - ShowOutput bool `yaml:"showOutput"` + // [dev] Pointer to bool so that we can distinguish unset (nil) from false. + ShowOutput *bool `yaml:"showOutput"` // The title to display in the popup panel if showOutput is true. If left unset, the command will be used as the title. OutputTitle string `yaml:"outputTitle"` // Actions to take after the command has completed - After CustomCommandAfterHook `yaml:"after"` + // [dev] Pointer so that we can tell whether it appears in the config file + After *CustomCommandAfterHook `yaml:"after"` } type CustomCommandPrompt struct { diff --git a/pkg/gui/services/custom_commands/handler_creator.go b/pkg/gui/services/custom_commands/handler_creator.go index 95de40a2e..9e17ca9fa 100644 --- a/pkg/gui/services/custom_commands/handler_creator.go +++ b/pkg/gui/services/custom_commands/handler_creator.go @@ -261,7 +261,7 @@ func (self *HandlerCreator) finalHandler(customCommand config.CustomCommand, ses cmdObj := self.c.OS().Cmd.NewShell(cmdStr) - if customCommand.Subprocess { + if customCommand.Subprocess != nil && *customCommand.Subprocess { return self.c.RunSubprocessAndRefresh(cmdObj) } @@ -273,7 +273,7 @@ func (self *HandlerCreator) finalHandler(customCommand config.CustomCommand, ses return self.c.WithWaitingStatus(loadingText, func(gocui.Task) error { self.c.LogAction(self.c.Tr.Actions.CustomCommand) - if customCommand.Stream { + if customCommand.Stream != nil && *customCommand.Stream { cmdObj.StreamOutput() } output, err := cmdObj.RunWithOutput() @@ -283,14 +283,14 @@ func (self *HandlerCreator) finalHandler(customCommand config.CustomCommand, ses } if err != nil { - if customCommand.After.CheckForConflicts { + if customCommand.After != nil && customCommand.After.CheckForConflicts { return self.mergeAndRebaseHelper.CheckForConflicts(err) } return err } - if customCommand.ShowOutput { + if customCommand.ShowOutput != nil && *customCommand.ShowOutput { if strings.TrimSpace(output) == "" { output = self.c.Tr.EmptyOutput } diff --git a/pkg/integration/tests/custom_commands/check_for_conflicts.go b/pkg/integration/tests/custom_commands/check_for_conflicts.go index 024f32733..25f1d2097 100644 --- a/pkg/integration/tests/custom_commands/check_for_conflicts.go +++ b/pkg/integration/tests/custom_commands/check_for_conflicts.go @@ -19,7 +19,7 @@ var CheckForConflicts = NewIntegrationTest(NewIntegrationTestArgs{ Key: "m", Context: "localBranches", Command: "git merge {{ .SelectedLocalBranch.Name | quote }}", - After: config.CustomCommandAfterHook{ + After: &config.CustomCommandAfterHook{ CheckForConflicts: true, }, }, diff --git a/pkg/integration/tests/custom_commands/show_output_in_panel.go b/pkg/integration/tests/custom_commands/show_output_in_panel.go index 171a477d8..7f00d8a5b 100644 --- a/pkg/integration/tests/custom_commands/show_output_in_panel.go +++ b/pkg/integration/tests/custom_commands/show_output_in_panel.go @@ -15,18 +15,19 @@ var ShowOutputInPanel = NewIntegrationTest(NewIntegrationTestArgs{ shell.EmptyCommit("my change") }, SetupConfig: func(cfg *config.AppConfig) { + trueVal := true cfg.GetUserConfig().CustomCommands = []config.CustomCommand{ { Key: "X", Context: "commits", Command: "printf '%s' '{{ .SelectedLocalCommit.Name }}'", - ShowOutput: true, + ShowOutput: &trueVal, }, { Key: "Y", Context: "commits", Command: "printf '%s' '{{ .SelectedLocalCommit.Name }}'", - ShowOutput: true, + ShowOutput: &trueVal, OutputTitle: "Subject of commit {{ .SelectedLocalCommit.Hash }}", }, }