-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstall.sh
executable file
·65 lines (53 loc) · 1.85 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env sh
repo='ONSdigital/git-diff-check'
binary='pre-commit'
get_latest_release() { # From https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
# Fetch the most recent release number from github
release_version=$(get_latest_release ${repo})
binary="${binary}_${release_version}"
if [[ "$OSTYPE" == "darwin"* ]]; then
binary="${binary}_darwin-amd64"
target=${HOME}/.githooks
else
echo "OS '${OSTYPE}' not currently supported by installer - please refer to manual instructions in the README."
exit 0
fi
release="https://github.com/${repo}/releases/download/${release_version}/${binary}"
# Create the target location if it doesn't already exist
[ ! -d ${target} ] &&
{
echo "Creating global hooks folder at ${target}";
mkdir -p ${target}
}
# Check if we're up to date
echo "Check for previous versions ..."
[ -f ${target}/pre-commit ] &&
{
existing="$(${target}/pre-commit --version)"
echo "-- found existing version ${existing}"
[ "${existing}" = "$release_version" ] &&
{
echo "-- already up to date!"
exit 0
}
echo "-- new version available ${release_version}"
}
# Fetch the tool
echo "Fetching Git Diff precommit hook ${release_version} ..."
echo "-- from ${release} ..."
curl -L --progress-bar -f ${release} -o "${target}/pre-commit"
# Check whether cURL was successful
[ $? != 0 ] &&
{
echo "Oops, something went wrong. Couldn't fetch!"
exit 1
}
chmod +x "${target}/pre-commit"
# Update the git config
echo "Updating git config ..."
git config --global core.hooksPath ${target}
echo "Add done!"