code.oscarkilo.com/klex-git/install/main.go

..
main.go
package main

// This binary is executed by the owner of the client Git repo.
// It installs the pre-commit hook that will trigger Klex updates.

import (
  "path"

  "oscarkilo.com/klex-git/util"
)

func main() {
  root, err := util.FindRoot()
  if err != nil {
    panic(err)
  }

  installPostCommitHook(root)
}

func installPostCommitHook(root string) {
  hook := path.Join(root, ".git", "hooks", "pre-commit")
  util.AddLineTo(hook, "#!/bin/sh")
  util.AddLineTo(hook, "go run oscarkilo.com/klex-git/commit")

  // ensure the hook file is executable
  util.RunOrDie("chmod", "a+x", hook)
}