#!/bin/bash # ╔════════════════════════════════════════════════════╗ # ║ VERIFICACIÓN DE REPOSITORIO GIT ║ # ╚════════════════════════════════════════════════════╝ if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then echo "" echo "🛑 Este comando debe ejecutarse dentro de un repositorio Git." exit 1 fi BRANCH="main" # ╔════════════════════════════════════════════════════╗ # ║ INGRESO DE CREDENCIALES ║ # ╚════════════════════════════════════════════════════╝ echo "" echo "🔐 Ingresá tu usuario de Gitea:" echo "╔════════════════╗" read -p "║ Usuario: " USER echo "╚════════════════╝" echo "" echo "🔐 Ingresá tu contraseña o token de Gitea:" echo "╔════════════════════════════════╗" read -s -p "║ Contraseña/Token: " TOKEN echo "" echo "╚════════════════════════════════╝" # ╔════════════════════════════════════════════════════╗ # ║ DETECCIÓN DE CAMBIOS SIN COMMITEAR ║ # ╚════════════════════════════════════════════════════╝ CHANGES=$(git status --porcelain) if [ -n "$CHANGES" ]; then echo "" echo "📦 Se detectaron cambios sin commitear:" echo "$CHANGES" read -p "¿Querés hacer commit automático de estos cambios? (s/n): " COMMIT_RESP if [ "$COMMIT_RESP" == "s" ]; then echo "" read -p "📝 Ingresá el mensaje de commit: " COMMIT_MSG git add . git commit -m "$COMMIT_MSG" echo "✅ Commit realizado." else echo "🛑 No se hizo commit. Continuando sin cambios." fi fi # ╔════════════════════════════════════════════════════╗ # ║ INICIO DE SUBIDA DE ARCHIVOS ║ # ╚════════════════════════════════════════════════════╝ echo "" echo "🚀 Subiendo archivos al repositorio remoto..." echo "" REPO_URL=$(git config --get remote.origin.url) git config --global credential.helper store echo "${REPO_URL/https:\/\//https://$USER:$TOKEN@}" > ~/.git-credentials git push origin $BRANCH if [ $? -ne 0 ]; then echo "" echo "⚠️ Push fallido. Intentando pull con --allow-unrelated-histories..." git pull origin $BRANCH --allow-unrelated-histories if [ $? -eq 0 ]; then echo "" echo "✅ Pull exitoso. Reintentando push..." git push origin $BRANCH else echo "" echo "⚠️ Verificando conflictos..." CONFLICTS=$(git diff --name-only --diff-filter=U) if [ -n "$CONFLICTS" ]; then echo "" echo "🚨 Conflictos detectados:" echo "$CONFLICTS" read -p "¿Hacer merge automático? (s/n): " RESP if [ "$RESP" == "s" ]; then git add . git commit -m "🔀 Merge automático" git push origin $BRANCH echo "🎉 Push completado después del merge." else echo "🛑 Merge cancelado. Resolvé manualmente." fi else echo "❌ Pull falló por otro motivo." fi fi fi