[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/git-commit 438f3dc434 2/2: magit-diff-dwim: Support module
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/git-commit 438f3dc434 2/2: magit-diff-dwim: Support modules their commits |
Date: |
Tue, 1 Mar 2022 10:58:10 -0500 (EST) |
branch: elpa/git-commit
commit 438f3dc43425d178f0725871795a727b620ba1dc
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>
magit-diff-dwim: Support modules their commits
This is a bit ugly but I doubt that teaching `magit-diff--dwim'
about modules would be the right thing to do and even if we did,
the changes in `magit-diff-dwim' would still have to go beyond
just adding two more pcase cases.
Closes #4151.
---
lisp/magit-base.el | 3 ++-
lisp/magit-diff.el | 45 ++++++++++++++++++++++++++++++---------------
lisp/magit-submodule.el | 1 +
3 files changed, 33 insertions(+), 16 deletions(-)
diff --git a/lisp/magit-base.el b/lisp/magit-base.el
index 623afa531d..e0de9ba37a 100644
--- a/lisp/magit-base.el
+++ b/lisp/magit-base.el
@@ -448,7 +448,8 @@ and delay of your graphical environment or operating
system."
(header :initform nil)))
(defclass magit-module-section (magit-file-section)
- ((keymap :initform 'magit-hunk-section-map)))
+ ((keymap :initform 'magit-hunk-section-map)
+ (range :initform nil)))
(defclass magit-hunk-section (magit-section)
((keymap :initform 'magit-hunk-section-map)
diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el
index 07205dcb7d..ee51b2e535 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -1019,21 +1019,36 @@ and `:slant'."
(defun magit-diff-dwim (&optional args files)
"Show changes for the thing at point."
(interactive (magit-diff-arguments))
- (pcase (magit-diff--dwim)
- (`unmerged (magit-diff-unmerged args files))
- (`unstaged (magit-diff-unstaged args files))
- (`staged
- (let ((file (magit-file-at-point)))
- (if (and file (equal (cddr (car (magit-file-status file))) '(?D ?U)))
- ;; File was deleted by us and modified by them. Show the latter.
- (magit-diff-unmerged args (list file))
- (magit-diff-staged nil args files))))
- (`(stash . ,value) (magit-stash-show value args))
- (`(commit . ,value)
- (magit-diff-range (format "%s^..%s" value value) args files))
- ((and range (pred stringp))
- (magit-diff-range range args files))
- (_ (call-interactively #'magit-diff-range))))
+ (let ((default-directory default-directory)
+ (section (magit-current-section)))
+ (cond
+ ((magit-section-match 'module section)
+ (setq default-directory
+ (expand-file-name
+ (file-name-as-directory (oref section value))))
+ (magit-diff-range (oref section range)))
+ (t
+ (when (magit-section-match 'module-commit section)
+ (setq args nil)
+ (setq files nil)
+ (setq default-directory
+ (expand-file-name
+ (file-name-as-directory (magit-section-parent-value section)))))
+ (pcase (magit-diff--dwim)
+ (`unmerged (magit-diff-unmerged args files))
+ (`unstaged (magit-diff-unstaged args files))
+ (`staged
+ (let ((file (magit-file-at-point)))
+ (if (and file (equal (cddr (car (magit-file-status file))) '(?D
?U)))
+ ;; File was deleted by us and modified by them. Show the
latter.
+ (magit-diff-unmerged args (list file))
+ (magit-diff-staged nil args files))))
+ (`(stash . ,value) (magit-stash-show value args))
+ (`(commit . ,value)
+ (magit-diff-range (format "%s^..%s" value value) args files))
+ ((and range (pred stringp))
+ (magit-diff-range range args files))
+ (_ (call-interactively #'magit-diff-range)))))))
(defun magit-diff--dwim ()
"Return information for performing DWIM diff.
diff --git a/lisp/magit-submodule.el b/lisp/magit-submodule.el
index e818ce64f3..5dbe15685c 100644
--- a/lisp/magit-submodule.el
+++ b/lisp/magit-submodule.el
@@ -607,6 +607,7 @@ These sections can be expanded to show the respective
commits."
(propertize module
'font-lock-face 'magit-diff-file-heading)
":")
+ (oset sec range range)
(magit-git-wash
(apply-partially 'magit-log-wash-log 'module)
"-c" "push.default=current" "log" "--oneline" range)