rusty-hook
rusty-hook copied to clipboard
Hooks are not unescaping Quotes before executing
Environment Details
-
Operating System
- Windows
- Rust Version: 1.43.0
-
Rust Release Channel
- Stable
- Cargo Version: 1.43.0
- rusty-hook Version: 0.11.1
Description
These fail but shouldn't:
pre-commit = "\"echo\""
pre-commit = """("echo")"""
Being unable to use quotes is preventing me from using pre-commit = """(git status --short | grep -q "^...folder/")"""
in my logic to only compile when changes are made in my rust folder.
"\"echo\""
is ran as \"echo\"
but should be ran as "echo"
.
"""("echo")"""
is ran as (\"echo\")
but should be ran as ("echo")
.
Thanks for the report @RefinedSoftwareLLC! Will try to take a deeper look at this one tomorrow
As a workaround, I got grep to work by removing all quotes and escape backslashes.
"""(grep -q "^...folder\.com/")"""
for now has to be """(grep -q ^...folder.com/)"""
- apparently I don't need quotes around the regexp.
- but
\.
doesn't work so I have to use.
which matches all characters instead of only a period. - using
\\.
in grep regexp just hangs the commit and it never stops running.
I can't reproduce this on Linux, but will check on my Windows machine in a bit.
Could you share two additional things whenever you get a chance?
- The output of
rusty-hook --version
(this will likely be 0.11.1 too but just want to check) - The output of the git command (presumably commit) that you mentioned is failing with those hook scripts
$ git commit -m "foo"
Found configured hook: pre-commit
Running command: ("echo")
[master d9d19f2] foo
1 file changed, 1 insertion(+), 1 deletion(-)
Yes, version 0.11.1
Found configured hook: pre-commit
Running command: ("echo")
'\"echo\"' is not recognized as an internal or external command,
operable program or batch file.
In cmd, if you directly type (\"echo\")
you get the same error, but ("echo")
works.
I'm guessing the escaping is due to https://github.com/rust-lang/rust/issues/29494
As this issue is unlikely to be fixed upstream (judging by the time it has been open for) can we fix this by using a different way of executing these commands? Afaict there is some workaround by using CreateProcessW
but I haven't looked too much into it. Is this something that's affecting a lot of users?
can we fix this by using a different way of executing these commands? Afaict there is some workaround by using CreateProcessW but I haven't looked too much into it. Is this something that's affecting a lot of users?
No, there's several viable, if mildly annoying, workarounds that are readily available, and we're definitely not going to dip down to CreateProcessW
directly. Folks can use the workarounds for now (even if that means defining the script in a file that's then invoked from the hook script) and we'll update accordingly whenever things are patched upstream