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.
1: @ECHO OFF
2: FOR /D %%a IN ("*") DO CALL :SvnCheck %%~dpa %%a
3: PAUSE
4: GOTO :eof
5:
6: :SvnCheck
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 ..
14:
15: :eof
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
2: FOR /D %%a IN ("*") DO IF EXIST %%~dpa%%a\.svn svn update %%~dpa%%a
This blog contains the thoughts and discoveries of Tim Barcz, a technologist with a interests in computer programming technologies.