From f73b4c84e5a7de7d00478552577fba5deb5ae2ff Mon Sep 17 00:00:00 2001 From: Davide Scaini Date: Sun, 29 Mar 2026 16:12:09 +0200 Subject: [PATCH] fix publish.sh: collect file list before orphan branch switch --- publish.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/publish.sh b/publish.sh index b0d993c..814b3d9 100755 --- a/publish.sh +++ b/publish.sh @@ -29,8 +29,12 @@ if [[ ! -f "$MANIFEST" ]]; then exit 1 fi +# Collect file list AND stage into temp dir before touching git state. +# Both must happen here — `git rm -rf .` removes the manifest itself, +# so it can't be re-read during the orphan branch step. STAGING="$(mktemp -d)" trap 'rm -rf "$STAGING"' EXIT +FILES=() while IFS= read -r relpath || [[ -n "$relpath" ]]; do [[ -z "$relpath" || "$relpath" == \#* ]] && continue @@ -46,10 +50,11 @@ while IFS= read -r relpath || [[ -n "$relpath" ]]; do echo "ERROR: '${relpath}' in manifest but not found (no override, no original)" exit 1 fi + FILES+=("$relpath") done < "$MANIFEST" echo "Files to be published:" -find "$STAGING" -type f | sed "s|${STAGING}/||" | sort +printf ' %s\n' "${FILES[@]}" if $DRY_RUN; then echo "" @@ -57,16 +62,16 @@ if $DRY_RUN; then exit 0 fi +# Create orphan branch, wipe working tree, restore only manifest files git -C "$LOCAL_DIR" checkout --orphan _public_tmp git -C "$LOCAL_DIR" rm -rf . --quiet cp -r "${STAGING}/." "${LOCAL_DIR}/" TIMESTAMP="$(date -u +%Y-%m-%dT%H:%M:%SZ)" -# Add only files from the manifest — never picks up untracked files not in the manifest -while IFS= read -r relpath || [[ -n "$relpath" ]]; do - [[ -z "$relpath" || "$relpath" == \#* ]] && continue +# Add only manifest files — never picks up untracked files outside the manifest +for relpath in "${FILES[@]}"; do git -C "$LOCAL_DIR" add -- "$relpath" -done < "$MANIFEST" +done git -C "$LOCAL_DIR" commit -m "Published ${TIMESTAMP}" git -C "$LOCAL_DIR" push --force "$REMOTE" "HEAD:${BRANCH}"