Function: magit-ediff-dwim

magit-ediff-dwim is an autoloaded, interactive and byte-compiled function defined in magit-ediff.el.

Signature

(magit-ediff-dwim)

Documentation

Compare, stage, or resolve using Ediff.

This command tries to guess what file, and what commit or range the user wants to compare, stage, or resolve using Ediff. It might only be able to guess either the file, or range or commit, in which case the user is asked about the other. It might not always guess right, in which case the appropriate magit-ediff-* command has to be used explicitly. If it cannot read the user's mind at all, then it asks the user for a command to run.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-ediff.el
;;;###autoload(autoload 'magit-ediff-dwim "magit-ediff" nil t)
(transient-define-suffix magit-ediff-dwim ()
  "Compare, stage, or resolve using Ediff.
This command tries to guess what file, and what commit or range
the user wants to compare, stage, or resolve using Ediff.  It
might only be able to guess either the file, or range or commit,
in which case the user is asked about the other.  It might not
always guess right, in which case the appropriate `magit-ediff-*'
command has to be used explicitly.  If it cannot read the user's
mind at all, then it asks the user for a command to run."
  (interactive)
  (magit-section-case
    (hunk (save-excursion
            (goto-char (oref (oref it parent) start))
            (magit-ediff-dwim)))
    (t
     (let ((range (magit-diff--dwim))
           (file (magit-current-file))
           command revA revB)
       (pcase range
         ((and (guard (not magit-ediff-dwim-show-on-hunks))
               (or 'unstaged 'staged))
          (setq command (if (magit-anything-unmerged-p)
                            magit-ediff-dwim-resolve-function
                          #'magit-ediff-stage)))
         ('unstaged (setq command #'magit-ediff-show-unstaged))
         ('staged (setq command #'magit-ediff-show-staged))
         (`(commit . ,value)
          (setq command #'magit-ediff-show-commit)
          (setq revB value))
         (`(stash . ,value)
          (setq command #'magit-ediff-show-stash)
          (setq revB value))
         ((pred stringp)
          (pcase-let ((`(,a ,b) (magit-ediff-compare--read-revisions range)))
            (setq command #'magit-ediff-compare)
            (setq revA a)
            (setq revB b)))
         (_
          (when (derived-mode-p 'magit-diff-mode)
            (pcase (magit-diff-type)
              ('committed (pcase-let ((`(,a ,b)
                                       (magit-ediff-compare--read-revisions
                                        magit-buffer-diff-range)))
                            (setq revA a)
                            (setq revB b)))
              ((guard (not magit-ediff-dwim-show-on-hunks))
               (setq command #'magit-ediff-stage))
              ('unstaged  (setq command #'magit-ediff-show-unstaged))
              ('staged    (setq command #'magit-ediff-show-staged))
              ('undefined (setq command nil))
              (_          (setq command nil))))))
       (cond ((not command)
              (call-interactively
               (magit-read-char-case
                   "Failed to read your mind; do you want to " t
                 (?c "[c]ommit"  #'magit-ediff-show-commit)
                 (?r "[r]ange"   #'magit-ediff-compare)
                 (?s "[s]tage"   #'magit-ediff-stage)
                 (?m "[m] resolve remaining conflicts"
                     #'magit-ediff-resolve-rest)
                 (?M "[M] resolve all conflicts"
                     #'magit-ediff-resolve-all))))
             ((eq command #'magit-ediff-compare)
              (apply #'magit-ediff-compare revA revB
                     (magit-ediff-read-files revA revB file)))
             ((eq command #'magit-ediff-show-commit)
              (magit-ediff-show-commit revB))
             ((eq command #'magit-ediff-show-stash)
              (magit-ediff-show-stash revB))
             (file
              (funcall command file))
             ((call-interactively command)))))))