File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ #
3+ # A git hook called by `git merge`, which afters when a `git pull` is performed on a local repository.
4+ #
5+ # This hook is called with the following parameters:
6+ #
7+ # * `$1` - status flag specifying whether or not the merge being done is a squash merge
8+ #
9+ # This hook cannot does __not__ affect the outcome of `git merge` and is not executed if merge fails due to conflicts.
10+
11+
12+ # VARIABLES #
13+
14+ is_squash=" $1 "
15+
16+
17+ # FUNCTIONS #
18+
19+ # Defines an error handler.
20+ #
21+ # $1 - error status
22+ on_error () {
23+ cleanup
24+ exit " $1 "
25+ }
26+
27+ # Runs clean-up tasks.
28+ cleanup () {
29+ echo ' ' >&2
30+ }
31+
32+ # Checks if Node.js module dependencies have changed.
33+ check_node_deps () {
34+ echo ' Checking changed files...' >&2
35+ local changed_files=" $( git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD) "
36+ echo " ${changed_files} " | grep ' ^package\.json$'
37+ if [[ " $? " -ne 0 ]]; then
38+ return 1
39+ fi
40+ return 0
41+ }
42+
43+ # Cleans Node.js module dependencies.
44+ clean_node_deps () {
45+ echo ' Removing Node.js module dependencies...' >&2
46+ make clean-node
47+ }
48+
49+ # Installs Node.js module dependencies.
50+ install_node_deps () {
51+ echo ' Installing Node.js module dependencies...'
52+ make install
53+ }
54+
55+ # Main execution sequence.
56+ main () {
57+ check_node_deps
58+ if [[ " $? " -ne 0 ]]; then
59+ clean_node_deps
60+ install_node_deps
61+ fi
62+ cleanup
63+ exit 0
64+ }
65+
66+ # Run main:
67+ main
You can’t perform that action at this time.
0 commit comments