playbook/scripts/sync_playbook.sh

42 lines
1.2 KiB
Bash

#!/usr/bin/env sh
set -eu
# Sync TSL Playbook snapshot to project root.
# - Copies docs/standards/tsl_playbook/.agents -> .agents
# - Copies docs/standards/tsl_playbook/.gitattributes -> .gitattributes
# Existing targets are backed up before overwrite.
ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
SRC="$ROOT/docs/standards/tsl_playbook"
AGENTS_SRC="$SRC/.agents"
GITATTR_SRC="$SRC/.gitattributes"
if [ ! -d "$AGENTS_SRC" ]; then
echo "ERROR: Playbook snapshot not found at $AGENTS_SRC" >&2
echo "Run: git subtree add --prefix docs/standards/tsl_playbook <playbook-url> main --squash" >&2
exit 1
fi
timestamp="$(date +%Y%m%d%H%M%S 2>/dev/null || echo bak)"
AGENTS_DST="$ROOT/.agents"
if [ -e "$AGENTS_DST" ]; then
mv "$AGENTS_DST" "$ROOT/.agents.bak.$timestamp"
echo "Backed up existing .agents -> .agents.bak.$timestamp"
fi
cp -R "$AGENTS_SRC" "$AGENTS_DST"
echo "Synced .agents from Playbook."
if [ -f "$GITATTR_SRC" ]; then
GITATTR_DST="$ROOT/.gitattributes"
if [ -e "$GITATTR_DST" ]; then
mv "$GITATTR_DST" "$ROOT/.gitattributes.bak.$timestamp"
echo "Backed up existing .gitattributes -> .gitattributes.bak.$timestamp"
fi
cp "$GITATTR_SRC" "$GITATTR_DST"
echo "Synced .gitattributes from Playbook."
fi
echo "Done."