emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/git-commit 78a979fde5 1/3: Support displaying errors that


From: ELPA Syncer
Subject: [nongnu] elpa/git-commit 78a979fde5 1/3: Support displaying errors that occur when washing a section
Date: Sat, 18 Mar 2023 17:01:03 -0400 (EDT)

branch: elpa/git-commit
commit 78a979fde52815242b165f083d171259db28e0b4
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>

    Support displaying errors that occur when washing a section
    
    `magit-git-wash' silently removes a section when the command produces
    no output on stdout and stderr is ignored.  For a section among many,
    that is usually the right thing to do, but when the section is the
    only or primary section of a buffer, then we might want to display
    the error (see subsequent commits).
    
    Add a new function `magit--git-wash', which takes a new argument that
    allows doing that.  Also add variable `magit--git-wash-keep-error' to
    allow forcing that for all sections inserted with `magit-git-wash'.
    That is experimental and might be removed again.
---
 lisp/magit-git.el | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/lisp/magit-git.el b/lisp/magit-git.el
index d928e63901..afeceb9935 100644
--- a/lisp/magit-git.el
+++ b/lisp/magit-git.el
@@ -566,6 +566,8 @@ message and add a section in the respective process buffer."
     (apply #'magit-git-insert args)
     (split-string (buffer-string) "\0" t)))
 
+(defvar magit--git-wash-keep-error nil) ; experimental
+
 (defun magit-git-wash (washer &rest args)
   "Execute Git with ARGS, inserting washed output at point.
 Actually first insert the raw output at point.  If there is no
@@ -573,21 +575,29 @@ output, call `magit-cancel-section'.  Otherwise 
temporarily narrow
 the buffer to the inserted text, move to its beginning, and then
 call function WASHER with ARGS as its sole argument."
   (declare (indent 1))
-  (let ((beg (point)))
-    (setq args (flatten-tree args))
-    (magit-git-insert args)
+  (apply #'magit--git-wash washer magit--git-wash-keep-error args))
+
+(defun magit--git-wash (washer keep-error &rest args)
+  (declare (indent 2))
+  (setq args (flatten-tree args))
+  (let ((beg (point))
+        (exit (if keep-error
+                  (magit-process-git t args)
+                (magit-git-insert args))))
     (if (= (point) beg)
         (magit-cancel-section)
       (unless (bolp)
         (insert "\n"))
-      (save-restriction
-        (narrow-to-region beg (point))
-        (goto-char beg)
-        (funcall washer args))
-      (when (or (= (point) beg)
-                (= (point) (1+ beg)))
-        (magit-cancel-section))
-      (magit-maybe-make-margin-overlay))))
+      (when (zerop exit)
+        (save-restriction
+          (narrow-to-region beg (point))
+          (goto-char beg)
+          (funcall washer args))
+        (when (or (= (point) beg)
+                  (= (point) (1+ beg)))
+          (magit-cancel-section))
+        (magit-maybe-make-margin-overlay)))
+    exit))
 
 (defun magit-git-executable-find (command)
   "Search for COMMAND in Git's exec path, falling back to `exec-path'.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]