@@ -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,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
162169echo " Temp dir was: $TEMP "
163170
164171if [ " $1 " = " serve" ]; then
0 commit comments