summaryrefslogtreecommitdiff
path: root/main.go
blob: 5ddc3862a53b509d37d17ad5fd37dcba4ccdfd4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main

// see `man 5 githooks` for details

import (
	"errors"
	"fmt"
	"io"
	"log"
	"os"
)

func main() {
	cwd, err := os.Getwd()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Current working directory: %s\n", cwd)

	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
}