cz commit with prepare-commit-msg hook
See original GitHub issueDescription
cz commit is very good tool. If prepare-commit-msg hook calls cz commit, become easy to commit by many user.
Possible Solution
like cz check, writing pre-commit config
---
repos:
- hooks:
- id: commitizen-prepare-commit-msg
stages: [prepare-commit-msg]
and user type git comit, then prepare-commit-msg hook works and invokes cz commit.
Is this feature accepted as this product policy?
Additional context
I did a basic research. And I found that there are two issues.
- The current cz commit calls git. But in this case, git calls cz commit
- Git hook is started without standard input, so we can’t create commit message interactively
I made a test implementation to solve the problem by the following method
- When called from git, write the commit message to the file which is set by “–commit-msg-file” argument
- Open tty manualy and use as stdio.
but this change has sideffect.
tty is manually opened as io.FileIO. But prompt_toolkit (which used by questionary) assumes tty is opened as io.TextIOWrapper. As a workaround I added wrap class
class WrapStdin:
def __init__(self):
fd = os.open("/dev/tty", os.O_RDWR | os.O_NOCTTY)
tty = open(fd, "wb+", buffering=0)
self.tty = tty
def __getattr__(self, key):
if key == "encoding":
return "UTF-8"
return getattr(self.tty, key)
def __del__(self):
self.tty.close()
All patch code is here. https://github.com/saygox/commitizen/commit/033159d08e240c493b5fa36d67e870e3b443d4d6
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Making commits the right way with hooks - DEV Community
There's a huge list of hooks that cover nearly every part of git. For now, we will just use pre-commit and prepare-commit-msg ....
Read more >Commitizen - GitHub Pages
If your repo is Commitizen friendly: ... Simply use git cz or just cz instead of git commit when committing. You can also...
Read more >How to write great git commit messages - bitspeicher.blog
yarn global add commitizen cz-conventional-changelog. 1. Tell commitizen to use the ... Add a template for the prepare-commit-msg hook:
Read more >use git's prepare-commit-msg hook during an interactive rebase
In a lerna/yarn monorepo, we use commitizen and cz-conventional-changelog to manage ...
Read more >How to use the latest Husky 8 with Commitizen for adding git ...
I've been trying to setup Husky with Commitizen to add git hooks to my project ... npx husky add .husky/prepare-commit-msg 'exec < /dev/tty...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mrlubos Thanks for the summary! It’s super helpful. I’ll take a deeper look and see how I can fix it when I have time 💪
Quite interesting indeed, please open a PR so we can discuss it there!