From 5e2dcbec35ce586abd115de668331ac78c04e66b Mon Sep 17 00:00:00 2001 From: giveen Date: Wed, 14 Jan 2026 15:54:42 -0700 Subject: [PATCH] scripts: make add_hexstrike_subtree.sh idempotent; support FORCE_SUBTREE_PULL for updates --- scripts/add_hexstrike_subtree.sh | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/scripts/add_hexstrike_subtree.sh b/scripts/add_hexstrike_subtree.sh index 1982f9b..69dc060 100755 --- a/scripts/add_hexstrike_subtree.sh +++ b/scripts/add_hexstrike_subtree.sh @@ -9,8 +9,24 @@ PREFIX="third_party/hexstrike" BRANCH="main" echo "This will add HexStrike as a git subtree under ${PREFIX}." -echo "If you already have a subtree, use 'git subtree pull' instead.\n" +echo "If the subtree already exists, the script will pull and rebase the subtree instead.\n" -git subtree add --prefix="${PREFIX}" "${REPO_URL}" "${BRANCH}" --squash - -echo "HexStrike subtree added under ${PREFIX}." +if [ -d "${PREFIX}" ]; then + echo "Detected existing subtree at ${PREFIX}." + if [ "${FORCE_SUBTREE_PULL:-false}" = "true" ]; then + echo "FORCE_SUBTREE_PULL=true: pulling latest changes into existing subtree..." + git subtree pull --prefix="${PREFIX}" "${REPO_URL}" "${BRANCH}" --squash || { + echo "git subtree pull failed; attempting without --squash..." + git subtree pull --prefix="${PREFIX}" "${REPO_URL}" "${BRANCH}" || exit 1 + } + echo "Subtree at ${PREFIX} updated." + else + echo "To update the existing subtree run:" + echo " FORCE_SUBTREE_PULL=true bash scripts/add_hexstrike_subtree.sh" + echo "Or run manually: git subtree pull --prefix=\"${PREFIX}\" ${REPO_URL} ${BRANCH} --squash" + fi +else + echo "Adding subtree for the first time..." + git subtree add --prefix="${PREFIX}" "${REPO_URL}" "${BRANCH}" --squash + echo "HexStrike subtree added under ${PREFIX}." +fi