typicode / husky

Git hooks made easy 🐶 woof!
https://typicode.github.io/husky
MIT License
32.38k stars 1.02k forks source link

any documentation on how to update commit-msg? #97

Closed thatkookooguy closed 7 years ago

thatkookooguy commented 7 years ago

I want to create a hook to add a line at the end of the commit message.

so, if a user wrote:

change files

I want the commit to change to

change files

-something I added

I see in the hooks support page that husky does support this event, but I can't seem to find how to change the commit message. Most cases I found online just validate the commit message and don't edit it.

is it possible?

Also, can't seem to see a URL to documentation anywhere. If there is any, can you please give me a link to it?

thanks!

iamstarkov commented 7 years ago

It seems like you need commit message templates and not hooks https://robots.thoughtbot.com/better-commit-messages-with-a-gitmessage-template

thatkookooguy commented 7 years ago

@iamstarkov a template is not what I'm looking for. This change shouldn't affect anything the committer actually wrote. it just adds a string to the end of the commit to mark commits. Also, I want the following things to be true:

So, a commit message template isn't the right solution here.

iamstarkov commented 7 years ago

Have you tried asking on StackOverflow? By the way, git has examples for all hooks: take a look https://github.com/git/git/blob/master/templates/hooks--commit-msg.sample

I wanted to note that the only husky's responsibility is to invoke hooks, not actual hooks implementation.

thatkookooguy commented 7 years ago

I already know how to make this in bash. But there's no clear documentation on where to set or get the commit message file for husky in javascript. I prefer to use javascript instead of bash if that's possible.

If it's not possible (meaning I'll have to use the original script), that's fine too.

But if there is a way to change the commit message with husky (and javascript), that's what I'm trying to figure out.

The example you added is in bash so it's not exactly what I'm looking for

That's part of what husky enables, no? writing the git hook in javascript?

I'm trying to figure out something specifically related to husky. not git hooks in general. Maybe I didn't make that clear in the original issue post.

It seems like you think I'm asking for an implementation. I'm trying to ask for some documentation on this repository.

thatkookooguy commented 7 years ago

seems like

I wanted to note that the only husky's responsibility is to invoke hooks, not actual hooks implementation.

was the right answer.

TechQuery commented 7 years ago

@Thatkookooguy , you can set the commit message by code like below:

require('fs').writeFileSync(process.env.GIT_PARAMS, 'some message edited');

just like what Vim or other command-line editor does~

Reference documentation

thatkookooguy commented 7 years ago

@TechQuery thanks! that's exactly what I needed! :-)