sharpvik / sema

Semantic commit tool
MIT License
56 stars 3 forks source link

allow writing commit messages #5

Closed mpldr closed 2 years ago

mpldr commented 2 years ago

Hi, love the idea!

I just have a little problem: currently I can only write commit titles, not messages. Due to how I do stuff I usually add 2-20 lines of prose as well which I currently have to do separately which is a bit tedious. Would it be possible to open $EDITOR or something similar with the title prefilled and the ability to write some text below?

sharpvik commented 2 years ago

I had this idea a long time ago, but no one has ever requested it and I myself don't write long commits too often. However, your request prompted me to investigate a little bit.

Default Editor

git var GIT_EDITOR

This command prints out the editor that git is configured to use. This would be useful for this feature, granted you probably have that set to your own preference and we want to be considerate.

Commit Templating

The git-commit command has a very useful flag: -t.

-t <file>, --template=<file>
           When editing the commit message, start the editor with the contents in the given file. The
           commit.template configuration variable is often used to give this option implicitly to the command. This
           mechanism can be used by projects that want to guide participants with some hints on what to write in
           the message in what order. If the user exits the editor without editing the message, the commit is
           aborted. This has no effect when a message is given by other means, e.g. with the -m or -F options.

Implementation Plan

I think what you're asking is quite doable. It will be added in the next release.

All we need to do is:

  1. Get the commit title (this part is already implemented).
  2. Create a file (maybe in /tmp or something) with that title line at the top.
  3. Pass the path to that file as git commit -t /tmp/sema-template-file.txt.

I think that's all there is to it.

Variability

I'd like to keep the default behaviour of sema as is and allow you to use this feature with a -l | --long flag. So you'll be doing

sema -pal

In future releases, I may add some way of configuring this behaviour. Maybe a config.sema file like below that you can put at the root of your repo.

long: true
mpldr commented 2 years ago

This bit from an ancient project of mine might be helpful: https://git.sr.ht/~poldi1405/bulkrename/tree/master/item/plan/edit.go#L11-37

(Please completely disregard everything else in this repo… this was a project for university that I really didnt care about.)