Skip to content

Commit

Permalink
git:plug-hook now uses the ./ops/git/hooks folder to populate git hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
vorban committed Jul 20, 2021
1 parent 88c685f commit 1717edf
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,7 @@ func main() {
app.Command("git:plug-hook", "Register hooks in the Git repository", func(cmd *cli.Cmd) {
cmd.Action = func() {
fmt.Printf("%s %s\n", color.MagentaString("Executing:"), "git:hook")
code :=
`#!/bin/sh
code := `#!/bin/sh
# don't validate if phpcs is not found
PHPCS="$(command -v phpcs)"
Expand All @@ -352,9 +351,21 @@ if [ ! -z "$FILES" ]; then
fi
fi
exit 0`
err := ioutil.WriteFile(".git/hooks/pre-commit", []byte(code), 0755)
// try to write the specific project hook
// if it cannot be read (i.e. does not exist),
// then write the default code above
script, err := ioutil.ReadFile("ops/git/hooks/pre-commit")
if err != nil {
fmt.Printf("Unable to write file: %v", err)
err := ioutil.WriteFile(".git/hooks/pre-commit", script, 0755)
if err != nil {
fmt.Printf("Unable to write file: %v", err)
}
} else {
fmt.Printf("./ops/git/hooks/pre-commit not found, fallback to default script")
err := ioutil.WriteFile(".git/hooks/pre-commit", []byte(code), 0755)
if err != nil {
fmt.Printf("Unable to write file: %v", err)
}
}
}
})
Expand Down

0 comments on commit 1717edf

Please sign in to comment.