(defvar emacs-git-branch
(when (and emacs-repository-version
(file-exists-p source-directory))
(let ((shell-return
(replace-regexp-in-string
"[\n)]" " " ; Replace newline and ) chars with spaces
(shell-command-to-string
(concat "cd " source-directory " && "
"git branch --contains "
emacs-repository-version)))))
;; Below regexp is tested for following "git branch --contains" values
;; Output for a commit in master branch too
;; "* (HEAD detached at origin/emacs-25)
;; master
;; "
;; Output for a commit only in emacs-25 branch
;; "* (HEAD detached at origin/emacs-25)
;; "
;; (message "%S" shell-return)
(string-match ".*[/ ]\\([^ ]+?\\)\\s-*$" shell-return)
(match-string-no-properties 1 shell-return)))
"Name of git branch from which the current emacs is built.")