diff --git a/scripts/add-subtrees.sh b/scripts/add-subtrees.sh new file mode 100644 index 00000000..6c7a473c --- /dev/null +++ b/scripts/add-subtrees.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Usage: +# ./scripts/add-subtrees.sh [prefix] [remote_branch] [target_branch] +# Example: ./scripts/add-subtrees.sh external main add-external-subtrees + +PREFIX="${1:-external}" +REMOTE_BRANCH="${2:-main}" +TARGET_BRANCH="${3:-add-external-subtrees}" + +repos=( + "https://github.com/n8n-io/n8n.git" + "https://github.com/n8n-io/n8n-docs.git" + "https://github.com/n8n-io/n8n-hosting.git" +) + +echo "Preparing branch $TARGET_BRANCH" +git fetch origin +git checkout -B "$TARGET_BRANCH" + +mkdir -p "$PREFIX" + +for repo in "${repos[@]}"; do + name=$(basename -s .git "$repo") + remote="remote-$name" + path="$PREFIX/$name" + + echo "Processing $repo -> $path" + + # add remote (or update its URL if it already exists) + if git remote get-url "$remote" >/dev/null 2>&1; then + git remote set-url "$remote" "$repo" + else + git remote add "$remote" "$repo" + fi + + git fetch "$remote" --depth=1 || git fetch "$remote" + + # Add as subtree (will create a commit on this branch) + if [ -d "$path" ]; then + echo "Path $path already exists; skipping subtree add for $name" + else + git subtree add --prefix="$path" "$remote" "$REMOTE_BRANCH" --squash + fi +done + +echo "Pushing $TARGET_BRANCH to origin" +git push origin "$TARGET_BRANCH" --force-with-lease + +echo "Done. +" \ No newline at end of file