From e1b0a5429aff161c31a920f3cbf7861e966da0f9 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Fri, 8 May 2015 14:12:18 -0400 Subject: [PATCH 1/4] Don't hardcode `bash`'s location --- install.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.go b/install.go index 6fc0e8d..13720b9 100644 --- a/install.go +++ b/install.go @@ -21,7 +21,7 @@ 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 From 2bccabc8e6854f8c78fadc99a92376c0cff20571 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Fri, 8 May 2015 14:13:07 -0400 Subject: [PATCH 2/4] Tersify --- install.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/install.go b/install.go index 13720b9..c593381 100644 --- a/install.go +++ b/install.go @@ -24,9 +24,7 @@ func init() { const gitHook = `#!/usr/bin/env bash set -e -if [[ $GIT_REFLOG_ACTION != pull* ]]; then - exit 0 -fi +[[ $GIT_REFLOG_ACTION != pull* ]] && exit 0 LOG=$(git log -U0 --oneline -p HEAD@{1}..HEAD %s) [ -z "$LOG" ] && echo "glock: no changes to apply" && exit 0 From 81d4ac66298eb6e2654fc0ac6f1d9a8b2e85f642 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Fri, 8 May 2015 14:13:31 -0400 Subject: [PATCH 3/4] Use regex and pluggable values --- install.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/install.go b/install.go index c593381..348c902 100644 --- a/install.go +++ b/install.go @@ -24,7 +24,7 @@ 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 @@ -32,12 +32,12 @@ 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"}, }, } @@ -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) From a5e3194e5976fc0f1fc3fa5b36ab994c683adda8 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Fri, 8 May 2015 14:13:50 -0400 Subject: [PATCH 4/4] Add post-rewrite hook Closes #23. --- install.go | 1 + 1 file changed, 1 insertion(+) diff --git a/install.go b/install.go index 348c902..f2bb7ad 100644 --- a/install.go +++ b/install.go @@ -38,6 +38,7 @@ var vcsHooks = map[*vcsCmd][]hook{ vcsGit: { {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"}, }, }