Skip to content

Commit

Permalink
Use regex and pluggable values
Browse files Browse the repository at this point in the history
  • Loading branch information
tamird committed May 8, 2015
1 parent 2bccabc commit 81d4ac6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ func init() {
const gitHook = `#!/usr/bin/env bash
set -e
[[ $GIT_REFLOG_ACTION != pull* ]] && exit 0
[[ ! $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
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"},
},
}

Expand All @@ -63,7 +63,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)
Expand Down

0 comments on commit 81d4ac6

Please sign in to comment.