Skip to content

Commit

Permalink
fix: Remove quoting for scripts (evilmartians#371)
Browse files Browse the repository at this point in the history
Co-authored-by: Brian Garvey <[email protected]>
Closes evilmartians#367
  • Loading branch information
mrexox committed Nov 17, 2022
1 parent dee11d9 commit 3fbb37d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 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: Remove quoting for scripts ([PR #371](https://github.com/evilmartians/lefthook/pull/371) by @stonesbg + @mrexox)
- fix: remove lefthook.checksum on uninstall ([PR #370](https://github.com/evilmartians/lefthook/pull370) by @JuliusHenke)
- fix: Print prepare-commit-msg hook if it exists in config ([PR #368](https://github.com/evilmartians/lefthook/pull/368) by @mrexox)
- fix: Allow changing refs for remote ([PR #363](https://github.com/evilmartians/lefthook/pull/363) by @mrexox)
Expand Down
17 changes: 8 additions & 9 deletions internal/lefthook/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ func (r *Runner) runScripts(dir string) {
continue
}

unquotedScriptPath := filepath.Join(dir, file.Name())
path := filepath.Join(dir, file.Name())

if r.hook.Parallel {
wg.Add(1)
go func(script *config.Script, path string, file os.FileInfo) {
defer wg.Done()
r.runScript(script, path, file)
}(script, unquotedScriptPath, file)
}(script, path, file)
} else {
r.runScript(script, unquotedScriptPath, file)
r.runScript(script, path, file)
}
}

Expand All @@ -185,13 +185,13 @@ func (r *Runner) runScripts(dir string) {
continue
}

unquotedScriptPath := filepath.Join(dir, file.Name())
path := filepath.Join(dir, file.Name())

r.runScript(script, unquotedScriptPath, file)
r.runScript(script, path, file)
}
}

func (r *Runner) runScript(script *config.Script, unquotedPath string, file os.FileInfo) {
func (r *Runner) runScript(script *config.Script, path string, file os.FileInfo) {
if script.DoSkip(r.repo.State()) {
logSkip(file.Name(), "(SKIP BY SETTINGS)")
return
Expand All @@ -210,7 +210,7 @@ func (r *Runner) runScript(script *config.Script, unquotedPath string, file os.F

// Make sure file is executable
if (file.Mode() & executableMask) == 0 {
if err := r.fs.Chmod(unquotedPath, executableFileMode); err != nil {
if err := r.fs.Chmod(path, executableFileMode); err != nil {
log.Errorf("Couldn't change file mode to make file executable: %s", err)
r.fail(file.Name(), "")
return
Expand All @@ -222,8 +222,7 @@ func (r *Runner) runScript(script *config.Script, unquotedPath string, file os.F
args = strings.Split(script.Runner, " ")
}

quotedScriptPath := shellescape.Quote(unquotedPath)
args = append(args, quotedScriptPath)
args = append(args, path)
args = append(args, r.args[:]...)

if script.Interactive {
Expand Down

0 comments on commit 3fbb37d

Please sign in to comment.