stdin processing for run-git

This commit is contained in:
2026-08-13 14:48:52 +02:00
parent 2d0aae1f87
commit 405c17c9f6
3 changed files with 40 additions and 3 deletions
+14
View File
@@ -49,3 +49,17 @@ Most are also exported as direct procedures such as `git-status`, `git-add`,
`git-fetch`, `git-switch`, `git-tag`, `git-log`, `git-diff`, and `git-show`.
See the Scribble documentation for command-specific behavior and return values.
## Low-level Git execution
`run-git` can be used when direct access to Git's stdin/stdout protocol is
needed. Optional text can be supplied to Git with `#:input`.
```racket
(run-git '(credential fill)
#:input "protocol=https\nhost=git.dijkewijk.nl\n\n")
```
The result remains two values: Git's exit code and the ordered
`(source line)` output items.
+8 -3
View File
@@ -88,11 +88,13 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; goal : Run Git without allowing interactive terminal prompts.
; pre : args contains the Git command and its arguments.
; post : Standard output and error have been read completely.
; pre : args contains the Git command and its arguments; input is #f or a string
; that must be written to Git's standard input.
; post : Optional input has been written and standard output and error have been
; read completely.
; result : The exit code and ordered (source line) output items.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (run-git args)
(define (run-git args #:input (input #f))
(putenv "GIT_TERMINAL_PROMPT" "0")
(let-values (((process stdout stdin stderr)
(apply subprocess
@@ -102,6 +104,9 @@
(git-exe)
(map (λ (arg) (format "~a" arg)) args)
)))
(when input
(display input stdin)
(flush-output stdin))
(close-output-port stdin)
(let ((output-channel (make-channel)))
(define (read-output source port)
+18
View File
@@ -251,3 +251,21 @@ Updates the version in @filepath{info.rkt}. The kind is @racket['major],
@racket['minor], or @racket['patch], with @racket['maj] and @racket['min] as
abbreviations. The result is the new version as a list of three integers.
}
@section{Low-level Git execution}
@defproc[(run-git [args list?]
[#:input input (or/c #f string?) #f])
(values exact-integer? list?)]{
Runs Git without interactive terminal prompts. When @racket[input] is a string,
it is written to Git's standard input before that input port is closed.
The procedure returns two values: Git's exit code and the ordered output items,
where each item identifies either @racket['stdout] or @racket['stderr].
@racketblock[
(run-git '(credential fill)
#:input "protocol=https\nhost=git.dijkewijk.nl\n\n")
]
}