@echo off chcp 65001 >nul setlocal EnableDelayedExpansion REM ============================================================ REM 새 프로젝트 초기화 스크립트 REM REM 현재 폴더에 git 초기화 + 템플릿 파일 복사 + 커밋 규칙 적용 REM Gitea 저장소가 있으면 remote까지 연결 REM REM 사용법: newproject [gitea저장소URL] REM 예시: newproject http://dabit.synology.me:3052/islee/my_project REM newproject (URL 없이 로컬 초기화만) REM ============================================================ set TEMPLATE_DIR=%~dp0template set CURRENT_DIR=%CD% set FOLDER_NAME=%~n0 REM --- 현재 폴더명 추출 --- for %%a in ("%CURRENT_DIR%") do set FOLDER_NAME=%%~na echo. echo ============================================================ echo 새 프로젝트 초기화 echo ============================================================ echo 폴더: %CURRENT_DIR% echo 이름: %FOLDER_NAME% echo ============================================================ REM --- 이미 git 저장소인지 확인 --- git rev-parse --git-dir >nul 2>&1 if %errorlevel%==0 ( echo. echo [알림] 이미 git 저장소입니다. 템플릿 파일만 추가합니다. goto :copy_templates ) REM --- git 초기화 --- echo. echo [1/4] git 저장소 초기화... git init echo 완료. :copy_templates REM --- 템플릿 파일 복사 --- echo [2/4] 템플릿 파일 복사... if not exist "%TEMPLATE_DIR%" ( echo [오류] 템플릿 폴더를 찾을 수 없습니다: %TEMPLATE_DIR% exit /b 1 ) REM .gitignore (기존 파일이 있으면 건너뛰기) if not exist ".gitignore" ( copy "%TEMPLATE_DIR%\.gitignore" ".gitignore" >nul echo .gitignore 복사됨 ) else ( echo .gitignore 이미 존재 - 건너뜀 ) REM .gitattributes if not exist ".gitattributes" ( copy "%TEMPLATE_DIR%\.gitattributes" ".gitattributes" >nul echo .gitattributes 복사됨 ) else ( echo .gitattributes 이미 존재 - 건너뜀 ) REM .gitmessage if not exist ".gitmessage" ( copy "%TEMPLATE_DIR%\.gitmessage" ".gitmessage" >nul echo .gitmessage 복사됨 ) else ( echo .gitmessage 이미 존재 - 건너뜀 ) REM --- 커밋 메시지 템플릿 적용 (로컬 git 설정) --- echo [3/4] 커밋 규칙 적용... git config --local commit.template .gitmessage echo 커밋 메시지 템플릿 적용됨 REM --- Gitea 원격 저장소 연결 --- echo [4/4] 원격 저장소 설정... set GITEA_URL=%~1 if "%GITEA_URL%"=="" ( echo 원격 저장소 URL이 없습니다. 나중에 아래 명령으로 추가하세요: echo git remote add origin http://dabit.synology.me:3052/islee/%FOLDER_NAME% goto :done ) REM .git 접미사 추가 echo %GITEA_URL% | findstr /r "\.git$" >nul if %errorlevel% neq 0 set GITEA_URL=%GITEA_URL%.git REM 기존 remote 확인 git remote get-url origin >nul 2>&1 if %errorlevel%==0 ( echo origin이 이미 설정되어 있습니다. git remote get-url origin ) else ( git remote add origin %GITEA_URL% echo 원격 저장소 연결됨: %GITEA_URL% ) :done echo. echo ============================================================ echo 초기화 완료! echo ============================================================ echo. echo 적용된 항목: echo .gitignore - Python/빌드/IDE 파일 제외 echo .gitattributes - 줄바꿈 자동 관리 (LF/CRLF) echo .gitmessage - 커밋 메시지 규칙 (feat/fix/docs...) echo. echo 다음 단계: echo 1. 파일 추가: git add -A echo 2. 첫 커밋: git commit -m "chore: 프로젝트 초기 설정" echo 3. 푸시: git push -u origin master echo. endlocal