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

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

[nongnu] elpa/git-commit a760dd1078: Only insert stderr into log and dif


From: ELPA Syncer
Subject: [nongnu] elpa/git-commit a760dd1078: Only insert stderr into log and diff buffers on failure
Date: Sun, 19 Mar 2023 20:00:57 -0400 (EDT)

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

    Only insert stderr into log and diff buffers on failure
    
    In [1: 78a979fde5] we added support for inserting git's stderr inline
    when washing a section and in [2: 2bd3db69d6] and [3: d05b1ed381] we
    started using that.  However, that did not take into account that git
    may output warnings while still succeeding.  In that case we must not
    insert the warnings because the section washers are not prepared to
    deal with them.
    
    1: 2023-03-18 78a979fde52815242b165f083d171259db28e0b4
       Support displaying errors that occur when washing a section
    
    2: 2023-03-18 2bd3db69d60e90cf4f4139a2bdae5bb448685e37
       Show errors inline in diff buffers
    
    3: 2023-03-18 d05b1ed381c44d53dfe16a964169ecbdae9067ff
       Show errors inline in log buffers
---
 lisp/magit-git.el | 56 ++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 33 insertions(+), 23 deletions(-)

diff --git a/lisp/magit-git.el b/lisp/magit-git.el
index bedb121422..ddecdb7c8a 100644
--- a/lisp/magit-git.el
+++ b/lisp/magit-git.el
@@ -501,30 +501,37 @@ a boolean, then raise an error."
   "Execute Git with ARGS, inserting its output at point.
 If Git exits with a non-zero exit status, then show a message and
 add a section in the respective process buffer."
+  (apply #'magit--git-insert nil args))
+
+(defun magit--git-insert (return-error &rest args)
   (setq args (magit-process-git-arguments args))
-  (if magit-git-debug
+  (if (or return-error magit-git-debug)
       (let (log)
         (unwind-protect
-            (progn
+            (let (exit errmsg)
               (setq log (make-temp-file "magit-stderr"))
               (delete-file log)
-              (let ((exit (magit-process-git (list t log) args)))
-                (when (> exit 0)
-                  (let ((msg "Git failed"))
-                    (when (file-exists-p log)
-                      (setq msg (with-temp-buffer
-                                  (insert-file-contents log)
-                                  (goto-char (point-max))
-                                  (if (functionp magit-git-debug)
-                                      (funcall magit-git-debug (buffer-string))
-                                    (magit--locate-error-message))))
-                      (let ((magit-git-debug nil))
-                        (with-current-buffer (magit-process-buffer t)
-                          (magit-process-insert-section default-directory
-                                                        magit-git-executable
-                                                        args exit log))))
-                    (message "%s" msg)))
-                exit))
+              (setq exit (magit-process-git (list t log) args))
+              (when (> exit 0)
+                (when (file-exists-p log)
+                  (with-temp-buffer
+                    (insert-file-contents log)
+                    (goto-char (point-max))
+                    (setq errmsg
+                          (if (functionp magit-git-debug)
+                              (funcall magit-git-debug (buffer-string))
+                            (magit--locate-error-message))))
+                  (unless return-error
+                    (let ((magit-git-debug nil))
+                      (with-current-buffer (magit-process-buffer t)
+                        (magit-process-insert-section default-directory
+                                                      magit-git-executable
+                                                      args exit log)))))
+                (unless return-error
+                  (if errmsg
+                      (message "%s" errmsg)
+                    (message "Git returned with exit-code %s" exit))))
+              (or errmsg exit))
           (ignore-errors (delete-file log))))
     (magit-process-git (list t nil) args)))
 
@@ -581,14 +588,17 @@ call function WASHER with ARGS as its sole argument."
   (declare (indent 2))
   (setq args (flatten-tree args))
   (let ((beg (point))
-        (exit (if keep-error
-                  (magit-process-git t args)
-                (magit-git-insert args))))
+        (exit (magit--git-insert keep-error args)))
+    (when (stringp exit)
+      (goto-char beg)
+      (insert (propertize exit 'face 'error))
+      (unless (bolp)
+        (insert "\n")))
     (if (= (point) beg)
         (magit-cancel-section)
       (unless (bolp)
         (insert "\n"))
-      (when (zerop exit)
+      (when (equal exit 0)
         (save-restriction
           (narrow-to-region beg (point))
           (goto-char beg)



reply via email to

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