From 97777cbd7a497df005123cb8a865aa53617291c9 Mon Sep 17 00:00:00 2001 From: Andrey Epifancev Date: Sun, 18 Oct 2026 19:14:59 +0400 Subject: [PATCH] =?UTF-8?q?fix(scripts):=20sync-statements.sh=20--in-place?= =?UTF-8?q?=20=E2=80=94=20=D0=B7=D0=B0=D1=89=D0=B8=D1=82=D1=8B=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BF=D0=B8=D0=B8=20=D1=81=D1=80=D0=B0=D0=B1=D0=B0=D1=82?= =?UTF-8?q?=D1=8B=D0=B2=D0=B0=D1=8E=D1=82=20=D0=B8=20=D0=BF=D1=80=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B2=D1=82=D0=BE=D1=80=D0=B5,=20.DS=5FStore=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D1=81=D1=87=D0=B8=D1=82=D0=B0=D0=B5=D1=82=D1=81?= =?UTF-8?q?=D1=8F=20=D0=B8=D0=B3=D0=BD=D0=BE=D1=80=D0=B8=D1=80=D1=83=D0=B5?= =?UTF-8?q?=D0=BC=D1=8B=D0=BC=20(#120)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- scripts/sync-statements.sh | 23 +++++++++++++++-------- scripts/test_sync_statements.sh | 5 +++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/scripts/sync-statements.sh b/scripts/sync-statements.sh index e4c0e84..968a062 100755 --- a/scripts/sync-statements.sh +++ b/scripts/sync-statements.sh @@ -247,15 +247,12 @@ if [ "$MODE" = check ]; then exit "$EVAL_CODE" fi -# lay_copy : заменить /api/arm_statements копией из источника, записать VERSION; -# затем защиты (игнор .gitignore хоста, содержимое, на котором остановится перенос в контур) — любая даёт код 1 -lay_copy() { - local root=$1 commit=$2 dest="$1/api/arm_statements" ign pth bad=0 - rm -rf "$dest"; mkdir -p "$root/api" - git -C "$SRC" archive "$commit" arm_statements | tar -x -C "$root/api" - printf '%s\n' "$commit" > "$dest/VERSION" +# guard_copy : защиты копии (игнор .gitignore хоста, содержимое, на котором остановится перенос в контур); +# код 1 со списком, если копию нельзя коммитить. Вызывается и после раскладки, и когда раскладывать нечего. +guard_copy() { + local root=$1 dest="$1/api/arm_statements" ign pth bad=0 ign=$(git -C "$root" ls-files --others --ignored --exclude-standard -- api/arm_statements 2>/dev/null \ - | grep -Ev '(^|/)(__pycache__|\.pytest_cache|\.mypy_cache|\.ruff_cache)(/|$)|\.pyc$' || true) + | grep -Ev '(^|/)(__pycache__|\.pytest_cache|\.mypy_cache|\.ruff_cache)(/|$)|\.pyc$|(^|/)\.DS_Store$' || true) if [ -n "$ign" ]; then echo "файлы копии игнорируются .gitignore хоста, в коммит не попадут:" printf '%s\n' "$ign" | sed 's/^/ /' @@ -271,6 +268,15 @@ lay_copy() { return 0 } +# lay_copy : заменить /api/arm_statements копией из источника, записать VERSION, защиты +lay_copy() { + local root=$1 commit=$2 dest="$1/api/arm_statements" + rm -rf "$dest"; mkdir -p "$root/api" + git -C "$SRC" archive "$commit" arm_statements | tar -x -C "$root/api" + printf '%s\n' "$commit" > "$dest/VERSION" + guard_copy "$root" +} + if [ "$MODE" = in-place ]; then COPY="$HOST_DIR/api/arm_statements" REQS="$HOST_DIR/api/requirements.txt" @@ -308,6 +314,7 @@ if [ "$MODE" = in-place ]; then LAID=0 if [ -d "$COPY" ] && [ -f "$COPY/VERSION" ] && [ "$(tr -d ' \t\r\n' < "$COPY/VERSION")" = "$REF_SHA" ]; then echo "раскладывать нечего: копия уже на $REF ($REF7)" + guard_copy "$HOST_DIR" || die "копию нельзя коммитить (см. выше)" 1 else # 4. раскладка lay_copy "$HOST_DIR" "$REF_SHA" || die "раскладка выполнена, но копию нельзя коммитить (см. выше)" 1 diff --git a/scripts/test_sync_statements.sh b/scripts/test_sync_statements.sh index 1c8df41..8c60f5c 100755 --- a/scripts/test_sync_statements.sh +++ b/scripts/test_sync_statements.sh @@ -271,6 +271,7 @@ reset_hosts cp "$FR/api/requirements.txt" "$WORK/req.bak" put "$FR/api/requirements.txt" "aiohttp==3.14.3" sync 20 "in-place: отказ без зависимости (fresh)" --in-place --host-dir "$FR" --ref origin/main +check "$([ "$(tr -d '\n' < "$FR/api/arm_statements/VERSION")" = "$S2" ] && diff -r -x VERSION "$WORK/arc/arm_statements" "$FR/api/arm_statements" >/dev/null && echo 0 || echo 1)" "in-place: fresh — api/arm_statements не тронут" cp "$WORK/req.bak" "$FR/api/requirements.txt" cp "$H/lines_x.yaml" "$AC/rules/statement_lines.yaml" sync 20 "in-place: код словаря вне перечня" --in-place --host-dir "$WORK/arm-core" --ref origin/main @@ -284,11 +285,15 @@ commit_push "$SRC" "S3 json" test-guards put "$FR/.gitignore" '*.json' sync 1 "in-place: .gitignore прячет файл" --in-place --host-dir "$FR" --ref origin/test-guards check "$(has case.json && has .gitignore && echo 0 || echo 1)" "in-place: в выводе case.json и .gitignore" +sync 1 "in-place: повтор после защиты .gitignore остаётся 1" --in-place --host-dir "$FR" --ref origin/test-guards +check "$(has case.json && has .gitignore && echo 0 || echo 1)" "in-place: повтор — снова case.json и .gitignore" rm "$FR/.gitignore" echo "# /Users/someone" >> "$SRC/arm_statements/steps.py" commit_push "$SRC" "S4 путь" test-guards sync 1 "in-place: содержимое для контура" --in-place --host-dir "$FR" --ref origin/test-guards check "$(has '/Users/' && echo 0 || echo 1)" "in-place: в выводе /Users/" +sync 1 "in-place: повтор после защиты путей остаётся 1" --in-place --host-dir "$FR" --ref origin/test-guards +check "$(has '/Users/' && echo 0 || echo 1)" "in-place: повтор — снова /Users/" git -C "$SRC" checkout -q main [ "$fail" = 0 ] || exit 1