Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Frictionless Subversion Updates

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:

New Solution

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

image

The Batch File Source

   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)

Update

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
   3: PAUSE
That's it, small, concise, and for all practical purposes down to one line.

Posted 10-08-2008 10:20 PM by Tim Barcz

[Advertisement]

Comments

chris wrote re: Frictionless Subversion Updates
on 10-09-2008 12:54 AM

Just a couple of things you might want to consider:

(1) I think you don't need the "CD %dir%" thing. Just doing a "svn up %dir%" should work (well, it works for me).

(2) If you keep the "CD %dir%" make sure you put the %dir% in quotes, otherwise it won't work when %dir% contains spaces. Same for the %svndir% in IF EXISTS

(3) At the top of the file put a "setlocal" and at the end a "endlocal", otherwise your "local variables" will be present in the environment of the "cmd.exe" where you started the batch file.

Alexey wrote re: Frictionless Subversion Updates
on 10-09-2008 1:12 AM

There are a bit friction but obvious way: select checkout folders by ctrl+click and choose Svn update from Tortoise context menu. It lags for a several seconds but gives you understanding what has been updated.

Tim Barcz wrote re: Frictionless Subversion Updates
on 10-09-2008 9:28 AM

@Chris,

Thank you for your comments, I've updated the batch file to a new version taking into account some of the suggestions you made.

Thanks

Bill wrote re: Frictionless Subversion Updates
on 10-09-2008 9:44 AM

I do something very similar except that I am using pushd and popd and I have the batch file in my path. This way I can call it from any directory at the command line.

Tim Barcz wrote re: Frictionless Subversion Updates
on 10-09-2008 9:47 AM

@Bill

Can you publish here?  I'd be interested in seeing that.

World’s simplest source code updater « If only I were . . . wrote World’s simplest source code updater « If only I were . . .
on 10-09-2008 9:49 AM

Pingback from  World’s simplest source code updater « If only I were . . .

devlicio.us wrote re: Frictionless Subversion Updates
on 04-08-2011 1:21 PM

Frictionless subversion updates.. I like it :)

devlicio.us wrote re: Frictionless Subversion Updates
on 04-22-2011 10:33 AM

Frictionless subversion updates.. Awful :)

devlicio.us wrote re: Frictionless Subversion Updates
on 05-02-2011 10:59 PM

Frictionless subversion updates.. Huh, really? :)

devlicio.us wrote re: Frictionless Subversion Updates
on 06-02-2011 9:23 PM

Frictionless subversion updates.. Great idea :)

devlicio.us wrote re: Frictionless Subversion Updates
on 06-03-2011 1:55 AM

Frictionless subversion updates.. Keen :)

devlicio.us wrote re: Frictionless Subversion Updates
on 06-04-2011 9:43 PM

Frictionless subversion updates.. He-he-he :)

devlicio.us wrote re: Frictionless Subversion Updates
on 06-05-2011 2:13 AM

Frictionless subversion updates.. Amazing :)

wh8d xxx 0qbi wrote re: Frictionless Subversion Updates
on 07-02-2011 3:27 AM

Frictionless subversion updates.. Huh, really? :)

pwx3 porn l9kc wrote re: Frictionless Subversion Updates
on 07-02-2011 8:01 AM

Frictionless subversion updates.. OMG! :)

buy stendra wrote re: Frictionless Subversion Updates
on 02-15-2013 4:49 PM

3fGgLt Awesome blog.Thanks Again. Fantastic.

bookmaring service wrote re: Frictionless Subversion Updates
on 03-14-2013 5:05 PM

CIkxJi Really informative article.Much thanks again. Cool.

buy social bookmarks wrote re: Frictionless Subversion Updates
on 03-24-2013 2:57 PM

2ygL9n Great, thanks for sharing this article.Much thanks again. Really Great.

best news of them all wrote re: Frictionless Subversion Updates
on 08-04-2013 2:57 PM

YXPO5K Im thankful for the article.Much thanks again. Much obliged.

link building team wrote re: Frictionless Subversion Updates
on 10-01-2013 5:44 AM

bJtxm5 A round of applause for your blog.Thanks Again. Fantastic.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)