Using PowerShell to Automate TortoiseSVN Updates

Using PowerShell to Automate TortoiseSVN Updates

If you find yourself working with a code base using SVN for source control (bla..), then you may as well spend a few minutes automating the periodic updates you’ll need to get from trunk.

Let’s do this with TortoiseSVN and PowerShell.  If you haven’t set up a PowerShell profile, that’s will be the first step.  Details on how to do that can be found on this TechNet article, or follow these steps:

Open a Windows Powershell prompt by pressing the Windows key, type Powershell in the search box, then right-click the Windows Powershell icon and choose ‘Run as administrator’.  At the Windows PowerShell prompt, check if your PowerShell profile exists:

Test-path $profile

If it doesn’t exist, the result from the above command will be False.  To create a profile, execute this command:

New-item –type file –force $profile

Now that the PowerShell profile is created, you’ll see the following directory was created: C:\Users\{your user name}\Documents\WindowsPowerShell.  To edit the profile, you can either open it up in your text editor of choice or have PowerShell do that for you:

Notepad $profile

Next is to create a function in the PowerShell profile that will be used to update the your SVN repo from trunk:

function fn_update_trunk {tortoiseproc /command:update /path:"C:\Work\ProjectX\trunk"}

What the above line is doing is creating a function that uses the TortiseSVN Automation Commands to update your local repository.  In this example, the SVN update command is being performed on the pre-existing repository I have at C:\Work\ProjectX\trunk.

Save the PowerShell profile file and you’re almost ready.  The next step is to create an shortcut that can be clicked to run the automated process.  I have this shortcut on my desktop.  In order to create that, from the Windows desktop right-click and choose New -> Shortcut.  A window will appear prompting you for the location of the shortcut.  Place the following text in the location box:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -command fn_update_trunk

This needs to be the location of the PowerShell executable on your computer.  For ease of use, this is adding a parameter to bypass the PowerShell execution policy.  Finally, a command is added to run the function that was created in the profile to update the SVN repository.

Click the Next button and you’ll be prompted to name the shortcut.  Once the shortcut is created, click on it and it’ll open a PowerShell prompt which will then open TortiseSVN and automatically update your SVN trunk.

Tags: , Filled Under: Programming Posted on: June 18, 2015

Leave a Reply

Your email address will not be published. Required fields are marked *