Files
magistr/.agent/skills/git-sync/scripts/check_and_pull.sh

36 lines
980 B
Bash

#!/bin/bash
echo "📡 Checking for updates locally..."
# 1. Запускаем fetch локально
git fetch origin
if [ $? -ne 0 ]; then
echo "❌ Fetch failed. Check your internet connection and git remote settings."
exit 1
fi
# 2. Проверяем количество новых коммитов (HEAD..@{u})
BEHIND_COUNT=$(git rev-list --count HEAD..@{u} 2>/dev/null)
# Если переменная пустая — значит ошибка в гите
if [ -z "$BEHIND_COUNT" ]; then
echo "⚠️ Git status unknown. Upstream branch might not be set."
exit 1
fi
# 3. Логика обновления
if [ "$BEHIND_COUNT" -gt 0 ]; then
echo "⬇️ Found $BEHIND_COUNT new commit(s). Pulling changes..."
# Выполняем git pull
git pull
if [ $? -eq 0 ]; then
echo "✅ Successfully updated!"
else
echo "❌ Update failed (merge conflicts?)."
fi
else
echo "✨ Already up to date."
fi