Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions scripts/add-subtrees.sh
Original file line number Diff line number Diff line change
@@ -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.
"