Skip to content

Instantly share code, notes, and snippets.

@Foadsf
Created November 13, 2024 12:16
Show Gist options
  • Save Foadsf/09022c3a51e30e9651269207cd6ade60 to your computer and use it in GitHub Desktop.
Save Foadsf/09022c3a51e30e9651269207cd6ade60 to your computer and use it in GitHub Desktop.
A cmd batch script that helps SVN track files moved outside of version control by temporarily moving them back to their original location and then using 'svn move' to relocate them properly.
@echo off
setlocal enabledelayedexpansion
:: Check if the SVN directory path is provided
if "%1"=="" (
echo Please provide the path to the SVN repository.
echo Usage: %~nx0 path\to\svn\repository
exit /b 1
)
:: Initialize variables
set repo_path=%1
pushd "%repo_path%"
:: Get and display list of missing files from SVN status
echo Filename Old Path New Path
echo ======== ========= =========
for /f "tokens=2 delims= " %%f in ('svn status "%repo_path%" ^| findstr "^! "') do (
set "found=0"
set "new_path=DELETED"
for /f "delims=" %%p in ('dir /s /b "%%~nxf" 2^>nul') do (
if not "%%p"=="!repo_path!\%%f" (
set "found=1"
set "new_path=%%p"
set "new_path=!new_path:%CD%\=!"
echo Moving !new_path! back to %%f temporarily...
:: Create the directory for the old location if it doesn't exist
mkdir "%%~dpf" 2>nul
:: Move file back to original location
move "!new_path!" "%%f"
echo Executing SVN move...
:: Use SVN to move the file to its new location
svn move "%%f" "!new_path!" --parents
)
)
echo %%~nxf %%f !new_path!
)
popd
endlocal
@Foadsf
Copy link
Author

Foadsf commented Nov 13, 2024

More info here on SO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment