Skip to content

Commit

Permalink
Merge pull request #27 from Arkweid/move-lefthook-skip-on-top
Browse files Browse the repository at this point in the history
Move lefthook skip on top
  • Loading branch information
Abroskin Alexander authored Jul 12, 2019
2 parents afd67f9 + 76ffed4 commit 67e70ae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 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
4 changes: 3 additions & 1 deletion cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var availableHooks = [...]string{
}

var checkSumHook = "prepare-commit-msg"
var force bool

var installCmd = &cobra.Command{
Use: "install",
Expand All @@ -48,13 +49,14 @@ var installCmd = &cobra.Command{
var appFs = afero.NewOsFs()

func init() {
rootCmd.PersistentFlags().BoolVarP(&force, "force", "f", false, "reinstall hooks without checking config version")
rootCmd.AddCommand(installCmd)
}

// InstallCmdExecutor execute basic configuration
func InstallCmdExecutor(args []string, fs afero.Fs) {
if yes, _ := afero.Exists(fs, getConfigYamlPath()); yes {
if !isConfigSync(fs) {
if !isConfigSync(fs) || force {
log.Println(au.Cyan("SYNCING"), au.Bold("lefthook.yml"))
DeleteGitHooks(fs)
AddGitHooks(fs)
Expand Down

0 comments on commit 67e70ae

Please sign in to comment.