diff --git a/tools/branch-deploy.sh b/tools/branch-deploy.sh
index 337fb80..a2bfb9c 100755
--- a/tools/branch-deploy.sh
+++ b/tools/branch-deploy.sh
@@ -3,22 +3,20 @@
# Useful for deploying all PRs/branches of a Hugo installation to a test URL for viewing.
set -u
-# Args: folder
+# Args: folder, baseurl
TARGET_FOLDER=$(realpath $1)
-URL_BASE="$2"
+BASE_URL="$2"
-INDEX_PAGE="${TARGET_FOLDER}/index.html"
mkdir -p "${TARGET_FOLDER}"
# Track all remote branches locally
+git remote prune origin > /dev/null
git branch -r | grep -v '\->' | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | while read remote; do git branch --track "${remote#origin/}" "$remote" >/dev/null 2>&1; done
# Pull the branches
git pull --all > /dev/null
git fetch --all > /dev/null
-echo -e "
Branches
\n" > "${INDEX_PAGE}"
-
# Iterate each local branch, and check it out into tmp folder, then build into the destination folder
for BRANCH in $(git for-each-ref --format='%(refname:short)' refs/heads); do
echo "Building ${BRANCH}"
@@ -31,15 +29,19 @@ for BRANCH in $(git for-each-ref --format='%(refname:short)' refs/heads); do
git --work-tree="${TEMP_FOLDER}" checkout "${BRANCH}" -- .
# Build to the destination folder
- hugo --gc -b "${URL_BASE}/${BRANCH}" -s "${TEMP_FOLDER}" -d "${TARGET_FOLDER}/${BRANCH}" > /dev/null
-
- # Add to the index page
- echo " - ${BRANCH}
" >> "${INDEX_PAGE}"
+ hugo --gc -b "${BASE_URL}/${BRANCH}" -s "${TEMP_FOLDER}" -d "${TARGET_FOLDER}/${BRANCH}" > /dev/null
# Cleanup the temp folder
rm -rf "${TEMP_FOLDER}"
done
+# Build the index page
+INDEX_PAGE="${TARGET_FOLDER}/index.html"
+
+echo -e "Branches
\n" > "${INDEX_PAGE}"
+for BRANCH in $(git for-each-ref --format='%(refname:short)' refs/heads); do
+ echo " - ${BRANCH}
" >> "${INDEX_PAGE}"
+done
echo -e "
\nLast Updated: $(date)
" >> "${INDEX_PAGE}"
# Reset the repo back to main