domingo, 2 de julio de 2017

Announcing commit-msg-prefix.

When writing commit messages, it's usual that your company/organisation has some policies and rules about the format and contents in the messages.

Some use an issue number, or name, or start with keywords (or emojis) like Add:/Clean:/Remove:.. (that can be converted to emojis in emacs too). But it's clear that somehow there's value in some kind of standarization.

So I created commit-msg-prefix, which lists the previous git commit messages and lets you pick one of them, and it will insert the relevant part of the commit in your current buffer.

My use case is when I do not remember the issue name/number I'm working on, but I remember keywords of previous commits that belong to the same issue.

There are a few variables to configure, like the exact git (or other) command to fetch logs, and the regex to apply to the log to extract the relevant part to insert.

The variable "commit-msg-prefix-input-method" is one of the symbols ('completing-read 'ido-completing-read 'commit-msg-prefix-helm-read 'ivy-read).

it defaults to ido-completing-read, but the idea is that you use your favourite input method.  ivy or helm, I guess :)

2 comentarios:

Anónimo dijo...

We use a scheme like the one you described, where every commit has be prefixed by a certain id.
Instead of an Emacs function, git provides hooks, which let you edit the commit message, before it is editable in Emacs. We use one of these hooks to insert the prefix, which works very well.

Raimon Grau dijo...

But how does the git prefix command decide which prefix to insert? It would work if the name of the branch contains the wanted id.

How do you solve this issue?