DEV Community

Discussion on: Enforce git commit messages automatically

Collapse
 
bloodgain profile image
Cliff

Some of this can also be done with pre/post-commit hooks in git, which eliminate the need for custom functions that everyone has to remember to use. And if someone uses plain git, it breaks your process, whereas they'd have to modify the hooks to get around it intentionally. Trying to use and involve your whole dev tool stack is a great idea, though. That's why the tools provide integration capability and APIs!

Also, while I applaud your PS1 decoration attempt, it's worth noting that the git contrib source provides a script called git-prompt.sh that defines a __git_ps1 function that does the heavy lifting for you. You can usually find the script in /usr/share/git-core/contrib/completion if you are using a standard git install or wherever you installed git. It can occasionally be slow, though, so YMMV.

Collapse
 
piyushkmr profile image
Piyush Kumar Baliyan

That is a good idea to integrate these with git hooks (I already have some hooks setup for linting and type-checking), I can add the API integration as well (that way people won't have to learn new shortcuts). But how can I auto add username to new branch?

And regarding commit message hook, I saw that you can prefill the editor content using git-hooks, but inline modification of commit-message is little tricky to get through (OR I am missing something).

The custom functions I created are just derived from common aliases developers use, an I personally found it faster to type gpoh instead of git push origin HEAD and so on.

Thanks for the __git_ps1, I didn't know that, although I'll not be using the dirty check, as it add a delay to each terminal prompt.