branch: elpa/magit
commit a2165a0ba7ceae43fe67cd8023e866dec48382b9
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>
magit-find-file-noselect: Pivot to file if index has multiple stages
---
lisp/magit-files.el | 3 +++
lisp/magit-git.el | 6 ++++++
2 files changed, 9 insertions(+)
diff --git a/lisp/magit-files.el b/lisp/magit-files.el
index 73541d74c7e..a590cae5f3e 100644
--- a/lisp/magit-files.el
+++ b/lisp/magit-files.el
@@ -115,6 +115,9 @@ the line and column corresponding to that location."
REV is a revision or one of \"{worktree}\" or \"{index}\". Non-nil
REVERT means to revert the buffer. If `ask-revert', then only after
asking. A non-nil value for REVERT is ignored if REV is \"{worktree}\"."
+ (when (and (equal rev "{index}")
+ (length> (magit--file-index-stages file) t))
+ (setq rev "{worktree}"))
(cond-let*
[[topdir (magit-toplevel)]
[file (expand-file-name file topdir)]]
diff --git a/lisp/magit-git.el b/lisp/magit-git.el
index 414ca024372..960a4f9e683 100644
--- a/lisp/magit-git.el
+++ b/lisp/magit-git.el
@@ -1329,6 +1329,12 @@ Sorted from longest to shortest CYGWIN name."
(and (derived-mode-p 'magit-log-mode)
(car magit-buffer-log-files))))
+;;; Blobs
+
+(defun magit--file-index-stages (file)
+ (mapcar (##split-string % " ")
+ (magit-git-lines "ls-files" "--stage" "--" file)))
+
;;; Predicates
(defun magit-no-commit-p ()