kidd / git-msg-prefix.el

Insert a piece of earlier vcs commits in your current commit message

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

git-msg-prefix.el

What

In many organizations, git commits have to have a structure, like starting with one word from a list (Add, Fix, Clean, Remove…).

In other projects, you should start the commit messages with the issue number, or a specific tag referring to the feature you’re developing (Billing-123).

git-msg-prefix is intended to solve this repetitive task, by providing a prompt with some customized list of options. The default command is to present a searchable list of the previous commits (more recent first), and lets you select the one you want. This list of candidates is configurable via `git-msg-prefix-log-command`.

Once selected, the relevant part of the commit line will be extracted from the choosen candidate (via the regex in git-msg-prefix-regex, and the matched text will be inserted in the current buffer.

A gif is worth a 10^3 words: ./git-msg-prefix.gif

Release post in my blog.

How

Install

This package will be in melpa shortly. For now, get it from https://github.com/kidd/git-msg-prefix.el

(use-package git-msg-prefix
  :ensure t
  :config
  (setq git-msg-prefix-log-flags " --since='1 week ago' "
        git-msg-prefix-input-method 'helm-comp-read)
  (add-hook 'git-commit-mode-hook 'git-msg-prefix))

Usage

Add a hook to activate run the function when starting to write your commit

(add-hook 'git-commit-mode-hook 'git-msg-prefix)
(setq git-msg-prefix-input-method 'helm-comp-read)

Otherwise, add a keybinding to that function or run it manually from the minibuffer.

(local-set-key
 (kbd "C-c i")
 'git-msg-prefix)

Configure

There are 3 variables to configure:

  • git-msg-prefix-log-command: defaults to “git log –pretty=format:"%s"”
  • git-msg-prefix-log-flags: defaults to “”
  • git-msg-prefix-regex: defaults to “^\([^ ]*\) ”
    • git-msg-prefix-input-method: defaults to ido-completing-read. Change it to your favourite input method. (‘completing-read ‘ido-completing-read ‘git-msg-prefix-helm-read ‘ivy-read)

Who

Raimon Grau <raimonster@gmail.com>

About

Insert a piece of earlier vcs commits in your current commit message

License:GNU General Public License v3.0


Languages

Language:Emacs Lisp 100.0%