Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use empty stdin by default #590

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading