@@ -40,6 +40,12 @@ readonly TEMP="$(mktemp -d)"
4040readonly SITE=$PWD /site
4141rm -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+
4349mkdir " $TEMP /content"
4450cp -r . " $TEMP /content/"
4551
@@ -64,8 +70,9 @@ 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 branch -r
75+ git worktree add --detach " $TEMP /current-release" " origin/${DOCS_BRANCHES[0]} "
6976 if [ -d " $TEMP /current-release/docs/versioned" ]; then
7077 cp -r " $TEMP /current-release/docs/versioned" " $TEMP /content/docs/docs"
7178 echo -e " \ndoc_base: /docs/versioned/" >> " $TEMP /content/docs/docs/.meta.yml"
@@ -99,7 +106,7 @@ if [ "$BUILD_VERSIONS" != "no" ]; then
99106 version=${previous[$i]}
100107
101108 echo " Building for previous version $version "
102- git clone --depth 1 -b ${DOCS_BRANCHES[$ i+1]} https://github.com/ ${GIT_SLUG} " $TEMP /docs- $version "
109+ git worktree add --detach " $TEMP /docs- $version " " remotes/origin/ ${DOCS_BRANCHES[i+1]} "
103110 if [ -d " $TEMP /docs-$version /docs/versioned" ]; then
104111 cp -r " $TEMP /docs-$version /docs/versioned" " $TEMP /content/docs/v$version -docs"
105112 echo -e " \ndoc_base: /docs/versioned/" >> " $TEMP /content/docs/v$version -docs/.meta.yml"
@@ -159,6 +166,7 @@ cat golang/_redirects >> site/_redirects
159166
160167# Clean up
161168# rm -rf $TEMP
169+ # git worktree prune
162170echo " Temp dir was: $TEMP "
163171
164172if [ " $1 " = " serve" ]; then
0 commit comments