aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/coverage-core.el18
-rw-r--r--modules/system-lib.el26
2 files changed, 29 insertions, 15 deletions
diff --git a/modules/coverage-core.el b/modules/coverage-core.el
index 93979530..47e891e6 100644
--- a/modules/coverage-core.el
+++ b/modules/coverage-core.el
@@ -14,6 +14,7 @@
(require 'seq)
(require 'subr-x)
+(require 'system-lib)
(defvar cj/coverage-backends nil
"Registry of coverage backends in priority order.
@@ -197,30 +198,17 @@ empty hash table. Malformed hunk headers are skipped silently."
(forward-line 1)))
result))
-(defun cj/--coverage-git-string (&rest args)
- "Run git with ARGS and return its stdout as a string.
-Signals `user-error' when git exits non-zero."
- (with-temp-buffer
- (let ((status (apply #'process-file "git" nil (current-buffer) nil args))
- (output (buffer-string)))
- (unless (zerop status)
- (user-error "git %s failed with status %s: %s"
- (string-join args " ")
- status
- (string-trim output)))
- output)))
-
(defun cj/--coverage-git-merge-base (base)
"Return the merge-base between HEAD and BASE."
(let ((merge-base (string-trim
- (cj/--coverage-git-string "merge-base" "HEAD" base))))
+ (cj/git-output-or-error "merge-base" "HEAD" base))))
(unless (not (string-empty-p merge-base))
(user-error "git merge-base HEAD %s returned no commit" base))
merge-base))
(defun cj/--coverage-git-diff (&rest args)
"Return git diff output for ARGS plus --unified=0."
- (apply #'cj/--coverage-git-string
+ (apply #'cj/git-output-or-error
(append (list "diff") args (list "--unified=0"))))
(defun cj/--coverage-changed-lines (scope &optional base)
diff --git a/modules/system-lib.el b/modules/system-lib.el
index dc1f8316..3ccec06b 100644
--- a/modules/system-lib.el
+++ b/modules/system-lib.el
@@ -54,6 +54,32 @@ interpolate."
argument
(shell-quote-argument argument)))
+(defun cj/process-output-or-error (program &rest args)
+ "Run PROGRAM with ARGS via `process-file' and return stdout, or signal error.
+
+On zero exit, returns the program's stdout as a string (including any
+trailing newline -- callers that need a trimmed value should call
+`string-trim' themselves). On non-zero exit, signals `user-error' with
+a message naming the program, the exit status, and the (trimmed) output
+so a user inspecting *Messages* can see what went wrong."
+ (with-temp-buffer
+ (let ((status (apply #'process-file program nil (current-buffer) nil args))
+ (output (buffer-string)))
+ (unless (zerop status)
+ (user-error "%s %s failed with status %s: %s"
+ program
+ (string-join args " ")
+ status
+ (string-trim output)))
+ output)))
+
+(defun cj/git-output-or-error (&rest args)
+ "Run git with ARGS and return stdout, or signal `user-error' on failure.
+
+Thin wrapper around `cj/process-output-or-error' with `git' as the
+program."
+ (apply #'cj/process-output-or-error "git" args))
+
(defun cj/log-silently (format-string &rest args)
"Append formatted message (FORMAT-STRING with ARGS) to *Messages* buffer.
This does so without echoing in the minibuffer."