Skip to content

Commit 1c5ae0c

Browse files
author
Matthew Fisher
committed
feat(builder): allow to lock BUILDPACK_URL to a commit
1 parent 1598d72 commit 1c5ae0c

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

  • builder/image/slugbuilder/builder

builder/image/slugbuilder/builder/build.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,24 @@ if [[ -n "$BUILDPACK_URL" ]]; then
8484
rm -fr "$buildpack"
8585

8686
url=${BUILDPACK_URL%#*}
87-
branch=${BUILDPACK_URL#*#}
87+
committish=${BUILDPACK_URL#*#}
8888

89-
if [ "$branch" == "$url" ]; then
90-
branch="master"
89+
if [ "$committish" == "$url" ]; then
90+
committish="master"
9191
fi
9292

93-
git clone --quiet --branch "$branch" --depth=1 "$url" "$buildpack"
93+
set +e
94+
git clone --quiet --branch "$committish" --depth=1 "$url" "$buildpack"
95+
SHALLOW_CLONED=$?
96+
set -e
97+
if [ $SHALLOW_CLONED -ne 0 ]; then
98+
# if the shallow clone failed partway through, clean up and try a full clone
99+
rm -rf "$buildpack"
100+
git clone --quiet "$url" "$buildpack"
101+
pushd "$buildpack" &>/dev/null
102+
git checkout --quiet "$committish"
103+
popd &>/dev/null
104+
fi
94105

95106
selected_buildpack="$buildpack"
96107
buildpack_name=$($buildpack/bin/detect "$build_root") && selected_buildpack=$buildpack

0 commit comments

Comments
 (0)