question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cz commit with prepare-commit-msg hook

See original GitHub issue

Description

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:open
  • Created 3 years ago
  • Reactions:4
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Lee-Wcommented, Dec 15, 2021

@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 💪

1reaction
woilecommented, Aug 14, 2020

Quite interesting indeed, please open a PR so we can discuss it there!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found