Function: magit-discard-files--discard

magit-discard-files--discard is a byte-compiled function defined in magit-apply.el.

Signature

(magit-discard-files--discard SECTIONS NEW-FILES)

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-apply.el
(defun magit-discard-files--discard (sections new-files)
  (let ((files (mapcar (##oref % value) sections)))
    (magit-confirm-files 'discard (append files new-files)
                         (format "Discard %s changes in" (magit-diff-type)))
    (if (eq (magit-diff-type (car sections)) 'unstaged)
        (magit-call-git "checkout" "--" files)
      (when new-files
        (magit-call-git "add"   "--" new-files)
        (magit-call-git "reset" "--" new-files))
      (let ((binaries (magit-binary-files "--cached")))
        (when binaries
          (setq sections
                (seq-remove (##member (oref % value) binaries)
                            sections)))
        (when sections
          (magit-discard-apply sections #'magit-apply-diffs))
        (when binaries
          (let ((modified (magit-unstaged-files t)))
            (setq binaries (magit--separate (##member % modified) binaries)))
          (when (cadr binaries)
            (magit-call-git "reset" "--" (cadr binaries)))
          (when (car binaries)
            (user-error
             (concat
              "Cannot discard staged changes to binary files, "
              "which also have unstaged changes.  Unstage instead."))))))))