SVN batch file to see which items in your repository have been switched to another branch/tag
Posted by jpluimers on 2014/10/29
One of the things that can make SVN work a mess is to loose track of local directories and files that have been switched (with svn switch) to other URLs in your repository.
The batch file below will help you track those down.
Run it from your repository root.
The batch files uses these things:
- svn status.
- svn info.
- svn switch.
- quoting path strings to keep them in one parameter.
- getting line by line command output using a FOR /F loop.
- parsing using substrings in batch files.
:: parse the output of `svn status` to see which files/directories have been 'switched' to a different branch
:: then get information about those switches
@echo off
echo If you do not see any output below this line, then none of your files/directories have been switched.
:: trick: set delimiter to a character disallowed in Windows filenames: \ / : * ? " < > |
:: see http://support.microsoft.com/kb/177506/en-us
:: that is also not part of the `svn status` output
:: see http://www.visualsvn.com/support/svnbook/ref/svn/c/status/
FOR /F "delims=:" %%l IN ('svn status --depth=infinity') DO call :line "%%l"
goto :eof
:line
setlocal ENABLEDELAYEDEXPANSION
set line=%1
:: substring http://stackoverflow.com/questions/636381/what-is-the-best-way-to-do-a-substring-in-a-batch-file
:: first quote is at position 1, last at position -1
set switch=%line:~5,1%
set subdirectory=%line:~9,-1%
if "%switch%"=="S" call :switched "%subdirectory%"
endlocal
goto :eof
:switched
echo subdirectory: "%subdirectory%" is switched
svn info %1
goto :eof
I also made batch files to switch my trunk to certain branches or tags and back.
Two examples:
:: run this batch file from within your repository root directory :: Note: batch files need to double the ^ and will be translated to a single ^. :: Note: URLs are case sensitive svn switch ^^/branches/Releases/1.1 trunk
Switch back (I hardly do this; my trunk is usually not a sandbox):
:: run this batch file from within your repository root directory :: Note: batch files need to double the ^ and will be translated to a single ^. :: Note: URLs are case sensitive svn switch ^^/trunk trunk
–jeroen






gabr42 said
Useful, thanks!