Friend and fellow blogger Chris Sutton wrote a post the other day about updating source code with batch file. I found it quite helpful given the number of open source projects I follow (or attempt to) and the different repositories we have at work. A simple click and all projects registered in the batch file were updated. The only problem is that any time I download a new project, I'm going to have to crack open the file and add in another project.
Chris' solution reduces friction, I'm wanting to provide a solution that reduces it further:
This new solution will traverse a directory and find all directories that contains the ".svn" directory which indicates the directory is under source control. If the directory is under source control then the batch file issues an update command to bring the source up to date.
File System Structure
The Batch File Source
1: @ECHO OFF
2: FOR /D %%a IN ("*") DO CALL :SvnCheck %%~dpa %%a
4: GOTO :eof
7: set sourcedir=%1%2
8: set dir=%2
9: set svndir=%sourcedir%\.svn
10: echo "%sourcedir%"
11: CD %dir%
12: IF EXIST %svndir% svn up
13: CD ..
Without getting into all of the details of the batch file syntax, the basics of what is going on here is that there is a for loop, looping through each directory. If the directory has the ".svn" directory then the "svn up" command is issued.
Happy updating (now with less friction)
After reading some of the comments, particularly some by "Chris", I've went back and made this simpler. Thank you Chris
1: @ECHO OFF
2: FOR /D %%a IN ("*") DO IF EXIST %%~dpa%%a\.svn svn update %%~dpa%%a
That's it, small, concise, and for all practical purposes down to one line.
10-08-2008 10:20 PM