61 lines
2.7 KiB
Bash
61 lines
2.7 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
# push-split.sh — push a subdirectory of the monorepo working-copy to its
|
||
|
|
# matching split repo on Hephaestus, preserving history via git-subtree-split.
|
||
|
|
#
|
||
|
|
# Since silentmode/silentmode was deleted and each project lives in its own
|
||
|
|
# repo on the forge (silentmode/theseus, silentmode/ariadne, silentmode/hephaestus,
|
||
|
|
# silentmode/sirius, …), cross-cutting commits made in this working copy need to
|
||
|
|
# be routed to whichever remote corresponds to the touched project.
|
||
|
|
#
|
||
|
|
# Usage:
|
||
|
|
# scripts/push-split.sh <project-dir> [remote-name]
|
||
|
|
#
|
||
|
|
# Examples:
|
||
|
|
# scripts/push-split.sh Hephaestus # → git remote 'hephaestus'
|
||
|
|
# scripts/push-split.sh TheseusNavigator # → git remote 'theseus' (Navigator suffix stripped)
|
||
|
|
# scripts/push-split.sh AriadneResolver # → git remote 'ariadne' (Resolver suffix stripped)
|
||
|
|
# scripts/push-split.sh site-sirius-x sirius # → remote 'sirius' (explicit override)
|
||
|
|
#
|
||
|
|
# List of configured remotes: `git remote -v`
|
||
|
|
#
|
||
|
|
# Notes:
|
||
|
|
# - Only ONE prefix per invocation. Cross-cutting changes that touched multiple
|
||
|
|
# projects need to be run once per touched directory.
|
||
|
|
# - Uses --branch <ephemeral>, pushes, then deletes it. Nothing sticks around.
|
||
|
|
# - Push target is always <remote>:master. Passing --branch was intentional
|
||
|
|
# over --squash: split history is preserved so file blame on the split repo
|
||
|
|
# still points at the real commits.
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
prefix="${1:?usage: push-split.sh <project-dir> [remote-name]}"
|
||
|
|
|
||
|
|
# Derive a remote name from the directory if not passed.
|
||
|
|
# Heuristic: lowercase, strip Navigator/Resolver suffix. Otherwise pass explicitly.
|
||
|
|
default_remote=$(echo "$prefix" | tr '[:upper:]' '[:lower:]' | sed 's/navigator$//; s/resolver$//')
|
||
|
|
remote="${2:-$default_remote}"
|
||
|
|
|
||
|
|
[ -d "$prefix" ] || { echo "error: no such directory: $prefix" >&2; exit 1; }
|
||
|
|
git remote get-url "$remote" >/dev/null 2>&1 || {
|
||
|
|
echo "error: no git remote named '$remote'." >&2
|
||
|
|
echo "available remotes: $(git remote | paste -sd ' ' -)" >&2
|
||
|
|
echo "pass an explicit remote name as the 2nd arg." >&2
|
||
|
|
exit 1
|
||
|
|
}
|
||
|
|
|
||
|
|
# Uncommitted changes get carried into the split — usually not what you want.
|
||
|
|
# Warn (but don't block; sometimes you know what you're doing).
|
||
|
|
if ! git diff --quiet HEAD -- "$prefix" 2>/dev/null; then
|
||
|
|
echo "warning: $prefix has uncommitted changes — those will NOT be included in the split." >&2
|
||
|
|
fi
|
||
|
|
|
||
|
|
branch="_push_${remote}_$$"
|
||
|
|
trap 'git branch -D "$branch" >/dev/null 2>&1 || true' EXIT
|
||
|
|
|
||
|
|
echo "→ splitting $prefix/ into ephemeral branch $branch …"
|
||
|
|
git subtree split --prefix="$prefix" HEAD -b "$branch" >/dev/null
|
||
|
|
|
||
|
|
echo "→ pushing $branch → $remote:master …"
|
||
|
|
git push "$remote" "$branch:master"
|
||
|
|
|
||
|
|
echo "✓ done — see https://code.silentmode.st/silentmode/$remote"
|