WriteHooks write git hooks to the given outDir
(outDir string)
| 25 | |
| 26 | // WriteHooks write git hooks to the given outDir |
| 27 | func WriteHooks(outDir string) (retErr error) { |
| 28 | hookFilePath := filepath.Join(outDir, commitMsgHook) |
| 29 | // commit-msg needs to be executable |
| 30 | file, err := os.OpenFile(hookFilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0700) |
| 31 | if err != nil { |
| 32 | return err |
| 33 | } |
| 34 | |
| 35 | defer func() { |
| 36 | err1 := file.Close() |
| 37 | if retErr == nil && err1 != nil { |
| 38 | retErr = err1 |
| 39 | } |
| 40 | }() |
| 41 | |
| 42 | _, err = file.WriteString(hookMessage) |
| 43 | if err != nil { |
| 44 | return err |
| 45 | } |
| 46 | return nil |
| 47 | } |