CoolFace
Apppublic

KOOHAWN/AI_PDF_TOOLKIt

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes
git-sync.ps1125 linesDownload Raw Back to root
1# Set encoding to UTF-8 to prevent Korean characters from breaking2$OutputEncoding = [System.Text.Encoding]::UTF83[Console]::OutputEncoding = [System.Text.Encoding]::UTF84 5Write-Host "===================================================" -ForegroundColor Cyan6Write-Host "   smart-pdf-ai-merger Git 수동 동기화 도구" -ForegroundColor Cyan7Write-Host "===================================================" -ForegroundColor Cyan8Write-Host " 원격 저장소(GitHub)와 로컬 파일의 소스 코드를"9Write-Host " 안전하게 양방향 백업 및 최신화합니다."10Write-Host "==================================================="11Write-Host ""12 13# 1. Git 실행 파일 경로 자동 검색 (Windows)14$gitPath = "git"15if (Test-Path "C:\Program Files\Git\cmd\git.exe") {16    $gitPath = "C:\Program Files\Git\cmd\git.exe"17} elseif (Test-Path "C:\Program Files (x86)\Git\cmd\git.exe") {18    $gitPath = "C:\Program Files (x86)\Git\cmd\git.exe"19} elseif (Test-Path "$env:USERPROFILE\AppData\Local\Programs\Git\cmd\git.exe") {20    $gitPath = "$env:USERPROFILE\AppData\Local\Programs\Git\cmd\git.exe"21}22 23# Git 존재 확인24try {25    & $gitPath --version > $null26} catch {27    Write-Host "❌ [오류] PC에서 Git 설치 경로를 찾을 수 없습니다." -ForegroundColor Red28    Write-Host "Git이 설치되어 있는지 확인해 주세요." -ForegroundColor Yellow29    exit 130}31 32$gitDir = Join-Path $PSScriptRoot ".git"33$warningFilePath = Join-Path $PSScriptRoot "깃_충돌_경고_우선확인.txt"34 35# 충돌 발생 여부 확인 함수36function Has-Conflicts {37    (Test-Path (Join-Path $gitDir "MERGE_HEAD")) -or `38    (Test-Path (Join-Path $gitDir "rebase-merge")) -or `39    (Test-Path (Join-Path $gitDir "rebase-apply"))40}41 42# 충돌 상태 체크43if (Has-Conflicts) {44    Write-Host "⚠️ [경고] 현재 저장소에 해결되지 않은 깃 충돌(Conflict)이 존재합니다." -ForegroundColor Yellow45    Write-Host "임시 경고 파일이 프로젝트 루트 폴더에 생성되었습니다. 확인 후 충돌을 해결해 주세요." -ForegroundColor Yellow46    [console]::beep(1000, 500)47    exit 148}49 50# 경고 파일이 존재한다면 삭제51if (Test-Path $warningFilePath) {52    Remove-Item $warningFilePath -Force53}54 55# 현재 활성화된 브랜치명 추출56$branch = (& $gitPath rev-parse --abbrev-ref HEAD).Trim()57Write-Host "👉 현재 사용 중인 깃 브랜치: [$branch]" -ForegroundColor Green58 59# 1. 로컬 수정 사항 감지 및 반영60$status = (& $gitPath status --porcelain).Trim()61$hasLocalChanges = $status.Length -gt 062 63if ($hasLocalChanges) {64    Write-Host "📝 감지된 파일 변경 내역:" -ForegroundColor Yellow65    Write-Host $status66    Write-Host "📦 변경 사항 백업 커밋 작성 중..." -ForegroundColor Cyan67    68    & $gitPath add -A69    $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"70    & $gitPath commit -m "수동 업데이트: $timestamp"71    Write-Host "✅ 로컬 커밋 완료!" -ForegroundColor Green72} else {73    Write-Host "✨ 수정된 로컬 파일이 없습니다. (커밋 생략)" -ForegroundColor Gray74}75 76# 2. 원격 최신 갱신 (Pull with Rebase)77Write-Host "📥 원격 저장소(GitHub)로부터 최신 코드 가져오는 중 (git pull --rebase)..." -ForegroundColor Cyan78try {79    & $gitPath pull --rebase origin $branch80    Write-Host "✅ 원격 저장소 동기화 완료!" -ForegroundColor Green81} catch {82    if (Has-Conflicts) {83        Write-Host "❌ [에러] 최신 코드를 당겨오는 중 충돌이 발생했습니다!" -ForegroundColor Red84        Write-Host "이전 히스토리를 보존하기 위해 리베이스 작업을 안전하게 취소하고 경고 메시지를 띄웁니다." -ForegroundColor Yellow85        86        try {87            & $gitPath rebase --abort88            Write-Host "ℹ️ 리베이스 작업을 안전하게 취소(Abort) 처리했습니다." -ForegroundColor Gray89        } catch {90            Write-Host "❌ 리베이스 취소 실패" -ForegroundColor Red91        }92 93        $warningMsg = "[깃 동기화 충돌 안내]`n" +94                      "원격 저장소의 최신 코드를 가져오던 중 충돌(Conflict)이 발생했습니다.`n" +95                      "서로 다른 PC에서 같은 파일의 같은 위치를 동시에 수정했을 때 주로 발생합니다.`n`n" +96                      "해결 방법:`n" +97                      "1. VS Code 등의 편집기에서 깃허브 변경 사항과 로컬 코드를 대조 및 해결합니다.`n" +98                      "2. 해결 후 터미널에 아래 명령어를 실행하여 수동으로 깃허브에 밀어 넣어주세요:`n" +99                      "   git add .`n" +100                      "   git commit -m `"충돌 해결 수동 커밋`"`n" +101                      "   git pull --rebase origin $branch`n" +102                      "   git push origin $branch`n`n" +103                      "수동 정리가 완료되면 이 안내 파일은 다음 동기화 시 자동으로 지워집니다."104                      105        Set-Content -Path $warningFilePath -Value $warningMsg -Encoding utf8106        [console]::beep(1000, 500)107        exit 1108    } else {109        Write-Host "❌ [오류] 원격 소스를 가져오는데 실패했습니다: $_" -ForegroundColor Red110        exit 1111    }112}113 114# 3. 깃허브 원격 업로드 (Push)115Write-Host "📤 원격 저장소(GitHub)로 업로드 중 (git push)..." -ForegroundColor Cyan116try {117    & $gitPath push origin $branch118    Write-Host "🎉 [성공] 모든 소스 코드가 깃허브와 완벽하게 양방향 연동되었습니다!" -ForegroundColor Green119} catch {120    Write-Host "❌ [오류] 원격 업로드(Push) 실패: $_" -ForegroundColor Red121    Write-Host "인터넷 연결을 확인하거나 권한을 체크해 주세요." -ForegroundColor Yellow122    exit 1123}124 125