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?
Written by Maxim Mitroshin
Related protips
1 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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Emacs
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#