Files
gplan-2/tools/sync_worktree_assets.sh

55 lines
2.6 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# worktree 素材同步:主工作区 → 本 worktree 增量拷贝 gitignore 面(game/assets/art/ 终稿与 .import 边车)。
# 素材不入 git,worktree 冷检出与主区新收素材之间必然缺件——呈现/样张断言红的环境成因。
# 只在 worktree 生效(主工作区直跑=无操作);有新拷件或缺 .godot 时跑一次编辑器导入刷新
#(headless --script 模式不触发 import,素材在盘而 .ctex 缺位照样加载失败)。
# 用法:tools/sync_worktree_assets.sh(闸机 code 域起手自动调用;可单独手跑)
# 纪律:拷贝一律相对路径定位(在源根 cd 后按相对路径落盘)——绝对路径 --parents 会在
# 目标仓顶层误产盘符目录树(杂散目录即此误产,熵增闸判红)。
set -u
REPO="$(cd "$(dirname "$0")/.." && pwd)"
GITDIR="$(git -C "$REPO" rev-parse --git-dir 2>/dev/null)"
COMMON="$(git -C "$REPO" rev-parse --git-common-dir 2>/dev/null)"
if [ -z "$GITDIR" ] || [ -z "$COMMON" ] || [ "$GITDIR" = "$COMMON" ]; then
echo "[assets] 主工作区:无同步面"
exit 0
fi
MAIN="$(git -C "$REPO" worktree list --porcelain 2>/dev/null | sed -n 's/^worktree //p' | head -1)"
if [ -z "$MAIN" ]; then
echo "[assets] 取不到主工作区路径(git worktree list 为空),跳过同步"
exit 0
fi
MAIN="$(cd "$MAIN" && pwd)"
[ "$MAIN" = "$REPO" ] && exit 0
_copied=0
if [ -d "$MAIN/game/assets/art" ]; then
_new="$(comm -13 <(cd "$REPO/game/assets/art" 2>/dev/null && find . -type f | sort) \
<(cd "$MAIN/game/assets/art" && find . -type f | sort) | wc -l)"
if [ "$_new" -gt 0 ]; then
mkdir -p "$REPO/game/assets/art"
cp -ru "$MAIN/game/assets/art/." "$REPO/game/assets/art/"
_copied=$((_copied + _new))
fi
fi
_imports="$(comm -13 <(cd "$REPO/game" 2>/dev/null && find . -name '*.import' -type f | sort) \
<(cd "$MAIN/game" && find . -name '*.import' -type f | sort) | wc -l)"
if [ "$_imports" -gt 0 ]; then
(cd "$MAIN/game" && find . -name '*.import' -type f -print0) | while IFS= read -r -d '' f; do
if [ ! -f "$REPO/game/$f" ]; then
mkdir -p "$REPO/game/$(dirname "$f")"
cp "$MAIN/game/$f" "$REPO/game/$f"
fi
done
_copied=$((_copied + _imports))
fi
if [ "$_copied" -gt 0 ] || [ ! -d "$REPO/game/.godot" ]; then
echo "[assets] worktree 素材同步:补拷 $_copied 件(含 .import 边车),刷新导入缓存"
"${GODOT_BIN:-/d/code/godot/Godot_v4.7.2-stable_win64_console.exe}" \
--headless --editor --quit --path "$REPO/game" >/dev/null 2>&1
echo "[assets] 导入刷新完成"
else
echo "[assets] worktree 素材同步:无缺件"
fi
exit 0