From e182282eb387d8c73d82e81d2e1fc1aaf5734810 Mon Sep 17 00:00:00 2001
From: xengineering <me@xengineering.eu>
Date: Wed, 30 Aug 2023 21:19:41 +0200
Subject: Add stdin parsing for Git post-receive hook

The first program for this repsoitory will be a Git post-receive hook
which will be used at any source repository which is registered for
automated builds.
---
 main.go | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 main.go

diff --git a/main.go b/main.go
new file mode 100644
index 0000000..ae97800
--- /dev/null
+++ b/main.go
@@ -0,0 +1,39 @@
+package main
+
+// see `man 5 githooks` for details
+
+import (
+	"errors"
+	"fmt"
+	"io"
+	"log"
+	"os"
+)
+
+func main() {
+	for {
+		fmt.Println(getUpdate())
+	}
+}
+
+type update struct {
+	old, updated, ref string
+}
+
+func (u update) String() string {
+	ret := fmt.Sprintf("'%s' updated from '%s' to '%s'", u.ref, u.old, u.updated)
+	return ret
+}
+
+func getUpdate() update {
+	var u update
+	_, err := fmt.Scanf("%s %s %s\n", &u.old, &u.updated, &u.ref)
+	if err != nil {
+		if errors.Is(err, io.EOF) {
+			os.Exit(0)
+		} else {
+			log.Fatal(err)
+		}
+	}
+	return u
+}
-- 
cgit v1.2.3-70-g09d2