#!/usr/bin/env bash # init_from_upstream.sh — bootstrap a new Exiles addon fork from upstream. # # Usage: # tools/init_from_upstream.sh [upstream-branch] # # Example: # tools/init_from_upstream.sh https://github.com/Ascension-Addons/CallToArms CallToArms # # What it does: # 1. Adds `upstream` remote and fetches it. # 2. Squash-imports the upstream tree at the named branch (default master/main) # into / at the repo root. # 3. Leaves you with a single staged commit you review and finalise. # # What it does NOT do: # - Push anything. # - Tag anything. # - Modify the upstream history (it's a squash import, not a merge). # # After running, verify with: # bash tools/build_zip.sh # unzip -l dist/.zip | head -5 # then `git commit --amend` if you want to edit the message, push, # and tag -coa.1 to trigger the first release. set -euo pipefail if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; then echo "usage: $0 [upstream-branch]" >&2 exit 2 fi upstream_url=$1 folder=$2 branch=${3:-} if [ -d "$folder" ]; then echo "refusing to overwrite existing folder $folder/" >&2 exit 1 fi if ! git remote get-url upstream >/dev/null 2>&1; then git remote add upstream "$upstream_url" else git remote set-url upstream "$upstream_url" fi echo "==> fetching upstream" git fetch --tags upstream if [ -z "$branch" ]; then # Try master, then main. if git rev-parse --verify "upstream/master" >/dev/null 2>&1; then branch=master elif git rev-parse --verify "upstream/main" >/dev/null 2>&1; then branch=main else echo "couldn't find upstream/master or upstream/main; pass branch explicitly" >&2 exit 1 fi fi echo "==> importing tree from upstream/$branch into $folder/" # Extract upstream tree into a temporary worktree-like dir, then move into folder. tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT git archive "upstream/$branch" | tar -x -C "$tmp" mkdir -p "$folder" # rsync preserves dotfiles; --exclude keeps obvious noise out. rsync -a --exclude '.git/' --exclude '.github/' --exclude '.gitea/' \ --exclude '.idea/' --exclude '.vscode/' --exclude '.DS_Store' \ "$tmp"/ "$folder"/ git add "$folder" upstream_sha=$(git rev-parse "upstream/$branch") upstream_short=$(git rev-parse --short "upstream/$branch") git commit -m "Import $folder from upstream@$upstream_short upstream: $upstream_url branch: $branch commit: $upstream_sha" cat < done. next steps: 1. bash tools/build_zip.sh 2. unzip -l dist/$folder.zip | head -5 (expect first entry: $folder/) 3. git push origin master 4. Read $folder/$folder.toc — look for the version string. Tag with -coa.1, e.g.: git tag -a 1.2.3-coa.1 -m "first Exiles release" git push origin 1.2.3-coa.1 The release workflow picks it up and publishes https://git.sub-net.at/Exiles//releases/tag/. The upstream remote stays configured so future rebases / re-imports are one-line: \`git fetch upstream && ...\`. EOF