pre-commit should be pre-commit.js
nsisodiya opened this issue · 10 comments
I am using this package.
in the hook directory, I need to create file name called pre-commit
,
my editor display it is a text file.
I am writing js code inside this file. I want this file to be named a pre-commit.js so that syntax highlighting and many other things will work !
All hooks have to be shell scripts (without the .sh ending). But you can call .js files inside a shell script with node.
@nsisodiya thanks for stopping by and contributing to the project with suggestions!
This is a problem related to your setup / workflow, most editors have a command to force the syntax highlighting correctly for mismatching file extensions.
@joh-klein suggestion stands and is a correct approach.
To add more context, the reason why we do not assume that the pre-commit
script filename is pre-commit.js
is because we do bind you to JavaScript. We want the user to be able to use any language and technology. It could be a C binary or a Python script.
Closing this for now but questions like these are welcome.
Ok, let me propose a solution !!
hooks directory can have multiple pre-commit scripts
like
pre-commit
pre-commit.sh
pre-commit.js
pre-commit.py
and you can execute all files !! that is fair win win situation !!
uhm... @nsisodiya have you seen https://github.com/typicode/husky ? The only reason why I built this is because I didn't know husky was around.
This said, I am thinking about your suggestion. I can probably execute whatever matches /^pre-commit/
regardless of the extension. That's probably a one line change. (reopening and PR welcome)
@nsisodiya landend on dev branch, wanna give it a try ? You can npm install
a github branch.
Edit: npm i kilianc/shared-git-hooks#develop
This doesn't work for me. It fails in environments where there is more than one file with the complete hook name as part of its filename. I had previously the following structure:
/hooks
--commit-msg
--commit-msg.js
(commit-msg would just call "node commit-msg.js")
Now, since there are two files with "commit-msg" in the filename, neither is called.
@joh-klein why would you have two scripts in that folder, isn't that confusing? You can use a shebang
Because I have to support some windows users (using git bash) where a shebang (not all at least) is not supported.
I see @joh-klein let me think about it
What about this topic? I have the same issue and would appreciate a solution.