I can not figure a way to make easily multiline description in the commitizen promt.
Do you have a clever way to do it?
Thanks.
@xavhan Thanks for opening this issue. This repo is for commitizen's command line tool (cz-cli) and is probably not what you need to change to accomplish this. Instead, you should fork and make changes to the conventional changelog adapter. Once you've made the changes you want, you'll then need to publish it to npm. Once you do this then you can use your own adapter in your commitizen config.
Our conventional changelog adapter (cz-conventional-changelog) follows a very specific style that the angular project uses. If you want to make changes to the convention (like adding multi-line descriptions) then tools like semantic release and others that rely upon you using this convention may break. Nonetheless, commitizen is written to allow you to build or modify adapters. Others have done so and they include
I've gone into how to create an adapter a bit more here.
Thanks for your answer, I'll dig into it!
@xavhan, you may already have a solution; I have experimenting on the same same issue and you could start your favorite editor from your adapter like this:
const child = require('child_process');
const fs = require('fs')
const filename = 'text.txt'; // Should be a random name in a temp folder eg. https://github.com/sindresorhus/temp-write
const vim = child.spawn('vim', [filename], {stdio: 'inherit'});
vim.on('exit', () => {
fs.readFile(filename, 'utf8', (err, data) => {
console.log(data);
});
});
However, I'm missing the ability to use git's default editor to get access to commit information like untrack/staged files, files to committed, what branch I'm on etc.
@jimthedev, Is it possible to only use commitizen to a post-commit script.
Eg. When I hit enter after git cz, commitizen will start up an adapter. The adapter ask question if the commit is a bug-fix or new feature etc. and building up a string (as it does today) BUT instead of actually make the commit commitizen will just pass the string to the usual git commit action. So commitizen will only decorate the commit message so that I can complete the message in my git-editor (like vim, nano, sublime etc.).
Flow: git cz --> adapter --> git commit (we are now in a git context, commitizen has exit and we can continue to edit the message). This is maybe not possible or outside the scope of commitizen, I don't know. Maybe I should take a look at the usual prepare-commit-msg hook. Thoughts?
@xavhan, sorry for hijacking your issue. Maybe I should create a new issue.
@tjoskar Don't worry ;) I am eager to see the outcome of yours.
@xavhan, after I posted my comment, I started to play around with prepare-commit-msg and come up with this: https://github.com/tjoskar/emoji-commit-hook (proof of concept). I will go with prepare-commit-msg for now but I really like the idea of commitizen; that you just have to put a few lines in your package.json and you are good to go. That is fantastic. However, I really miss the ability for multiline commits and to get commit-info while I am writing my commit message.
@tjoskar I think that could work and am happy to entertain PRs so long as they don't break the new --retry functionality. One question. Is there a difference between using a post hook and just running git cz && git cz --amend --no-verify? The first command will ask you to fill in the prompts, run your tests, and make the commit, the second command lets you edit the commit message to add multiline messages. I know it isn't ideal, but might be acceptable.
@jimthedev, I have never thought of using --amend directly after using git cz. Why have I not thought of that before? It feels however like a ugly hack but as you say, "it might be acceptable". I will try it out tomorrow and get back to you. – Thanks for the tip.
Just add \n to your description :wink:
@ddomingues
Just add\nto your description 😉
Thanks! For some reason I didn't think on that! 🤣
Most helpful comment
Just add
\nto your description :wink: