Function: magit-insert-worktrees

magit-insert-worktrees is a byte-compiled function defined in magit-worktree.el.

Signature

(magit-insert-worktrees)

Documentation

Insert sections for all worktrees.

If there is only one worktree, then insert nothing.

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-worktree.el
(defun magit-insert-worktrees ()
  "Insert sections for all worktrees.
If there is only one worktree, then insert nothing."
  (let ((worktrees (magit-list-worktrees)))
    (when (length> worktrees 1)
      (magit-insert-section (worktrees)
        (magit-insert-heading t "Worktrees")
        (let* ((cols
                (mapcar
                 (lambda (config)
                   (pcase-let ((`(,directory ,commit ,branch ,bare) config))
                     (cons (cond
                             (branch
                              (propertize
                               branch 'font-lock-face
                               (if (equal branch (magit-get-current-branch))
                                   'magit-branch-current
                                 'magit-branch-local)))
                             (commit
                              (propertize
                               (magit-rev-abbrev commit) 'font-lock-face
                               (if (file-equal-p default-directory directory)
                                   '(magit-hash magit-branch-current)
                                 'magit-hash)))
                             (bare "(bare)"))
                           config)))
                 worktrees))
               (align (1+ (apply #'max (mapcar (##string-width (car %)) cols)))))
          (pcase-dolist (`(,head . ,config) cols)
            (magit--insert-worktree
             config
             (concat head (make-string (- align (length head)) ?\s)))))
        (insert ?\n)))))