| 43 | } |
| 44 | |
| 45 | func listHooks(repo *repo.Repo) ([]string, error) { |
| 46 | hooksPath := path.Join(repo.Root, ".quickhook") |
| 47 | |
| 48 | entries, err := ioutil.ReadDir(hooksPath) |
| 49 | if err != nil { |
| 50 | if os.IsNotExist(err) { |
| 51 | fmt.Fprintf(os.Stderr, "Missing hooks directory: %v\n", hooksPath) |
| 52 | os.Exit(66) // EX_NOINPUT |
| 53 | } else { |
| 54 | return nil, err |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | var hooks []string |
| 59 | for _, entry := range entries { |
| 60 | name := entry.Name() |
| 61 | // Rename the mutating hook to the regular pre-commit one. |
| 62 | if name == "pre-commit-mutating" { |
| 63 | name = "pre-commit" |
| 64 | } |
| 65 | isHook := name == "pre-commit" || |
| 66 | name == "commit-msg" |
| 67 | if entry.IsDir() && isHook { |
| 68 | hooks = append(hooks, name) |
| 69 | } |
| 70 | } |
| 71 | return lo.Uniq(hooks), nil |
| 72 | } |
| 73 | |
| 74 | func promptForInstallShim(stdin io.Reader, repo *repo.Repo, shimPath string) (bool, error) { |
| 75 | _, err := os.Stat(path.Join(repo.Root, shimPath)) |