rss/actualizar_repo.sh
2025-08-16 13:12:01 +02:00

35 lines
1.3 KiB
Bash
Executable file
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.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# --- Script para actualizar el repositorio de Git de forma robusta ---
echo "🚀 Iniciando actualización del repositorio..."
# 1. Sincronizar con el repositorio remoto para evitar conflictos
echo "----------------------------------------"
echo "🔄 Sincronizando con el repositorio remoto (git pull)..."
git pull || { echo "❌ Error al hacer git pull. Soluciona los conflictos y vuelve a intentarlo."; exit 1; }
echo "----------------------------------------"
# 2. Preparar todos los archivos modificados y nuevos
echo " Añadiendo todos los archivos al área de preparación (git add .)"
git add .
git add -u # Asegura que los archivos eliminados también se registren
# 3. Crear el mensaje del commit solo si hay cambios
COMMIT_MSG="Actualización del $(date +'%Y-%m-%d a las %H:%M:%S')"
echo "💬 Creando commit con el mensaje: '$COMMIT_MSG'"
# Solo hacemos commit si hay algo que añadir para evitar commits vacíos
if ! git diff-index --quiet HEAD --; then
git commit -m "$COMMIT_MSG"
else
echo " No hay cambios que subir. El repositorio ya está actualizado."
exit 0
fi
# 4. Subir los cambios a GitHub
echo "⬆️ Subiendo cambios al repositorio remoto (git push)..."
git push || { echo "❌ Error al hacer git push. Revisa la conexión o los permisos."; exit 1; }
echo "✅ ¡Actualización completada!"