Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
build: rebuild if git HEAD changes
Browse files Browse the repository at this point in the history
Install git hooks which handle cases when git HEAD is changed.
The git hooks just remove config-generated.go file to force
binary rebuild.

Fixes #431.

Signed-off-by: Dmitry Voytik <[email protected]>
  • Loading branch information
Dmitry Voytik committed Aug 18, 2017
1 parent 8f4f4c2 commit 16cab3d
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ QUIET_GENERATE = $(Q:@=@echo ' GENERATE '$@;)
QUIET_INST = $(Q:@=@echo ' INSTALL '$@;)
QUIET_TEST = $(Q:@=@echo ' TEST '$@;)

default: $(TARGET) $(CONFIG) pause
default: $(TARGET) $(CONFIG) pause install-git-hooks
.DEFAULT: default

build: default
Expand Down Expand Up @@ -224,6 +224,7 @@ pause: pause/pause.go
coverage \
default \
install \
install-git-hooks \
pause \
show-header \
show-summary \
Expand Down Expand Up @@ -328,3 +329,43 @@ show-summary: show-header
@printf "\tproxy+shim path (PKGLIBEXECDIR) : %s\n" $(PKGLIBEXECDIR)
@printf "\tpause bundle path (PAUSEROOTPATH) : %s\n" $(PAUSEROOTPATH)
@printf "\n"


# The following git hooks handle HEAD changes:
# post-checkout <prev_head> <new_head> <file_or_branch_checkout>
# post-commit # no parameters
# post-merge <squash_or_not>
# post-rewrite <amend_or_rebase>
#
define GIT_HOOK_POST_CHECKOUT
#!/usr/bin/env bash
prev_head=$$1
new_head=$$2
[[ "$$prev_head" == "$$new_head" ]] && exit
printf "\nexecuting post-checkout git hook\n\n"
rm -f config-generated.go
endef
export GIT_HOOK_POST_CHECKOUT

define GIT_HOOK_POST_GENERIC
#!/usr/bin/env bash
printf "\n executing $$0 git hook\n\n"
rm -f config-generated.go
endef
export GIT_HOOK_POST_GENERIC

# This git-hook is executed after every checkout git operation
.git/hooks/post-checkout: Makefile
@ mkdir -p .git/hooks/
$(QUIET_INST)echo "$$GIT_HOOK_POST_CHECKOUT" >$@
@ chmod +x $@

# This git-hook is executed after every commit, merge, amend or rebase git
# operation
.git/hooks/post-commit .git/hooks/post-merge .git/hooks/post-rewrite: Makefile
@ mkdir -p .git/hooks/
$(QUIET_INST)echo "$$GIT_HOOK_POST_GENERIC" >$@
@ chmod +x $@

install-git-hooks: .git/hooks/post-checkout .git/hooks/post-commit \
.git/hooks/post-merge .git/hooks/post-rewrite

0 comments on commit 16cab3d

Please sign in to comment.