Skip to content

Commit

Permalink
fix: use empty stdin by default (#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox committed Nov 30, 2023
1 parent 96e1fb5 commit 5703093
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## master (unreleased)

- fix: use empty stdin by default ([#590](https://github.com/evilmartians/lefthook/pull/590)) by @mrexox
- feat: add priorities to commands ([#589](https://github.com/evilmartians/lefthook/pull/589)) by @mrexox

## 1.5.4 (2023-11-27)
Expand Down
5 changes: 4 additions & 1 deletion internal/lefthook/run/exec/execute_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ type executeArgs struct {
}

func (e CommandExecutor) Execute(ctx context.Context, opts Options, out io.Writer) error {
in := os.Stdin
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 {
Expand Down
7 changes: 6 additions & 1 deletion internal/lefthook/run/exec/execute_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions internal/lefthook/run/exec/nullReader.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 5703093

Please sign in to comment.