Function: magit-get-previous-branch

magit-get-previous-branch is a byte-compiled function defined in magit-git.el.

Signature

(magit-get-previous-branch)

Documentation

Return the refname of the previously checked out branch.

Return nil if no branch can be found in the HEAD reflog which is different from the current branch and still exists. The amount of time spent searching is limited by magit-get-previous-branch-timeout.

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-git.el
(defun magit-get-previous-branch ()
  "Return the refname of the previously checked out branch.
Return nil if no branch can be found in the `HEAD' reflog
which is different from the current branch and still exists.
The amount of time spent searching is limited by
`magit-get-previous-branch-timeout'."
  (let ((t0 (float-time))
        (current (magit-get-current-branch))
        (i 1) prev)
    (while (cond ((> (- (float-time) t0) magit-get-previous-branch-timeout)
                  (setq prev nil))
                 ((setq prev (magit-rev-verify (format "@{-%d}" i)))
                  (or (not (setq prev (magit-rev-branch prev)))
                      (equal prev current))))
      (cl-incf i))
    prev))