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