newCommandFactory resolves the OS shell once at factory-build time so per-hook invocations don't pay the shell-detection cost.
()
| 135 | // newCommandFactory resolves the OS shell once at factory-build time so |
| 136 | // per-hook invocations don't pay the shell-detection cost. |
| 137 | func newCommandFactory() HandlerFactory { |
| 138 | shell, shellArgs := shellpath.DetectShell() |
| 139 | return func(env HandlerEnv, hook Hook) (Handler, error) { |
| 140 | if hook.Command == "" { |
| 141 | return nil, errors.New("command hook requires a non-empty command") |
| 142 | } |
| 143 | return &commandHandler{ |
| 144 | workingDir: hookWorkingDir(env.WorkingDir, hook.WorkingDir), |
| 145 | env: hookEnv(env.Env, hook.Env), |
| 146 | shell: shell, |
| 147 | shellArgs: shellArgs, |
| 148 | command: hook.Command, |
| 149 | }, nil |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | // hookWorkingDir resolves the directory a command hook runs in. An |
| 154 | // absolute override wins; a relative override is joined onto the |
no test coverage detected