template-ebook/tools/dev-setup.sh

34 lines
808 B
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# dev-setup.sh
# Erstellt Git-Hook, der beim Branchwechsel eine Datei mit dem Branch-Namen erstellt
HOOK_PATH=".git/hooks/post-checkout"
echo "⚙️ Richte Git-Hook ein für Branch-Datei (z.B. BRANCH-MAIN)..."
# Prüfe ob .git-Verzeichnis existiert
if [ ! -d .git ]; then
echo "❌ Dieses Skript muss im Root eines Git-Repositories ausgeführt werden."
exit 1
fi
# Hook-Inhalt
read -r -d '' HOOK_SCRIPT <<'EOF'
#!/bin/sh
branch=$(git rev-parse --abbrev-ref HEAD)
# Entferne alte BRANCH-* Dateien
rm -f BRANCH-*
# Erzeuge neue Datei mit aktuellem Branchnamen
touch "BRANCH-${branch}"
EOF
# Hook schreiben
echo "$HOOK_SCRIPT" > "$HOOK_PATH"
chmod +x "$HOOK_PATH"
echo "✅ Git-Hook erstellt: $HOOK_PATH"
echo "📄 Beispiel: BRANCH-main wird erstellt beim Wechsel auf 'main'"