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

prepare-commit-msg hook? #88

Open
inside opened this issue Jun 3, 2016 · 5 comments
Open

prepare-commit-msg hook? #88

inside opened this issue Jun 3, 2016 · 5 comments

Comments

@inside
Copy link

inside commented Jun 3, 2016

Hi,

Is it possible to trigger the prepare-commit-msg hook using this configuration in package.json?

  "config": {
    "pre-git": {
      "prepare-commit-msg": [
        "path/to/prepare-commit-msg"
      ]
    }
  }

Best,

@bahmutov
Copy link
Owner

bahmutov commented Jun 3, 2016

Hi, not sure what this git hook does, can you explain?

@inside
Copy link
Author

inside commented Jun 4, 2016

I use this hook to populate the commit message with some useful infos like the name of the branch you are currently on. Here's the link to the doc.

For what it's worth, you'll find below the script I use to insert text like this: [feature name] (branch name):

#!/bin/sh

# Put this file in .git/hooks/prepare-commit-msg
# (don't forget to check permissions on the file, it must be executable)
# This script prepares the commit message by inserting
# [PROJECT_NAME] (BRANCH) at the top of the message.
# PROJECT_NAME is your own environment variable,
# you can set it like this:
# $ export PROJECT_NAME=MY_PROJECT_NAME
# or don't set it, you'll just have empty brackets.
# Then you just have to write the commit message.

current_branch()
{
    ref=$(git rev-parse --abbrev-ref HEAD 2> /dev/null) \
        || return
    echo $ref
}

# If $2 is empty, prepare the commit message.
# See what are the values of $2 there:
# http://git-scm.com/docs/githooks#_prepare_commit_msg
# Useful for leaving the commit message untouched on a merge.
if [ -z "$2" ]
then
    BRANCH=$(current_branch)
    TIME=$(date +%s)
    TEMPORARY_COMMIT_FILE="/tmp/temporary_commit_file.$TIME"

    echo "[$PROJECT_NAME] ($BRANCH)" | cat - "$1" > $TEMPORARY_COMMIT_FILE
    mv $TEMPORARY_COMMIT_FILE "$1"
fi

@bahmutov
Copy link
Owner

bahmutov commented Jun 7, 2016

that's a cool feature, I should probably do this.

@fernandogmar
Copy link

I am thinking out loud... how about to execute commit-wizard on this step and then use the result, instead of using npm run commit this could be just git commit? Could it be possible?

@fernandogmar
Copy link

I am going to try it . I will hack a bit using this https://github.com/linxiaowu66/prepare-commit-msg-angular/blob/master/index.js

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

No branches or pull requests

3 participants