Function: magit-get-previous-branch
magit-get-previous-branch is a natively 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 /nix/store/irvbdy0zra0dn8fpd008f32x5ix6qm5v-emacs-packages-deps/share/emacs/site-lisp/elpa/magit-20261005.508/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))))
(incf i))
prev))