Function: magit-apply-patch

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

Signature

(magit-apply-patch SECTION:S ARGS PATCH)

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260822.1158/magit-apply.el
(defun magit-apply-patch (section:s args patch)
  (let* ((files (if (atom section:s)
                    (list (oref section:s value))
                  (mapcar (##oref % value) section:s)))
         (command (symbol-name this-command))
         (command (if (and command (string-match "^magit-\\([^-]+\\)" command))
                      (match-str 1 command)
                    "apply"))
         (context (magit-diff-get-context))
         (ignore-context (magit-diff-ignore-any-space-p)))
    (unless (magit-diff-context-p)
      (user-error "Not enough context to apply patch.  Increase the context"))
    (unless magit-inhibit-refresh
      (magit-run-before-change-functions files command))
    (if (eq this-command 'magit-copy-diff-as-kill)
        (kill-new patch)
      (with-temp-buffer
        (insert patch)
        (let ((magit-inhibit-refresh t))
          (magit-run-git-with-input
           "apply" args "-p0"
           (if ignore-context "-C0" (format "-C%s" context))
           "--ignore-space-change" "-")))
      (unless magit-inhibit-refresh
        (magit-run-after-apply-functions files command)
        (magit-refresh)))))