Skip to content

Commit

Permalink
Merge pull request #24 from tamird/better-git-hooks
Browse files Browse the repository at this point in the history
Add post-rewrite hook
  • Loading branch information
robfig committed May 13, 2015
2 parents 08e6ace + a5e3194 commit e0f2599
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,24 @@ 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
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"},
},
}

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

0 comments on commit e0f2599

Please sign in to comment.