diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..f2cc609 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.bat text eol=crlf +*.ps1 text eol=crlf diff --git a/docs/development-log.md b/docs/development-log.md index af5c40a..2130e01 100644 --- a/docs/development-log.md +++ b/docs/development-log.md @@ -1428,3 +1428,9 @@ This is the append-only implementation and handoff record shared by Codex and Cl in the way are stashed, never deleted; `master` is moved to the same commit. - Verification: run three times against a throwaway clone (files in the way, already up to date, uncommitted change). Not run against the main folder, which is the owner's to run. +- Correction, same day: the first version failed when the owner ran it. Its Korean text was read + by `cmd` as commands, and the files it stashed were still in the folder afterwards, so the + merge was refused. Why the stash left them there was not found; it did not happen in a copy. + The logic now lives in `tools/sync-main-folder.ps1` (UTF-8 with a byte order mark), moves the + files in the way into `.git/sync-backup/` itself, and the batch file is plain ASCII. Run four + ways against a throwaway clone, including a Korean file name, from a code page 949 console. diff --git a/tools/sync-main-folder.bat b/tools/sync-main-folder.bat index 46f5e99..0f9ae0c 100644 --- a/tools/sync-main-folder.bat +++ b/tools/sync-main-folder.bat @@ -3,101 +3,14 @@ rem Brings the main folder up to the branch the work is done on (TASK-062). rem rem sync-main-folder.bat [branch] [folder] rem -rem It only ever moves forward (fast-forward). It never discards a change: if files in the main -rem folder are in the way, they are put in a stash, and the stash is named on screen. -chcp 65001 >nul -setlocal EnableExtensions - -set "BRANCH=claude/app-features-purpose-c45235" -set "MAIN=D:\Android\UBGitea" -if not "%~1"=="" set "BRANCH=%~1" -if not "%~2"=="" set "MAIN=%~2" -set "STASHED=" - -echo. -echo 메인 폴더 동기화 -echo 폴더 : %MAIN% -echo 가져올 작업 : %BRANCH% -echo. - -where git >nul 2>nul -if errorlevel 1 ( - echo [중단] git 을 찾을 수 없습니다. Git 이 설치되어 있는지 확인해 주세요. - goto :fail -) -if not exist "%MAIN%\.git" ( - echo [중단] %MAIN% 은 Git 저장소가 아닙니다. - goto :fail -) -git -C "%MAIN%" rev-parse --verify --quiet "%BRANCH%" >nul -if errorlevel 1 ( - echo [중단] %BRANCH% 브랜치가 없습니다. - goto :fail -) - -rem A change to a tracked file is someone's work in progress. It is not touched. -git -C "%MAIN%" diff --quiet -if errorlevel 1 goto :dirty -git -C "%MAIN%" diff --cached --quiet -if errorlevel 1 goto :dirty - -echo [1/3] 최신 작업으로 이동합니다. -git -C "%MAIN%" merge --ff-only "%BRANCH%" >nul 2>nul -if not errorlevel 1 goto :merged - -rem The usual reason: a file that the branch now tracks already lies in the folder, untracked. -echo 폴더에 있던 파일이 길을 막고 있어 임시 보관한 뒤 다시 시도합니다. -set "STASHED=main-folder-before-sync-%DATE%-%TIME%" -git -C "%MAIN%" stash push -u -m "%STASHED%" >nul -if errorlevel 1 ( - echo [중단] 임시 보관에 실패했습니다. - set "STASHED=" - goto :fail -) -git -C "%MAIN%" merge --ff-only "%BRANCH%" -if errorlevel 1 ( - echo. - echo [중단] 앞으로만 이동하는 방식으로는 합칠 수 없습니다. - echo 메인 폴더에 이 작업에 없는 커밋이 있는 경우입니다. 아무것도 바뀌지 않았습니다. - goto :fail -) - -:merged -echo [2/3] master 를 같은 위치로 맞춥니다. -for /f "delims=" %%b in ('git -C "%MAIN%" branch --show-current') do set "CURRENT=%%b" -if /i "%CURRENT%"=="master" ( - echo 지금 master 에 있으므로 이미 맞춰졌습니다. -) else ( - git -C "%MAIN%" branch -f master "%BRANCH%" >nul 2>nul - if errorlevel 1 echo [주의] master 를 옮기지 못했습니다. 다른 폴더에서 master 를 열어 둔 경우입니다. -) - -echo [3/3] 결과 -git -C "%MAIN%" log --oneline -3 -echo. -if defined STASHED ( - echo 임시 보관한 파일이 있습니다: "%STASHED%" - echo 최신 버전이 이미 들어 있으므로 보통은 꺼낼 필요가 없습니다. - echo 목록 보기: git -C "%MAIN%" stash list - echo. -) -echo 완료되었습니다. -echo. +rem The work is done by sync-main-folder.ps1, next to this file. This file has no text other than +rem plain ASCII on purpose: cmd reads a batch file in the system's code page, and Korean text in +rem it was read as commands. +setlocal +set "ARGS=" +if not "%~1"=="" set ARGS=-Branch "%~1" +if not "%~2"=="" set ARGS=%ARGS% -Main "%~2" +powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0sync-main-folder.ps1" %ARGS% +set "RESULT=%ERRORLEVEL%" pause -exit /b 0 - -:dirty -echo [중단] 메인 폴더에 저장하지 않은 수정이 있습니다. 아무것도 바꾸지 않았습니다. -echo 아래 파일을 커밋하거나 되돌린 뒤 다시 실행해 주세요. -echo. -git -C "%MAIN%" status --short - -:fail -echo. -if defined STASHED ( - echo 임시 보관한 파일이 있습니다: "%STASHED%" - echo 되돌리기: git -C "%MAIN%" stash pop - echo. -) -pause -exit /b 1 +exit /b %RESULT% diff --git a/tools/sync-main-folder.ps1 b/tools/sync-main-folder.ps1 new file mode 100644 index 0000000..1563765 --- /dev/null +++ b/tools/sync-main-folder.ps1 @@ -0,0 +1,123 @@ +# Brings the main folder up to the branch the work is done on (TASK-062). +# Run it through sync-main-folder.bat. +# +# It only ever moves forward (fast-forward), and it never deletes: a file that is in the way is +# moved into .git\sync-backup\