Commit 6cf97f5c authored by Kyle Meyer's avatar Kyle Meyer Committed by Jonas Bernoulli

magit-reverse-files: Extend binary file check

The magit apply variants fail on binary files because they operate on
diff output that exists in the buffer, and that output isn't (and
shouldn't be) inserted with `git diff --binary'.  d0e04a14
(magit-reverse-files: do not attempt to reverse binary files,
2015-03-06) provided a more informative error message by checking for
staged binary files.  Teach magit-reverse-files to also check for
binary files when reversing files from revision and diff buffers.

For revision mode, note that we use `diff REV^..REV' rather than
`diff-index REV', but diff-index would be needed to match what the
revision buffer shows for merge and root commits.  However, using
diff-index isn't worth the added complexity.  In the case of a merge
commit, `diff REV^..REV' would still return the correct list of binary
files in the very rare case that a binary file shows up as a resolved
path in a revision buffer.  In the case of a root commit, we'd fail to
detect binary files, but this just means that we fall back to
displaying a less informative error message in the process buffer.

Closes #3625.
parent d4240f5e
......@@ -644,7 +644,14 @@ so causes the change to be applied to the index as well."
(defun magit-reverse-files (sections args)
(pcase-let ((`(,binaries ,sections)
(let ((bs (magit-binary-files "--cached")))
(let ((bs (magit-binary-files
(cond ((derived-mode-p 'magit-revision-mode)
(let ((rev (car magit-refresh-args)))
(format "%s^..%s" rev rev)))
((derived-mode-p 'magit-diff-mode)
(car magit-refresh-args))
(t
"--cached")))))
(--separate (member (oref it value) bs)
sections))))
(magit-confirm-files 'reverse (--map (oref it value) sections))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment