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

feat: git hooks integration #106

Merged
merged 7 commits into from
Jan 16, 2020
Merged

feat: git hooks integration #106

merged 7 commits into from
Jan 16, 2020

Conversation

AlexAtHome
Copy link
Contributor

I added git hooks support so you can run git-cz on prepare-commit-msg.

To make it work, you should update .git/hooks/prepare-commit-msg with following code:

#!/bin/bash
exec < /dev/tty && git-cz --hook || true

# If `git-cz` and `commitizen` are installed locally, run this instead
exec < /dev/tty && node_modules/.bin/git-cz --hook || true

Same works with Husky:

{
  "husky": {
    "hooks": {
      "...": "...",
      "prepare-commit-msg": "exec < /dev/tty && node_modules/.bin/git-cz --hook || true",
    }
  }
}

Closes #79

Alexander Bolotskov added 3 commits December 10, 2019 21:23
To run git-cz on `prepare-commit-msg` you can basically follow this
instruction
(https://github.com/commitizen/cz-cli#optional-running-commitizen-on-git-commit)
but usestreamich's `git-cz` instead of `cz-conventional-changelog`.

✅ Closes: #79
@AlexAtHome AlexAtHome changed the title Git hooks integration feat: git hooks integration Dec 12, 2019
@dnlfrst
Copy link

dnlfrst commented Jan 3, 2020

I would really appreciate this feature. Is there anything that prevents it from being merged?


Workaround in the mean time

  1. Download the implementation provided by @mamoruuu (I appreciate your efforts! 🙌) in his fork.

  2. In the downloaded fork, run:

    npm i
    npm i --save-dev yarn # Given, you do not have `yarn` globally available in your CLI.
    npm run build
  3. In your repository, run:

    npm uninstall --save-dev git-cz
    npm i --save-dev /path/to/the/downloaded/fork # Use a relative path for portability.

@streamich streamich mentioned this pull request Jan 16, 2020
13 tasks
Copy link
Owner

@streamich streamich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This is very nice.

@@ -31,7 +33,7 @@ const main = async () => {
params[arg] = true;
}

const {'dry-run': isDryRun, ...passThroughParams} = params;
const {'dry-run': isDryRun, hook: isHook, ...passThroughParams} = params;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have --dry-run flag that prints the message to STDOUT, and now we have --hook flag that will write the message to /.git/COMMIT_EDITMSG, and by default it would execute git commit .... I'm thinking maybe we could unify all of those into a single argument:

git-cz --output=git
git-cz --output=stdout
git-cz --output=file --file=/.git/COMMIT_EDITMSG
git-cz --output=file --file=/.git/MERGE_MSG
git-cz --output=file --file=/.git/SQUASH_MSG

lib/cli.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
lib/cli.js Outdated
* @see https://github.com/streamich/git-cz/issues/79
*/
if (isHook) {
const commitMsgFile = getGitRootDir() + '/.git/COMMIT_EDITMSG';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be also useful to support /.git/MERGE_MSG and /.git/SQUASH_MSG?

@streamich
Copy link
Owner

🎉 This PR is included in version 4.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

Husky integration
3 participants