aboutsummaryrefslogtreecommitdiff
path: root/lisp/magit-git.el
diff options
context:
space:
mode:
authorJonas Bernoulli <jonas@bernoul.li>2026-01-21 09:18:03 +0100
committerJonas Bernoulli <jonas@bernoul.li>2026-01-21 09:18:03 +0100
commitc85358f5b0ae990e1f7fa2f15172dd6404a237fe (patch)
tree1fb89409042e933aedaa018d7ccb70812af12b26 /lisp/magit-git.el
parentb44f151051917c648039063e8f70bcd365d87dc4 (diff)
magit-git-string: Return nil if exit status is not zero
Also ignore stderr when determining the first line of output to be returned. (When `magit-git-debug' is non-nil, it is still inserted into the process buffer.) The new implementation is similar to the experimental `magit-git-string-p', except that that did not ignore stderr, which I consider a bug. Define `magit-git-string-p' as an obsolete alias of `magit-git-debug', despite this change in behavior; doing so is more likely to fix latent bugs than to be a breaking change.
Diffstat (limited to 'lisp/magit-git.el')
-rw-r--r--lisp/magit-git.el35
1 files changed, 12 insertions, 23 deletions
diff --git a/lisp/magit-git.el b/lisp/magit-git.el
index 7c5cdfd..414ca02 100644
--- a/lisp/magit-git.el
+++ b/lisp/magit-git.el
@@ -433,22 +433,6 @@ to do the following.
"Execute Git with ARGS, returning t if its exit code is 1."
(= (magit-git-exit-code args) 1))
-(defun magit-git-string-p (&rest args)
- "Execute Git with ARGS, returning the first line of its output.
-If the exit code isn't zero or if there is no output, then return
-nil. Neither of these results is considered an error; if that is
-what you want, then use `magit-git-string-ng' instead.
-
-This is an experimental replacement for `magit-git-string', and
-still subject to major changes."
- (magit--with-refresh-cache (cons default-directory args)
- (magit--with-temp-process-buffer
- (and (zerop (magit-process-git t args))
- (not (bobp))
- (progn
- (goto-char (point-min))
- (buffer-substring-no-properties (point) (line-end-position)))))))
-
(defun magit-git-string-ng (&rest args)
"Execute Git with ARGS, returning the first line of its output.
If the exit code isn't zero or if there is no output, then that
@@ -590,16 +574,18 @@ insert the run command and stderr into the process buffer."
(match-str 1)))
(defun magit-git-string (&rest args)
- "Execute Git with ARGS, returning the first line of its output.
-If there is no output, return nil. If the output begins with a
-newline, return an empty string."
+ "Execute Git with ARGS, returning the first line of its output (stdout).
+If the exit code isn't zero or if there is no output, then return nil.
+Neither of these results is considered an error; if that is what you
+want, then use `magit-git-string-ng' instead."
(setq args (flatten-tree args))
(magit--with-refresh-cache (cons default-directory args)
(magit--with-temp-process-buffer
- (apply #'magit-git-insert args)
- (unless (bobp)
- (goto-char (point-min))
- (buffer-substring-no-properties (point) (line-end-position))))))
+ (and (zerop (apply #'magit-git-insert args))
+ (not (bobp))
+ (progn
+ (goto-char (point-min))
+ (buffer-substring-no-properties (point) (line-end-position)))))))
(defun magit-git-lines (&rest args)
"Execute Git with ARGS, returning its output as a list of lines.
@@ -3000,6 +2986,9 @@ out. Only existing branches can be selected."
;;; _
+(define-obsolete-function-alias 'magit-git-string-p
+ #'magit-git-string "Magit 4.6.0")
+
(define-obsolete-function-alias 'magit-rev-verify-commit
#'magit-commit-p "Magit 4.6.0")