Skip to content

Commit d83f749

Browse files
committed
Switch from 'git clone' to 'git worktree add' for higher speed
1 parent 65b7bae commit d83f749

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

hack/build.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ readonly TEMP="$(mktemp -d)"
4040
readonly SITE=$PWD/site
4141
rm -rf site/
4242

43+
# If we're running on Netlify, update git branches
44+
if [ "$CI" == "true" ]; then
45+
git fetch --prune origin
46+
fi
47+
48+
4349
mkdir "$TEMP/content"
4450
cp -r . "$TEMP/content/"
4551

@@ -64,8 +70,8 @@ if [ "$BUILD_VERSIONS" != "no" ]; then
6470
sed -i 's| versioned/| development/|g' "$TEMP/content/config/redirects.yml"
6571

6672
# Handle current release specially, as we don't include a version slug
67-
# TODO: can we make one clone and reuse it, possibly with git worktrees?
68-
git clone --depth 1 -b "${DOCS_BRANCHES[0]}" "https://github.com/${GIT_SLUG}" "$TEMP/current-release"
73+
# Note that git worktree reuses the same git clone, so we don't need to clone 50+MB each time.
74+
git worktree add --detach "$TEMP/current-release" "origin/${DOCS_BRANCHES[0]}"
6975
if [ -d "$TEMP/current-release/docs/versioned" ]; then
7076
cp -r "$TEMP/current-release/docs/versioned" "$TEMP/content/docs/docs"
7177
echo -e "\ndoc_base: /docs/versioned/" >> "$TEMP/content/docs/docs/.meta.yml"
@@ -99,7 +105,7 @@ if [ "$BUILD_VERSIONS" != "no" ]; then
99105
version=${previous[$i]}
100106

101107
echo "Building for previous version $version"
102-
git clone --depth 1 -b ${DOCS_BRANCHES[$i+1]} https://github.com/${GIT_SLUG} "$TEMP/docs-$version"
108+
git worktree add --detach "$TEMP/docs-$version" "origin/${DOCS_BRANCHES[i+1]}"
103109
if [ -d "$TEMP/docs-$version/docs/versioned" ]; then
104110
cp -r "$TEMP/docs-$version/docs/versioned" "$TEMP/content/docs/v$version-docs"
105111
echo -e "\ndoc_base: /docs/versioned/" >> "$TEMP/content/docs/v$version-docs/.meta.yml"
@@ -159,6 +165,7 @@ cat golang/_redirects >> site/_redirects
159165

160166
# Clean up
161167
# rm -rf $TEMP
168+
# git worktree prune
162169
echo "Temp dir was: $TEMP"
163170

164171
if [ "$1" = "serve" ]; then

0 commit comments

Comments
 (0)