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
+2 -2
View File
@@ -207,8 +207,8 @@ journalctl -u shop -n 5 --no-pager
Каталог клона — там, где лежат `package.json` и `scripts/` (часто `/opt/shop` или `/opt/shop/shop10`):
```bash
cd /opt/shop/shop10 # ваш путь к репозиторию
git config --global --add safe.directory "$(pwd)"
cd /opt/shop/shop10
bash scripts/git-sync.sh # если detached HEAD или ошибка git pull
bash scripts/server-update.sh
```
+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)"
+11 -5
View File
@@ -1,17 +1,23 @@
#!/bin/bash
# Обновление на сервере: git pull, npm, restart shop
# Запуск из любого места:
# bash /opt/shop/shop10/scripts/server-update.sh
# cd /opt/shop/shop10 && bash scripts/server-update.sh
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=shop-root.sh
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/shop-root.sh"
source "$SCRIPT_DIR/shop-root.sh"
echo "=== Shop update: $SHOP_ROOT ==="
git config --global --add safe.directory "$SHOP_ROOT" 2>/dev/null || true
git pull
if [ ! -d .git ]; then
echo "Ошибка: $SHOP_ROOT не git-репозиторий (нет .git)."
echo "Если код только в /opt/shop/shop10 без git — переустановите:"
echo " mv /opt/shop/shop10 /opt/shop/shop10.bak"
echo " git clone https://git.evilfox.cc/test/shop10.git /opt/shop/shop10"
exit 1
fi
bash "$SCRIPT_DIR/git-sync.sh"
npm install --omit=dev
+21 -21
View File
@@ -1,31 +1,31 @@
#!/bin/bash
# Каталог репозитория (где package.json). Переопределение: SHOP_ROOT=/path
# Каталог репозитория (package.json + по возможности .git)
# Переопределение: SHOP_ROOT=/opt/shop/shop10
_resolve_shop_root() {
if [ -n "${SHOP_ROOT:-}" ] && [ -f "${SHOP_ROOT}/package.json" ]; then
return 0
fi
local here
here="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
if [ -f "${here}/package.json" ]; then
SHOP_ROOT="$here"
return 0
fi
if [ -f /opt/shop/shop10/package.json ]; then
SHOP_ROOT=/opt/shop/shop10
return 0
fi
if [ -f /opt/shop/package.json ]; then
SHOP_ROOT=/opt/shop
return 0
fi
local d
for d in \
"${SHOP_ROOT:-}" \
"$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" \
"/opt/shop/shop10" \
"/opt/shop"; do
[ -z "$d" ] && continue
[ -f "${d}/package.json" ] && [ -d "${d}/.git" ] && SHOP_ROOT="$d" && return 0
done
for d in \
"${SHOP_ROOT:-}" \
"$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" \
"/opt/shop/shop10" \
"/opt/shop"; do
[ -z "$d" ] && continue
[ -f "${d}/package.json" ] && SHOP_ROOT="$d" && return 0
done
return 1
}
if ! _resolve_shop_root; then
echo "Ошибка: не найден каталог Shop (нет package.json)."
echo "Перейдите в каталог клона и запустите:"
echo " bash scripts/server-update.sh"
echo "Или задайте: SHOP_ROOT=/opt/shop/shop10 bash scripts/server-update.sh"
echo " git clone https://git.evilfox.cc/test/shop10.git /opt/shop/shop10"
echo " SHOP_ROOT=/opt/shop/shop10 bash scripts/server-update.sh"
exit 1
fi
+22
View File
@@ -30,6 +30,28 @@ sudo bash scripts/quick-deploy-ubuntu.sh
bash /opt/shop/shop10/scripts/server-update.sh
```
## git: You are not currently on a branch / not a git repository
Клон на теге (detached HEAD) или обновление из `/opt/shop` вместо `/opt/shop/shop10`:
```bash
cd /opt/shop/shop10
git status
bash scripts/git-sync.sh
bash scripts/server-update.sh
```
Если `fatal: not a git repository` в `/opt/shop/shop10`:
```bash
ls -la /opt/shop/shop10/.git
# нет .git — заново:
mv /opt/shop/shop10 /opt/shop/shop10.bak.$(date +%s)
git clone https://git.evilfox.cc/test/shop10.git /opt/shop/shop10
cp /opt/shop/shop10.bak.*/.env /opt/shop/shop10/.env 2>/dev/null || cp /opt/shop/shop10/.env.example /opt/shop/shop10/.env
bash /opt/shop/shop10/scripts/server-update.sh
```
## scripts/server-update.sh: No such file or directory
Вы не в каталоге репозитория или клон в подпапке (например `/opt/shop/shop10`):