RunHook runs the Git hook for $HOOK. - standard input contents are taken from $STDIN - arguments are taken from $ARGS
()
| 265 | // - standard input contents are taken from $STDIN |
| 266 | // - arguments are taken from $ARGS |
| 267 | func (g Git) RunHook() error { |
| 268 | hook, stdin, args := os.Getenv("HOOK"), os.Getenv("STDIN"), strings.Fields(os.Getenv("ARGS")) |
| 269 | switch hook { |
| 270 | case "pre-commit": |
| 271 | return g.preCommit() |
| 272 | case "commit-msg": |
| 273 | var messageFile string |
| 274 | if len(args) > 0 { |
| 275 | messageFile = args[0] |
| 276 | } |
| 277 | return g.commitMsg(messageFile) |
| 278 | case "pre-push": |
| 279 | if mg.Verbose() { |
| 280 | fmt.Println("Running pre-push hook with", args) |
| 281 | } |
| 282 | return g.prePush(stdin, args...) |
| 283 | default: |
| 284 | return fmt.Errorf("Unknown hook %s", hook) |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | // Diff returns error if `git diff` is not empty |
| 289 | func (Git) Diff() error { |