1

I'm trying to write a git post-commit file in node.js and I'm having trouble.

The file seems to have to be named post-commit in the .git/hooks directory. Since that file can't have an extension, my vim editor won't persistently give it javascript syntax highlighting, and thus none of my snippets work, and a variety of other challenges present themselves.

What can I do? Tell git to run post-commit.js or tell vim to consider this file javascript, but that doesn't persist.

Thoughts?

2 Answers 2

2

You can have the post-commit file run a separate JavaScript file.

post-commit:

#!/bin/bash/
node yourJavascriptFile.js
Sign up to request clarification or add additional context in comments.

5 Comments

A bit much for a single command, but useful once there's more than one build step.
That doesn't work. It can't seem to find that file. I think it executes the post-commit bash file from the top level directory, rather than from within .git/hooks
Adding the absolute path to both node and the script is best practice.
@ppovoski, absolute paths is the worst practice. It's an antipattern almost always and everywhere. Especially for user script files. In this particular case, it is better to use node $(dirname ${BASH_SOURCE[0]})/yourJavascriptFile.js to look for the script in the hooks directory. The node binary must be in the PATH.
It is also worth noting that the shebang string has a typo. There should be no trailing slash after #!/bin/bash
1

Use :set filetype=javascript command in vim to set file type. You may also want to enable modeline in vim and include the aforementioned command in a comment at the top of your file like this:

/* vim: set filetype=javascript : */
your_Javascript_code_goes_here()

To enable modeline in vim, add this to your ~/.vimrc file:

set modelines=2
set modeline

That will enable searching for vim modelines in the first two lines of the file.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.