Skip to content

Commit e35206b

Browse files
feat(builder): Try shallow cloning buildpack repos
Try to shallow clone buildpack repositories before falling back to deep cloning. This improves clone times significantly.
1 parent 1d4eaf5 commit e35206b

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

builder/image/slugbuilder/builder/install-buildpacks

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@ download_buildpack() {
88
buildpack_name=$(basename $buildpack_url)
99
buildpack_commit="$2"
1010

11-
git clone $buildpack_url $BUILDPACK_INSTALL_PATH/$buildpack_name
12-
pushd $BUILDPACK_INSTALL_PATH/$buildpack_name &>/dev/null
13-
git checkout --quiet $buildpack_commit
14-
popd &>/dev/null
11+
set +e
12+
git clone --branch $buildpack_commit --depth 1 $buildpack_url $BUILDPACK_INSTALL_PATH/$buildpack_name
13+
SHALLOW_CLONED=$?
14+
set -e
15+
if [ $SHALLOW_CLONED -ne 0 ]; then
16+
# if the shallow clone failed partway through, clean up and try a full clone
17+
rm -rf $BUILDPACK_INSTALL_PATH/$buildpack_name
18+
git clone $buildpack_url $BUILDPACK_INSTALL_PATH/$buildpack_name
19+
pushd $BUILDPACK_INSTALL_PATH/$buildpack_name &>/dev/null
20+
git checkout --quiet $buildpack_commit
21+
popd &>/dev/null
22+
fi
1523

1624
}
1725

0 commit comments

Comments
 (0)