diff --git a/internal/lefthook/run/exec/execute_unix.go b/internal/lefthook/run/exec/execute_unix.go index 80ca771c..cff07375 100644 --- a/internal/lefthook/run/exec/execute_unix.go +++ b/internal/lefthook/run/exec/execute_unix.go @@ -28,18 +28,11 @@ type executeArgs struct { interactive, useStdin bool } -type nullReader struct{} - -func (nullReader) Read(b []byte) (int, error) { - if len(b) == 0 { - return 0, nil - } - - return 0, io.EOF -} - func (e CommandExecutor) Execute(ctx context.Context, opts Options, out io.Writer) error { var in io.Reader = nullReader{} + if opts.UseStdin { + in = os.Stdin + } if opts.Interactive && !isatty.IsTerminal(os.Stdin.Fd()) { tty, err := os.Open("/dev/tty") if err == nil { diff --git a/internal/lefthook/run/exec/execute_windows.go b/internal/lefthook/run/exec/execute_windows.go index 4c88c2c0..6b0ca244 100644 --- a/internal/lefthook/run/exec/execute_windows.go +++ b/internal/lefthook/run/exec/execute_windows.go @@ -29,8 +29,13 @@ func (e CommandExecutor) Execute(ctx context.Context, opts Options, out io.Write ) } + var in io.Reader = nullReader{} + if opts.Interactive || opts.UseStdin { + in = os.Stdin + } + args := &executeArgs{ - in: os.Stdin, + in: in, out: out, envs: envs, root: root, diff --git a/internal/lefthook/run/exec/nullReader.go b/internal/lefthook/run/exec/nullReader.go new file mode 100644 index 00000000..dd774b5e --- /dev/null +++ b/internal/lefthook/run/exec/nullReader.go @@ -0,0 +1,10 @@ +package exec + +import "io" + +// nullReader always returns EOF. +type nullReader struct{} + +func (nullReader) Read(b []byte) (int, error) { + return 0, io.EOF +}