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: Remove quoting for scripts #371

Merged
merged 4 commits into from
Nov 17, 2022
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: 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