diff --git a/internal/config/command.go b/internal/config/command.go index a0412305..79a70f2e 100644 --- a/internal/config/command.go +++ b/internal/config/command.go @@ -21,8 +21,9 @@ type Command struct { Files string `mapstructure:"files" yaml:",omitempty" json:"files,omitempty" toml:"files,omitempty"` Env map[string]string `mapstructure:"env" yaml:",omitempty" json:"env,omitempty" toml:"env,omitempty"` - Root string `mapstructure:"root" yaml:",omitempty" json:"root,omitempty" toml:"root,omitempty"` - Exclude string `mapstructure:"exclude" yaml:",omitempty" json:"exclude,omitempty" toml:"exclude,omitempty"` + Root string `mapstructure:"root" yaml:",omitempty" json:"root,omitempty" toml:"root,omitempty"` + Exclude string `mapstructure:"exclude" yaml:",omitempty" json:"exclude,omitempty" toml:"exclude,omitempty"` + Priority int `mapstructure:"priority" yaml:",omitempty" json:"priority,omitempty" toml:"priority,omitempty"` FailText string `mapstructure:"fail_text" yaml:"fail_text,omitempty" json:"fail_text,omitempty" toml:"fail_text,omitempty"` Interactive bool `mapstructure:"interactive" yaml:",omitempty" json:"interactive,omitempty" toml:"interactive,omitempty"` diff --git a/internal/lefthook/run/runner.go b/internal/lefthook/run/runner.go index 6a8024ee..dbac0a0d 100644 --- a/internal/lefthook/run/runner.go +++ b/internal/lefthook/run/runner.go @@ -255,7 +255,7 @@ func (r *Runner) runScripts(ctx context.Context, dir string) { continue } - if script.Interactive { + if script.Interactive && !r.Hook.Piped { interactiveScripts = append(interactiveScripts, file) continue } @@ -332,7 +332,7 @@ func (r *Runner) runCommands(ctx context.Context) { } } - sortAlnum(commands) + sortAlnum(commands, r.Hook.Commands) interactiveCommands := make([]string, 0) var wg sync.WaitGroup @@ -343,7 +343,7 @@ func (r *Runner) runCommands(ctx context.Context) { continue } - if r.Hook.Commands[name].Interactive { + if r.Hook.Commands[name].Interactive && !r.Hook.Piped { interactiveCommands = append(interactiveCommands, name) continue } @@ -536,8 +536,22 @@ func (r *Runner) logExecute(name string, err error, out io.Reader) { // If the command names starts with letter the command name will be sorted alphabetically. // // []string{"1_command", "10command", "3 command", "command5"} // -> 1_command, 3 command, 10command, command5 -func sortAlnum(strs []string) { +func sortAlnum(strs []string, commands map[string]*config.Command) { sort.SliceStable(strs, func(i, j int) bool { + commandI, iok := commands[strs[i]] + commandJ, jok := commands[strs[j]] + + if iok && jok && (commandI.Priority != 0 || commandJ.Priority != 0) { + if commandI.Priority == 0 { + return false + } + if commandJ.Priority == 0 { + return true + } + + return commandI.Priority < commandJ.Priority + } + numEnds := -1 for idx, ch := range strs[i] { if unicode.IsDigit(ch) {