fix(scripts): sync-statements.sh --in-place — защиты копии срабатывают и при повторе, .DS_Store не считается игнорируемым (#120)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Andrey Epifancev 2026-10-18 19:14:59 +04:00
parent b5ad8a0f4c
commit 97777cbd7a
2 changed files with 20 additions and 8 deletions

View File

@ -247,15 +247,12 @@ if [ "$MODE" = check ]; then
exit "$EVAL_CODE" exit "$EVAL_CODE"
fi fi
# lay_copy <host_root> <commit>: заменить <host_root>/api/arm_statements копией из источника, записать VERSION; # guard_copy <host_root>: защиты копии (игнор .gitignore хоста, содержимое, на котором остановится перенос в контур);
# затем защиты (игнор .gitignore хоста, содержимое, на котором остановится перенос в контур) — любая даёт код 1 # код 1 со списком, если копию нельзя коммитить. Вызывается и после раскладки, и когда раскладывать нечего.
lay_copy() { guard_copy() {
local root=$1 commit=$2 dest="$1/api/arm_statements" ign pth bad=0 local root=$1 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"
ign=$(git -C "$root" ls-files --others --ignored --exclude-standard -- api/arm_statements 2>/dev/null \ 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 if [ -n "$ign" ]; then
echo "файлы копии игнорируются .gitignore хоста, в коммит не попадут:" echo "файлы копии игнорируются .gitignore хоста, в коммит не попадут:"
printf '%s\n' "$ign" | sed 's/^/ /' printf '%s\n' "$ign" | sed 's/^/ /'
@ -271,6 +268,15 @@ lay_copy() {
return 0 return 0
} }
# lay_copy <host_root> <commit>: заменить <host_root>/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 if [ "$MODE" = in-place ]; then
COPY="$HOST_DIR/api/arm_statements" COPY="$HOST_DIR/api/arm_statements"
REQS="$HOST_DIR/api/requirements.txt" REQS="$HOST_DIR/api/requirements.txt"
@ -308,6 +314,7 @@ if [ "$MODE" = in-place ]; then
LAID=0 LAID=0
if [ -d "$COPY" ] && [ -f "$COPY/VERSION" ] && [ "$(tr -d ' \t\r\n' < "$COPY/VERSION")" = "$REF_SHA" ]; then if [ -d "$COPY" ] && [ -f "$COPY/VERSION" ] && [ "$(tr -d ' \t\r\n' < "$COPY/VERSION")" = "$REF_SHA" ]; then
echo "раскладывать нечего: копия уже на $REF ($REF7)" echo "раскладывать нечего: копия уже на $REF ($REF7)"
guard_copy "$HOST_DIR" || die "копию нельзя коммитить (см. выше)" 1
else else
# 4. раскладка # 4. раскладка
lay_copy "$HOST_DIR" "$REF_SHA" || die "раскладка выполнена, но копию нельзя коммитить (см. выше)" 1 lay_copy "$HOST_DIR" "$REF_SHA" || die "раскладка выполнена, но копию нельзя коммитить (см. выше)" 1

View File

@ -271,6 +271,7 @@ reset_hosts
cp "$FR/api/requirements.txt" "$WORK/req.bak" cp "$FR/api/requirements.txt" "$WORK/req.bak"
put "$FR/api/requirements.txt" "aiohttp==3.14.3" put "$FR/api/requirements.txt" "aiohttp==3.14.3"
sync 20 "in-place: отказ без зависимости (fresh)" --in-place --host-dir "$FR" --ref origin/main 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 "$WORK/req.bak" "$FR/api/requirements.txt"
cp "$H/lines_x.yaml" "$AC/rules/statement_lines.yaml" cp "$H/lines_x.yaml" "$AC/rules/statement_lines.yaml"
sync 20 "in-place: код словаря вне перечня" --in-place --host-dir "$WORK/arm-core" --ref origin/main 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' put "$FR/.gitignore" '*.json'
sync 1 "in-place: .gitignore прячет файл" --in-place --host-dir "$FR" --ref origin/test-guards 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" 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" rm "$FR/.gitignore"
echo "# /Users/someone" >> "$SRC/arm_statements/steps.py" echo "# /Users/someone" >> "$SRC/arm_statements/steps.py"
commit_push "$SRC" "S4 путь" test-guards commit_push "$SRC" "S4 путь" test-guards
sync 1 "in-place: содержимое для контура" --in-place --host-dir "$FR" --ref origin/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/" 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 git -C "$SRC" checkout -q main
[ "$fail" = 0 ] || exit 1 [ "$fail" = 0 ] || exit 1