From e897844c1e3dcd11ff585f5c595e07434fefd585 Mon Sep 17 00:00:00 2001 From: Brian Garvey Date: Wed, 16 Nov 2022 10:37:18 +0000 Subject: [PATCH 1/4] Create Go-syntax representation of the value --- internal/lefthook/runner/runner.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/lefthook/runner/runner.go b/internal/lefthook/runner/runner.go index 237ac0ea..4aea04b2 100644 --- a/internal/lefthook/runner/runner.go +++ b/internal/lefthook/runner/runner.go @@ -222,7 +222,8 @@ func (r *Runner) runScript(script *config.Script, unquotedPath string, file os.F args = strings.Split(script.Runner, " ") } - quotedScriptPath := shellescape.Quote(unquotedPath) + quotedScriptPath := fmt.Sprintf("%#v", unquotedPath) + args = append(args, quotedScriptPath) args = append(args, r.args[:]...) From 4c5e9b16b848c887fb61fbee90c98d6e7c9eace9 Mon Sep 17 00:00:00 2001 From: Brian Garvey Date: Thu, 17 Nov 2022 10:33:57 +0000 Subject: [PATCH 2/4] Update to remove quotedScriptPath --- internal/lefthook/runner/runner.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/internal/lefthook/runner/runner.go b/internal/lefthook/runner/runner.go index 4aea04b2..84c6c40e 100644 --- a/internal/lefthook/runner/runner.go +++ b/internal/lefthook/runner/runner.go @@ -222,9 +222,7 @@ func (r *Runner) runScript(script *config.Script, unquotedPath string, file os.F args = strings.Split(script.Runner, " ") } - quotedScriptPath := fmt.Sprintf("%#v", unquotedPath) - - args = append(args, quotedScriptPath) + args = append(args, fmt.Sprintf("%#v", unquotedPath)) args = append(args, r.args[:]...) if script.Interactive { From aa79a79a05da3f463d3fc93062a1b4429eedc507 Mon Sep 17 00:00:00 2001 From: Valentin Kiselev Date: Thu, 17 Nov 2022 13:52:20 +0300 Subject: [PATCH 3/4] fix: Remove quoting for script path --- internal/lefthook/runner/runner.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/lefthook/runner/runner.go b/internal/lefthook/runner/runner.go index 84c6c40e..91cf699d 100644 --- a/internal/lefthook/runner/runner.go +++ b/internal/lefthook/runner/runner.go @@ -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) } } @@ -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 @@ -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 @@ -222,7 +222,7 @@ func (r *Runner) runScript(script *config.Script, unquotedPath string, file os.F args = strings.Split(script.Runner, " ") } - args = append(args, fmt.Sprintf("%#v", unquotedPath)) + args = append(args, path) args = append(args, r.args[:]...) if script.Interactive { From 0545d09cdccf36dc6a8857f7b0241fbc17f5c410 Mon Sep 17 00:00:00 2001 From: Valentin Kiselev Date: Thu, 17 Nov 2022 13:57:01 +0300 Subject: [PATCH 4/4] chore: Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dcbf6529..7edc9e56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)