Skip to content

Commit a3c0c45

Browse files
committed
feat(lefthook): make feature installed after git
1 parent cdf3301 commit a3c0c45

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/lefthook/devcontainer-feature.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Lefthook",
33
"id": "lefthook",
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"documentationURL": "http://github.com/omoxyz/devcontainer-features/tree/main/src/lefthook",
66
"description": "Install Lefthook fast polyglot Git hooks manager.",
77
"options": {
@@ -18,5 +18,8 @@
1818
"description": "Install directly from Github release or from package manager (apt).",
1919
"default": true
2020
}
21-
}
21+
},
22+
"installsAfter": [
23+
"ghcr.io/devcontainers/features/git"
24+
]
2225
}

src/lefthook/install.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/usr/bin/env bash
22

3+
if [ "$(id -u)" -ne 0 ]; then
4+
echo -e 'Scripts must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
5+
exit 1
6+
fi
7+
38
source ./utils.sh
49

510
LEFTHOOK_VERSION=${VERSION:-"latest"}
@@ -14,11 +19,6 @@ apt_get_update
1419
# Clean up
1520
rm -rf /var/lib/apt/lists/*
1621

17-
if [ "$(id -u)" -ne 0 ]; then
18-
echo -e 'Scripts must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
19-
exit 1
20-
fi
21-
2222
export DEBIAN_FRONTEND=noninteractive
2323

2424
get_github_filename() {
@@ -39,19 +39,23 @@ install_from_github() {
3939
latest_version=${versions[0]}
4040
prev_version=${versions[1]}
4141

42+
4243
echo "Downloading lefthook v${latest_version}...."
4344

4445
check_packages wget
4546
local arch=$(dpkg --print-architecture)
4647

4748
local filename=$(get_github_filename $latest_version $arch)
4849

50+
set +e
51+
4952
mkdir -p /tmp/lefthook
5053
pushd /tmp/lefthook
5154
wget ${GITHUB_REPO}/releases/download/v${latest_version}/${filename}
5255
local exit_code=$?
5356

5457
set -e
58+
5559
if [ "$exit_code" != "0" ]; then
5660
# Handle situation where git tags are ahead of what was is available to actually download
5761
echo "(!) lefthook version ${latest_version} failed to download. Attempting to fall back to ${prev_version} to retry..."

0 commit comments

Comments
 (0)