shared-git-hooks icon indicating copy to clipboard operation
shared-git-hooks copied to clipboard

pre-commit should be pre-commit.js

Open nsisodiya opened this issue 9 years ago • 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 !

nsisodiya avatar May 19 '16 09:05 nsisodiya

All hooks have to be shell scripts (without the .sh ending). But you can call .js files inside a shell script with node.

joh-klein avatar May 30 '16 13:05 joh-klein

@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.

kilianc avatar May 30 '16 17:05 kilianc

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 !!

nsisodiya avatar May 31 '16 04:05 nsisodiya

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)

kilianc avatar May 31 '16 16:05 kilianc

@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

kilianc avatar Jun 03 '16 00:06 kilianc

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 avatar Jun 16 '16 14:06 joh-klein

@joh-klein why would you have two scripts in that folder, isn't that confusing? You can use a shebang

kilianc avatar Jun 16 '16 15:06 kilianc

Because I have to support some windows users (using git bash) where a shebang (not all at least) is not supported.

joh-klein avatar Jun 17 '16 08:06 joh-klein

I see @joh-klein let me think about it

kilianc avatar Jun 17 '16 17:06 kilianc

What about this topic? I have the same issue and would appreciate a solution.

keshix avatar Aug 30 '16 07:08 keshix