fix: git-sync для detached HEAD, shop-root требует .git

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
shop
2026-05-17 13:24:06 +03:00
parent b7c8d2ed80
commit da77b1f8da
5 changed files with 94 additions and 28 deletions
+38
View File
@@ -0,0 +1,38 @@
#!/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 https://git.evilfox.cc/test/shop10.git /opt/shop/shop10"
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)"