rycus86 / githooks

Githooks: per-repo and global Git hooks with version control
MIT License
380 stars 19 forks source link

Wrong shebang, githook script fails #157

Closed mjk-gh closed 3 years ago

mjk-gh commented 3 years ago

The currently used shebang is:

!/bin/sh

On systems that only have bash installed, /bin/sh is the same as /bin/bash.

However, on systems that have a POSIX shell installed (e.g. dash), /bin/sh is not bash, but dash instead, so the githooks script does not work properly anymore:

$ git hooks config
/home/myuser/.githooks/bin/githooks: 2209: shift: can't shift that many

Replacing the shebang with

!/bin/bash

fixes above error.

rycus86 commented 3 years ago

Hi @mjk-gh

It doesn't seem to be a POSIX sh vs. Bash issue, but I agree the error message could be improved there. Check the relevant code at https://github.com/rycus86/githooks/blob/master/cli.sh#L2209 which assumes that git hooks config has at least one more argument behind it. I assume Bash might silently ignore the shift failure there.

You can check the available arguments there with git hooks config help

I can put in a change to check if the CONFIG_ARGUMENT variable is empty, or the number of arguments is less than 2 and print a more useful error message there instead of can't shift that many