2026-04-22 16:00:40 +00:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
# unity_auto_sync.sh — Unity 프로젝트 git 자동 sync (BT5-Dev C안, 2026-04-23 PD 승인)
|
|
|
|
|
|
# Unity Editor GitAutoSync.cs(Process.Start) → 본 스크립트 호출 → 실제 git 작업
|
|
|
|
|
|
#
|
|
|
|
|
|
# 용법: unity_auto_sync.sh {init|pull|push|status}
|
|
|
|
|
|
#
|
|
|
|
|
|
# 경로 규약 (C34-11):
|
|
|
|
|
|
# UNITY_PROJECT_ROOT = paths.local.json 에서 읽음 (PC별 실값)
|
|
|
|
|
|
# UNITY_GIT_REMOTE = paths.local.json 에서 읽음 (Gitea 레포)
|
|
|
|
|
|
# BT 본 레포 루트는 git rev-parse 또는 BURNINGTIMES_ROOT 환경변수
|
|
|
|
|
|
|
|
|
|
|
|
set -u
|
|
|
|
|
|
|
|
|
|
|
|
ACTION="${1:-status}"
|
|
|
|
|
|
|
2026-04-22 16:18:49 +00:00
|
|
|
|
# BT 본 레포 루트 결정 — Unity Editor 호출 시 cwd=Unity 레포이므로 git rev-parse가 오판
|
|
|
|
|
|
# 탐색 순서: 환경변수 > 고정 경로 후보 > git rev-parse (fallback)
|
|
|
|
|
|
if [ -n "${BURNINGTIMES_ROOT:-}" ] && [ -d "$BURNINGTIMES_ROOT" ]; then
|
|
|
|
|
|
REPO_ROOT="$BURNINGTIMES_ROOT"
|
|
|
|
|
|
elif [ -d "E:/BurningTimes" ]; then
|
|
|
|
|
|
REPO_ROOT="E:/BurningTimes"
|
|
|
|
|
|
elif [ -d "$HOME/BurningTimes" ]; then
|
|
|
|
|
|
REPO_ROOT="$HOME/BurningTimes"
|
|
|
|
|
|
else
|
|
|
|
|
|
REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null)
|
2026-04-22 16:00:40 +00:00
|
|
|
|
fi
|
2026-04-22 16:18:49 +00:00
|
|
|
|
if [ -z "$REPO_ROOT" ] || [ ! -d "$REPO_ROOT" ]; then
|
|
|
|
|
|
echo "❌ BT 본 레포 찾지 못함 — BURNINGTIMES_ROOT 환경변수 설정 필요" >&2
|
2026-04-22 16:00:40 +00:00
|
|
|
|
exit 2
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# paths.local.json 로드
|
|
|
|
|
|
PATHS_FILE="$REPO_ROOT/paths.local.json"
|
|
|
|
|
|
if [ ! -f "$PATHS_FILE" ]; then
|
|
|
|
|
|
echo "❌ paths.local.json 부재 — template 복사 후 값 입력 필요" >&2
|
|
|
|
|
|
exit 3
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# JSON 파싱 (jq 있으면 활용, 없으면 grep)
|
|
|
|
|
|
read_json() {
|
|
|
|
|
|
local key="$1"
|
|
|
|
|
|
if command -v jq >/dev/null 2>&1; then
|
|
|
|
|
|
jq -r ".${key} // empty" "$PATHS_FILE" 2>/dev/null
|
|
|
|
|
|
else
|
|
|
|
|
|
grep -o "\"${key}\"[[:space:]]*:[[:space:]]*\"[^\"]*\"" "$PATHS_FILE" 2>/dev/null \
|
|
|
|
|
|
| sed 's/.*"\([^"]*\)"$/\1/'
|
|
|
|
|
|
fi
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UNITY_ROOT=$(read_json "UNITY_PROJECT_ROOT")
|
|
|
|
|
|
UNITY_REMOTE=$(read_json "UNITY_GIT_REMOTE")
|
|
|
|
|
|
|
|
|
|
|
|
if [ -z "$UNITY_ROOT" ] || [ "$UNITY_ROOT" = "__SET_PER_PC__" ]; then
|
|
|
|
|
|
echo "❌ UNITY_PROJECT_ROOT 미설정 — paths.local.json 편집 필요" >&2
|
|
|
|
|
|
exit 4
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ ! -d "$UNITY_ROOT" ]; then
|
|
|
|
|
|
echo "❌ Unity 프로젝트 경로 부재: $UNITY_ROOT" >&2
|
|
|
|
|
|
exit 5
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# 로그 디렉토리 (BT C34-17 audit 중앙 저장소 연계)
|
|
|
|
|
|
LOG_DIR="$HOME/.claude/burningtimes-audit/unity_sync"
|
|
|
|
|
|
mkdir -p "$LOG_DIR"
|
|
|
|
|
|
LOG_FILE="$LOG_DIR/$(date +%Y-%m-%d).log"
|
|
|
|
|
|
|
|
|
|
|
|
log() {
|
|
|
|
|
|
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG_FILE"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cd "$UNITY_ROOT" || { echo "❌ cd 실패: $UNITY_ROOT" >&2; exit 6; }
|
|
|
|
|
|
|
|
|
|
|
|
# git 레포 미초기화 판정
|
|
|
|
|
|
if [ ! -d ".git" ]; then
|
|
|
|
|
|
if [ "$ACTION" = "init" ]; then
|
|
|
|
|
|
log "▶️ git init — Unity 프로젝트 레포 초기화"
|
|
|
|
|
|
git init -b main 2>&1 | tee -a "$LOG_FILE"
|
|
|
|
|
|
# Unity 표준 .gitignore·.gitattributes는 스크립트 외부에서 사전 배치 (Claude Code 직접 작성)
|
|
|
|
|
|
if [ -n "$UNITY_REMOTE" ] && [ "$UNITY_REMOTE" != "__SET_PER_PC__" ]; then
|
|
|
|
|
|
git remote add origin "$UNITY_REMOTE" 2>&1 | tee -a "$LOG_FILE"
|
|
|
|
|
|
log "✅ init + remote 설정 완료 (origin: $UNITY_REMOTE)"
|
|
|
|
|
|
else
|
|
|
|
|
|
log "⚠️ UNITY_GIT_REMOTE 미설정 — Gitea 레포 생성 후 수동 add 필요"
|
|
|
|
|
|
fi
|
|
|
|
|
|
log "📌 다음 단계: git add -A && git commit && push"
|
|
|
|
|
|
exit 0
|
|
|
|
|
|
else
|
|
|
|
|
|
echo "❌ Unity 프로젝트 git 레포 아님. 'init' 먼저 수행" >&2
|
|
|
|
|
|
exit 7
|
|
|
|
|
|
fi
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
case "$ACTION" in
|
|
|
|
|
|
pull)
|
|
|
|
|
|
log "▶️ pull"
|
|
|
|
|
|
if git fetch origin 2>&1 | tee -a "$LOG_FILE" \
|
|
|
|
|
|
&& git merge --ff-only origin/main 2>&1 | tee -a "$LOG_FILE"; then
|
|
|
|
|
|
log "✅ pull 완료"
|
|
|
|
|
|
exit 0
|
|
|
|
|
|
else
|
|
|
|
|
|
log "❌ pull 실패 (충돌/네트워크/레포 미생성 가능) — 수동 개입 필요"
|
|
|
|
|
|
exit 8
|
|
|
|
|
|
fi
|
|
|
|
|
|
;;
|
|
|
|
|
|
push)
|
|
|
|
|
|
log "▶️ push — add + commit + push"
|
|
|
|
|
|
git add -A 2>&1 | tee -a "$LOG_FILE"
|
|
|
|
|
|
|
|
|
|
|
|
if git diff --cached --quiet; then
|
|
|
|
|
|
log "ℹ️ 스테이징 변경 없음"
|
|
|
|
|
|
# 선행 commit 있으면 push
|
|
|
|
|
|
if git log origin/main..HEAD --oneline 2>/dev/null | grep -q .; then
|
|
|
|
|
|
log "▶️ 로컬 선행 commit push 시도"
|
|
|
|
|
|
if git push origin main 2>&1 | tee -a "$LOG_FILE"; then
|
|
|
|
|
|
log "✅ 선행 commit push 완료"
|
|
|
|
|
|
exit 0
|
|
|
|
|
|
fi
|
|
|
|
|
|
fi
|
|
|
|
|
|
log "ℹ️ push 대상 없음 — 정상 종료"
|
|
|
|
|
|
exit 0
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# 현재 scene 추정 (Unity EditorBuildSettings 기반)
|
|
|
|
|
|
SCENE="unknown"
|
|
|
|
|
|
if [ -f "ProjectSettings/EditorBuildSettings.asset" ]; then
|
|
|
|
|
|
SCENE=$(grep -m1 "path:" "ProjectSettings/EditorBuildSettings.asset" 2>/dev/null \
|
|
|
|
|
|
| sed 's|.*path: ||;s|\.unity.*||;s|.*/||' || echo "unknown")
|
|
|
|
|
|
fi
|
|
|
|
|
|
N_FILES=$(git diff --cached --name-only | wc -l | tr -d ' ')
|
|
|
|
|
|
MSG="auto: $(date +'%Y-%m-%d %H:%M') · scene: ${SCENE:-unknown} · ${N_FILES} files"
|
|
|
|
|
|
|
|
|
|
|
|
git commit -m "$MSG" 2>&1 | tee -a "$LOG_FILE"
|
|
|
|
|
|
|
|
|
|
|
|
if git push origin main 2>&1 | tee -a "$LOG_FILE"; then
|
|
|
|
|
|
log "✅ push 완료: $MSG"
|
|
|
|
|
|
exit 0
|
|
|
|
|
|
else
|
|
|
|
|
|
log "❌ push 실패 — 로컬 commit 유지, 네트워크/원격 확인 필요"
|
|
|
|
|
|
exit 9
|
|
|
|
|
|
fi
|
|
|
|
|
|
;;
|
|
|
|
|
|
status)
|
|
|
|
|
|
log "▶️ status"
|
|
|
|
|
|
git status --short 2>&1 | tee -a "$LOG_FILE"
|
|
|
|
|
|
echo "--- 최근 3개 commit ---" | tee -a "$LOG_FILE"
|
|
|
|
|
|
git log -3 --oneline 2>&1 | tee -a "$LOG_FILE"
|
|
|
|
|
|
exit 0
|
|
|
|
|
|
;;
|
|
|
|
|
|
*)
|
|
|
|
|
|
cat <<EOF >&2
|
|
|
|
|
|
Usage: unity_auto_sync.sh {init|pull|push|status}
|
|
|
|
|
|
|
|
|
|
|
|
Actions:
|
|
|
|
|
|
init — git 레포 초기화 + remote 설정 (.gitignore/.gitattributes는 사전 배치)
|
|
|
|
|
|
pull — fetch + ff-only merge (충돌 시 중단)
|
|
|
|
|
|
push — add + commit(자동 메시지) + push
|
|
|
|
|
|
status — 작업 트리 상태 + 최근 3개 commit
|
|
|
|
|
|
|
|
|
|
|
|
Prerequisite:
|
|
|
|
|
|
paths.local.json 의 UNITY_PROJECT_ROOT · UNITY_GIT_REMOTE 설정 필수
|
|
|
|
|
|
EOF
|
|
|
|
|
|
exit 1
|
|
|
|
|
|
;;
|
|
|
|
|
|
esac
|