Skip to content

Instantly share code, notes, and snippets.

@jiito
Last active November 21, 2022 21:55
Show Gist options
  • Save jiito/afb4911bd518bb1c9c8ab6ae0e534828 to your computer and use it in GitHub Desktop.
Save jiito/afb4911bd518bb1c9c8ab6ae0e534828 to your computer and use it in GitHub Desktop.
Get the branch identifier in lisp
;;; git.el -*- lexical-binding: t; -*-
(defun get-jira-prefix (iden)
"Get the JIRA branch identifier from IDEN."
(let ((prefix (string-match "[A-Za-z]+-[0-9]+" iden)))
(if (not prefix)
(message iden) (substring iden prefix (match-end 0))
)
)
)
(defun current-git-branch ()
"Get the current git branch."
(vc-git--symbolic-ref (buffer-file-name)))
(defun insert-branch-id()
"Insert the ticket identifier at point"
(insert (format "[%s]: " (get-jira-prefix (current-git-branch)) ))
(evil-insert-state)
)
;; add to commit with magit
(add-hook 'git-commit-setup-hook 'insert-branch-id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment