branch: elpa/magit
commit 64e69ea809042a1182c7a0b3e92c1f7c6b4f8b6b
Author: Jonas Bernoulli <jo...@bernoul.li>
Commit: Jonas Bernoulli <jo...@bernoul.li>

    magit--git-insert: Do not return empty string as error message
    
    When RETURN-ERROR is `full' this function returns all stderr output.
    If there was nothing on stderr, then it returned the empty string,
    now it returns the exit code in that case too.
    
    If a caller of `magit--git-wash' uses `wash-anyway' for KEEP-ERROR, it
    likely does so because a non-zero exit code does not necessarily mean
    that an error occurred.  If `magit--git-insert' cannot find any error
    string in such a case, that is because there wasn't actually an error,
    and it must return the exit code.  This does not affect the case when
    there is an actual error because that would be accompanied by non-empty
    stdout.
    
    Callers can then still interpret the non-zero, non-string return value
    as an error, but they don't have to.  (magit--git-wash ... 'wash-anyway
    ...) does not and because it no longer ends up inserting the empty
    string and some separator whitespace before the output from stdout,
    stdout washing does no longer break.
    
    The command `magit-diff-paths' uses `magit--git-wash' as described, and
    it broke when support for `full' as a special RETURN-ERROR was added in
    [1: 1f17e515cf].  (Like "diff", "git diff --no-index" exits with 1 if
    there are differences.)
    
    Fixes second coming of #5093.
    
    1: 2024-11-15 1f17e515cfbef3acfd2bdf990cd206d6ae02010b
       magit--git-{insert,wash}: Potentially use complete error text
---
 lisp/magit-git.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/magit-git.el b/lisp/magit-git.el
index d432531d21..4c5ec28029 100644
--- a/lisp/magit-git.el
+++ b/lisp/magit-git.el
@@ -484,7 +484,8 @@ insert the run command and stderr into the process buffer."
                     (setq errmsg
                           (cond
                            ((eq return-error 'full)
-                            (buffer-string))
+                            (let ((str (buffer-string)))
+                              (and (not (equal str "")) str)))
                            ((functionp magit-git-debug)
                             (funcall magit-git-debug (buffer-string)))
                            ((magit--locate-error-message)))))

Reply via email to