Scripts for automating commits and updates with Subversion

Version control is good, but there are two possible pitfalls for me:
  1. In the morning, it can happen that I start working without updating my project. If this is a project I worked on, on  another computer the day before, as soon as I want to commit the new changes, I will have to merge all the changes in one file. Not a big issue, but unnessary work.
  2. Before I leave the office, I unfortunately often forget to commit.
 
I wrote a commit batch file that runs every two hours,  but the problem was that I manually had to define in which directories the batch file should look and, if there was nothing to commit, I still had to click the commit window away (if you have about 30 open projects, that isn’t much fun).
I decided to improve my batch file: It should automatically generate a list of all the root directories of projects under version control and then check if there is something to commit. If there is nothing to commit, the batch file should just continue without showing me the commit window.
 
One hour of surfing and my rudimentary powershell knowledge resulted in two small scripts that check for projects should be committed and should be updated. In order to run these scripts, you need a Windows computer and the command line utilities for Subversion (they are usually installed if you use TortoiseSVN). I think that a script like this can also be written in other scripting languages and for other operating systems.
If you want to run it on your computer, you will have to adjust the abolute paths in the scripts to your settings.
 
 
The commit script (svncommit.ps1):
 
 
Remarks:
  • Line 1: Changing to the root directory of my data drive with all my projects
  • Line 2: Here we look for .svn folders (subversion puts them in the root directory of a project. Powershell looks in all folders if there is a subfolder with this name (it continues if it encounters system directories) and saves the path of these directories in the file svn.txt.
  • Line 5-14: In the for loop, I loop through every project root directory, check the subversion status, write the result once again to a file (status.txt) and check  if it is not empty: if it is not empty, it does a commit.
  • I save the files svn.txt and status.txt in a directory that is not under version control, so it is not around when I check for changes in the project directory.
  • This script runs every two hours on my computers.
 
The update script (svnupdate.ps1) is also short and simple
 
 
 
It hast the same first two lines as the commit script. With the subversion update option /closeonend:2, only projects that are not up-to-date will be updated.
 

3 thoughts on “Scripts for automating commits and updates with Subversion

  1. Hi Chris
    It shows the commit window, that lists all the files that are unversioned, changed, etc. You can decide what to do (for example, delete or add).
    Hope this helps
    CHeers
    Renger

Comments are closed.