Function: magit-stage-untracked

magit-stage-untracked is a byte-compiled function defined in magit-apply.el.

Signature

(magit-stage-untracked &optional INTENT)

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260822.1158/magit-apply.el
(defun magit-stage-untracked (&optional intent)
  (let* ((section (magit-current-section))
         (files (pcase (magit-diff-scope)
                  ('file  (list (oref section value)))
                  ('files (magit-region-values nil t))
                  ('list  (magit-untracked-files))))
         plain repos)
    (dolist (file files)
      (if (and (not (file-symlink-p file))
               (magit-git-repo-p file t))
          (push file repos)
        (push file plain)))
    (magit-run-before-change-functions files "stage")
    (when plain
      (magit-run-git "add" (and intent "--intent-to-add")
                     "--" plain)
      (when magit-auto-revert-mode
        (mapc #'magit-turn-on-auto-revert-mode-if-desired plain)))
    (dolist (repo repos)
      (save-excursion
        (when-let ((section (magit-get-section
                             `((file . ,repo) (untracked) (status)))))
          (goto-char (oref section start))
          (let* ((topdir (magit-toplevel))
                 (url (let ((default-directory
                             (file-name-as-directory (expand-file-name repo))))
                        (or (magit-get "remote" (magit-get-some-remote) "url")
                            (file-name-concat "." repo))))
                 (package
                  (and (equal borg-user-emacs-directory topdir)
                       (file-name-nondirectory (directory-file-name repo)))))
            (if (and package
                     (fboundp 'borg-assimilate)
                     (y-or-n-p (format "Also assimilate `%s' drone?" package)))
                (borg-assimilate package url)
              (magit-submodule-add-1
               url repo (magit-submodule-read-name-for-path repo package))
              (when (and package
                         (fboundp 'borg--sort-submodule-sections)
                         (fboundp 'borg--maybe-absorb-gitdir))
                (borg--sort-submodule-sections
                 (expand-file-name ".gitmodules" topdir))
                (let ((default-directory borg-user-emacs-directory))
                  (borg--maybe-absorb-gitdir package))))))))
    (magit-run-after-apply-functions files "stage")))