Files
shop10/scripts/git-sync.sh
T

39 lines
1.1 KiB
Bash

#!/bin/bash
# Синхронизация с origin/main (исправляет detached HEAD)
set -euo pipefail
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/shop-root.sh"
if [ ! -d .git ]; then
echo "Ошибка: в $SHOP_ROOT нет .git — нужен полный clone:"
echo " git clone <URL-репозитория> /opt/shop"
exit 1
fi
git config --global --add safe.directory "$SHOP_ROOT" 2>/dev/null || true
echo "=== git sync: $SHOP_ROOT ==="
git fetch origin
if git symbolic-ref -q HEAD >/dev/null 2>&1; then
BRANCH=$(git branch --show-current)
echo "Текущая ветка: ${BRANCH:-?}"
else
echo "Состояние: detached HEAD ($(git rev-parse --short HEAD))"
BRANCH=""
fi
if [ "$BRANCH" != "main" ]; then
if git show-ref --verify --quiet refs/remotes/origin/main; then
git checkout -B main origin/main
elif git show-ref --verify --quiet refs/heads/main; then
git checkout main
else
echo "Ветка main не найдена на origin"
exit 1
fi
fi
git pull origin main
echo "OK: $(git log -1 --oneline)"