diff --git a/install.go b/install.go index 6fc0e8d..f2bb7ad 100644 --- a/install.go +++ b/install.go @@ -21,12 +21,10 @@ func init() { cmdInstall.Run = runInstall // break init loop } -const gitHook = `#!/bin/bash +const gitHook = `#!/usr/bin/env bash set -e -if [[ $GIT_REFLOG_ACTION != pull* ]]; then - exit 0 -fi +[[ ! $GIT_REFLOG_ACTION =~ %v ]] && exit 0 LOG=$(git log -U0 --oneline -p HEAD@{1}..HEAD %s) [ -z "$LOG" ] && echo "glock: no changes to apply" && exit 0 @@ -34,12 +32,13 @@ echo "glock: applying updates..." glock apply %s <<< "$LOG" ` -type hook struct{ filename, content string } +type hook struct{ filename, content, action string } var vcsHooks = map[*vcsCmd][]hook{ vcsGit: { - {filepath.Join(".git", "hooks", "post-merge"), gitHook}, // git pull - {filepath.Join(".git", "hooks", "post-checkout"), gitHook}, // git pull --rebase + {filepath.Join(".git", "hooks", "post-merge"), gitHook, "pull"}, + {filepath.Join(".git", "hooks", "post-checkout"), gitHook, "pull[[:space:]]+--rebase"}, + {filepath.Join(".git", "hooks", "post-rewrite"), gitHook, "rebase"}, }, } @@ -65,7 +64,7 @@ func runInstall(cmd *Command, args []string) { if err != nil { perror(err) } - var hookContent = fmt.Sprintf(hook.content, glockfilePath, importPath) + var hookContent = fmt.Sprintf(hook.content, hook.action, glockfilePath, importPath) err = ioutil.WriteFile(filename, []byte(hookContent), 0755) if err != nil { perror(err)