Skip to content

Commit

Permalink
Add LEFTHOOK env in hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
A.A.Abroskin committed Jul 12, 2019
1 parent afd67f9 commit f81e7c2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ func addHook(hookName string, fs afero.Fs) {
return
}
// TODO: text/template
template := "#!/bin/bash\n" + autoInstall(hookName, fs) + "\n" +
"cmd=\"lefthook run " + hookName + " $@\"" +
template := `
#!/bin/sh
if [ "{$LEFTHOOK}" = "0" ]; then
exit 0
fi
` + autoInstall(hookName, fs) + "\n" + "cmd=\"lefthook run " + hookName + " $@\"" +
`
if lefthook >/dev/null 2>&1
then
exec $cmd
Expand Down Expand Up @@ -102,9 +108,10 @@ fi

func autoInstall(hookName string, fs afero.Fs) string {
if hookName == checkSumHook {
return "# lefthook_version: " + configChecksum(fs) + "\n" +
return "\n# lefthook_version: " + configChecksum(fs) + "\n\n" +
"cmd=\"lefthook install\"" +
`
if lefthook >/dev/null 2>&1
then
exec $cmd
Expand Down

0 comments on commit f81e7c2

Please sign in to comment.