Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[suggestion] to add doc about git hook which would not depend upon 3-rd party tool #87

Closed
kopach opened this issue Dec 1, 2020 · 3 comments
Assignees

Comments

@kopach
Copy link

kopach commented Dec 1, 2020

Hi. In my project we do use conventional commits, but we don't use husky or Yorkie, also we don't want to force people to use emojis in commits. However, personally, I like putting emojis into my commits and I want it to be automated. Therefore, I've added devmoji into my .git/hooks/ manually. Here is info on how I have this done. In the root of project, run:

cp .git/hooks/prepare-commit-msg.sample .git/hooks/prepare-commit-msg # note, it's important to copy this to make sure file is executable
echo "#\!/bin/sh\n\nCOMMIT_MSG_FILE=\$1\nCOMMIT_MSG=\$(cat \$COMMIT_MSG_FILE)\n\necho \"\${COMMIT_MSG}\" | devmoji > \$1" > .git/hooks/prepare-commit-msg

Would be great to have this added to the README of the project. Thanks!


The resulting content of .git/hooks/prepare-commit-msg would be:

#!/bin/sh

COMMIT_MSG_FILE=$1
COMMIT_MSG=$(cat $COMMIT_MSG_FILE)

echo "${COMMIT_MSG}" | devmoji > $1
@folke
Copy link
Owner

folke commented Dec 9, 2020

Thank you for the suggestion!
I've added a link to this issue from the docs.

Fixed in 8f7b36a

@folke folke closed this as completed Dec 9, 2020
@vhscom
Copy link

vhscom commented Feb 5, 2022

I'm guessing OP was running macOS. On Linux you need to use echo -e in order to enable interpolation of backslash escapes. Then their hook works great. Another good reason not to use Husky is it falls apart when you try and perform an interactive rebase and that's frustrating when you're right at the finish line.

@arantebw
Copy link

arantebw commented Feb 9, 2023

I agree with @vhscom, it will fail on Linux if echo does not have the -e option. So,

echo -e "#\!/bin/sh\n\nCOMMIT_MSG_FILE=\$1\nCOMMIT_MSG=\$(cat \$COMMIT_MSG_FILE)\n\necho \"\${COMMIT_MSG}\" | devmoji > \$1" > .git/hooks/prepare-commit-msg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants