Skip to content

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

Closed

Description

@kopach

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

Activity

  1. folke commented on Dec 9, 2020

    @folke
    Owner

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

    Fixed in 8f7b36a

  2. vhscom commented on Feb 5, 2022

    @vhscom

    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.

  3. arantebw commented on Feb 9, 2023

    @arantebw

    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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions