Skip to content

Commit 7a588bb

Browse files
committed
Create separate Makefile for initializing git hooks
1 parent caa3859 commit 7a588bb

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

tools/make/lib/init/Makefile

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11

2-
# VARIABLES #
2+
# DEPENDENCIES #
33

4-
# Define the command to copy files:
5-
CP ?= cp
6-
7-
# Define the command for setting executable permissions:
8-
MAKE_EXECUTABLE ?= chmod +x
9-
10-
# Define the destination directory for git hooks:
11-
GIT_HOOKS_DIR ?= $(ROOT_DIR)/.git/hooks
12-
13-
# Define the directory from which to copy git hooks:
14-
TOOLS_GIT_HOOKS_DIR ?= $(TOOLS_DIR)/git/hooks
15-
16-
# Define the path of the `git pre-push` hook:
17-
GIT_HOOK_PRE_PUSH ?= pre-push
4+
include $(TOOLS_MAKE_LIB_DIR)/init/git_hooks.mk
185

196

207
# TARGETS #
@@ -23,9 +10,7 @@ GIT_HOOK_PRE_PUSH ?= pre-push
2310
#
2411
# This target performs initialization tasks, such as installing git hooks, etc.
2512

26-
init:
27-
@$(CP) $(TOOLS_GIT_HOOKS_DIR)/$(GIT_HOOK_PRE_PUSH) $(GIT_HOOKS_DIR)
28-
@$(MAKE_EXECUTABLE) $(GIT_HOOKS_DIR)/$(GIT_HOOK_PRE_PUSH)
13+
init: init-git-hooks
2914

3015
.PHONY: init
3116

tools/make/lib/init/git_hooks.mk

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
# VARIABLES #
3+
4+
# Define the command to copy files:
5+
CP ?= cp
6+
7+
# Define the command for setting executable permissions:
8+
MAKE_EXECUTABLE ?= chmod +x
9+
10+
# Define the directory from which to copy git hooks:
11+
GIT_HOOKS_DIR ?= $(TOOLS_DIR)/git/hooks
12+
13+
# Define a list of hooks:
14+
GIT_HOOKS ?= $(shell find $(GIT_HOOKS_DIR) -type f | xargs -n 1 basename)
15+
16+
# Define the destination directory for git hooks:
17+
GIT_HOOKS_OUT ?= $(ROOT_DIR)/.git/hooks
18+
19+
20+
# TARGETS #
21+
22+
# Installs git hooks.
23+
#
24+
# This target installs [git hooks][1].
25+
#
26+
# [1]: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
27+
28+
init-git-hooks:
29+
@for file in $(GIT_HOOKS); do \
30+
$(CP) $(GIT_HOOKS_DIR)/$$file $(GIT_HOOKS_OUT)/$$file; \
31+
$(MAKE_EXECUTABLE) $(GIT_HOOKS_OUT)/$$file; \
32+
done
33+
34+
.PHONY: init-git-hooks
35+

0 commit comments

Comments
 (0)