-
-
Notifications
You must be signed in to change notification settings - Fork 290
feat(commit): add --write-message-to-file option #731
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ff56b4e
feat(commit): add --write-message-to-file option
crai0 af8e276
test(commit): add test for --write-message-to-file option
crai0 a2d0cb8
docs(commit): document --write-message-to-file option
crai0 dc0c86f
docs(tutorials): add tutorial for automatically preparing commit message
crai0 cd93206
test(commit): add negative test cases for --write-message-to-file option
crai0 14fac5b
docs(commit): link to prepare-commit-msg hook tutorial
crai0 4e28075
docs(prepare-commit-msg): add additional information to tutorial
crai0 ea3ecce
refactor(commit): change type of write_message_to_file to path
crai0 ab42fd4
test(commit): pass path for write_message_to_file
crai0 5b4f944
feat(hooks): add prepare-commit-msg and post-commit hooks
crai0 f04a719
docs(tutorials): add installation guide and feature overview for hooks
crai0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Automatically prepare message before commit | ||
|
||
## About | ||
|
||
It can be desirable to use commitizen for all types of commits (i.e. regular, merge, | ||
squash) so that the complete git history adheres to the commit message convention | ||
without ever having to call `cz commit` manually. | ||
|
||
To automatically prepare a commit message prior to committing, you can | ||
use a [Git hook](prepare-commit-msg-docs): | ||
|
||
> The [prepare-commit-msg] hook is invoked by git-commit right after preparing the | ||
> default log message, and before the editor is started. | ||
|
||
This allows for enforcing the usage of commitizen so that whenever a commit is about to | ||
be created, commitizen is used for creating the commit message. Running `git commit` or | ||
`git commit -m "..."` for example, would trigger commitizen and use the generated commit | ||
message for the commit. | ||
|
||
## How to | ||
|
||
- Step 1: Create a new [`prepare-commit-msg`][prepare-commit-msg-docs] Git hook by running the following commands from the root of the Git repository: | ||
|
||
```sh | ||
cd .git/hooks | ||
touch prepare-commit-msg | ||
chmod +x prepare-commit-msg | ||
``` | ||
|
||
- Step 2: Edit the newly created file and add the following content: | ||
|
||
```sh | ||
#!/bin/sh | ||
COMMIT_MSG_FILE=$1 | ||
exec < /dev/tty && cz commit --dry-run --write-message-to-file $COMMIT_MSG_FILE || true | ||
``` | ||
|
||
See the Git hooks documentation on [`prepare-commit-msg` hooks][prepare-commit-msg-docs] for details on how this works. | ||
|
||
[prepare-commit-msg-docs]: https://git-scm.com/docs/githooks#_prepare_commit_msg | ||
|
||
## Drawbacks | ||
|
||
If additional hooks are used (e.g. pre-commit) that prevent a commit from being created, | ||
the message has to be created from scratch when commiting again. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
COMMIT_MSG_FILE=$1 | ||
exec < /dev/tty && cz commit --dry-run --write-message-to-file $COMMIT_MSG_FILE || true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.