Skip to content

Commit

Permalink
fix: files from stdin only null separated (#615)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox authored Jan 24, 2024
1 parent 9f59b4e commit 3418528
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func newRunCmd(opts *lefthook.Options) *cobra.Command {

runCmd.Flags().BoolVar(
&runArgs.FilesFromStdin, "files-from-stdin", false,
"get files from standard input, null- or \\n-separated",
"get files from standard input, null-separated",
)

runCmd.Flags().StringSliceVar(
Expand Down
4 changes: 2 additions & 2 deletions internal/lefthook/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,12 @@ func (l *Lefthook) configHookCommandCompletions(hookName string) []string {
}
}

// parseFilesFromString parses both `\0`- and `\n`-separated files.
// parseFilesFromString parses both `\0`-separated files.
func parseFilesFromString(paths string) []string {
var result []string
start := 0
for i, c := range paths {
if c == 0 || c == '\n' {
if c == 0 {
result = append(result, paths[start:i])
start = i + 1
}
Expand Down
9 changes: 0 additions & 9 deletions testdata/files_override.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ stdout 'a-file\.js b_file\.go c,file\.rb'
exec lefthook run echo --file a-file.js --file ghost.file
stdout 'a-file\.js ghost\.file'

stdin b_file.go
exec lefthook run echo --files-from-stdin
stdout 'b_file\.go c,file\.rb'

stdin b_file.go
exec lefthook run echo --files-from-stdin --file ghost.file
stdout 'ghost\.file b_file\.go c,file\.rb'

-- lefthook.yml --
skip_output:
- meta
Expand All @@ -36,7 +28,6 @@ a-file.js

-- b_file.go --
b_file.go
c,file.rb

-- c,file.rb --
c,file.rb

0 comments on commit 3418528

Please sign in to comment.