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 regression from #314 (chmod missed fix) #330

Merged
merged 3 commits into from
Sep 28, 2022
Merged
Changes from 2 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
13 changes: 7 additions & 6 deletions internal/lefthook/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,23 +161,24 @@ func (r *Runner) runScripts(dir string) {
continue
}

scriptPath := shellescape.Quote(filepath.Join(dir, file.Name()))
unquotedScriptPath := 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, scriptPath, file)
}(script, unquotedScriptPath, file)
} else {
r.runScript(script, scriptPath, file)
r.runScript(script, unquotedScriptPath, file)
}
}

wg.Wait()
}

func (r *Runner) runScript(script *config.Script, path string, file os.FileInfo) {
func (r *Runner) runScript(script *config.Script, unquotedPath string, file os.FileInfo) {
quotedScriptPath := shellescape.Quote(unquotedPath)
ariccio marked this conversation as resolved.
Show resolved Hide resolved
if script.DoSkip(r.repo.State()) {
logSkip(file.Name(), "(SKIP BY SETTINGS)")
return
Expand All @@ -196,7 +197,7 @@ func (r *Runner) runScript(script *config.Script, path string, file os.FileInfo)

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

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

r.run(RunOptions{
Expand Down