Function: magit-checkout-stage

magit-checkout-stage is an interactive and byte-compiled function defined in magit-merge.el.

Signature

(magit-checkout-stage FILE ARG)

Documentation

During a conflict checkout and stage side, or restore conflict.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-merge.el
(defun magit-checkout-stage (file arg)
  "During a conflict checkout and stage side, or restore conflict."
  (interactive
    (let ((file (magit-completing-read "Checkout file"
                                       (magit-tracked-files) nil 'any nil
                                       'magit-read-file-hist
                                       (magit-current-file))))
      (cond ((member file (magit-unmerged-files))
             (list file (magit-checkout-read-stage file)))
            ((yes-or-no-p (format "Restore conflicts in %s? " file))
             (list file "--merge"))
            ((user-error "Quit")))))
  (pcase (cons arg (cddr (car (magit-file-status file))))
    ((or `("--ours"   ?D ,_)
         '("--ours"   ?U ?A)
         `("--theirs" ,_ ?D)
         '("--theirs" ?A ?U))
     (magit-run-git "rm" "--" file))
    (_ (if (equal arg "--merge")
           ;; This fails if the file was deleted on one
           ;; side.  And we cannot do anything about it.
           (magit-run-git "checkout" "--merge" "--" file)
         (magit-call-git "checkout" arg "--" file)
         (magit-run-git "add" "-u" "--" file)))))