Last Updated: February 25, 2016
·
594
· rocco66

Extract issue name from branch name

If your branch have issue number in name then you can press some hotkeys and insert this issue name in commit mesasge(for stash integration for example).

Target pattern is #PROJECT-issuenumber at the end of branch name. Example:

my-branch#PROJ-1 -> PROJ-1

Code:

(defun insert-issue-number-from-branch ()
  "Get current issue name from branch and insert in commit message"
  (interactive)
  (let* ((branch-name (magit-get-current-branch))
         (pat "#\\([A-Z]+-[0-9]+\\)$")
         (pos (string-match pat branch-name)))
    (if pos
        (save-excursion
          (end-of-buffer)
          (insert "\n")
          (insert (match-string 1 branch-name)))
      (message "#PROJECT-number not found in the end of branch name"))))

(global-set-key (kbd "C-x M-i") 'insert-issue-number-from-branch)

Does anybody know how can I do it automatically(some hook?) instead of press keys?

1 Response
Add your response

ok, two years were passed and now I have an answer:

(add-hook 'git-commit-setup-hook 'insert-issue-number-from-branch-noni)

and remove (interactive)

over 1 year ago ·