The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,779 other followers

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:

:: 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

One Response to “SVN batch file to see which items in your repository have been switched to another branch/tag”

  1. gabr42 said

    Useful, thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: