Sending Logs to the Client
You can send messages back to the user's terminal during a push — the same channel git
itself uses for remote: lines. This is handy for showing links, warnings or build status.
push.log()
Call push.log() inside a push handler. Each call becomes a remote: line:
repos.on("push", (push) => {
push.log("")
push.log("Thanks for your push!")
push.log("Open a pull request:")
push.log(` https://example.com/${push.repo}/pull/new/${push.branch}`)
push.log("")
push.accept()
})On the client:
$ git push http://localhost:7005/my-project main
...
remote:
remote: Thanks for your push!
remote: Open a pull request:
remote: https://example.com/my-project/pull/new/main
remote:
To http://localhost:7005/my-project
77bb26e..22918d5 main -> mainListing repositories in a log
log() accepts the same arguments as console.log. Combine it with repos.list() to
show the user other repositories:
repos.on("push", async (push) => {
push.log("")
push.log("Other repositories on this server:")
for (const repo of await repos.list()) {
push.log(` - ${repo}`)
}
push.log("")
push.accept()
})Writing to the response stream
For lower-level control you can listen for the response event and write to the stream
directly. Its log() helper formats a message as a git sideband line:
repos.on("push", (push) => {
push.on("response", (stream) => {
stream.log("streaming a message before the push result")
})
push.accept()
})