diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 30 |
1 files changed, 19 insertions, 11 deletions
@@ -14,17 +14,17 @@ import ( func main() { log.SetFlags(0) + defer log.Println("Exiting craft") log.Println("Starting craft") log.Printf("Git hook type: %s\n", getHookType()) - - cwd, err := os.Getwd() - if err != nil { - log.Fatal(err) - } - fmt.Printf("Current working directory: %s\n", cwd) + log.Printf("Git repository: %s\n", getRepositoryPath()) for { - fmt.Println(getUpdate()) + eof, update := getUpdate() + if eof { + break + } + log.Printf("Git ref update: %s\n", update) } } @@ -55,24 +55,32 @@ func validateHookType(hookType string) { log.Fatalf("Not supported Git hook type '%s'\n", hookType) } +func getRepositoryPath() string { + cwd, err := os.Getwd() + if err != nil { + log.Fatal(err) + } + return cwd +} + 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) + ret := fmt.Sprintf("'%s' from '%s' to '%s'", u.ref, u.old, u.updated) return ret } -func getUpdate() update { +func getUpdate() (bool, 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) + return true, u } else { log.Fatal(err) } } - return u + return false, u } |