PowerShell and .svnignore

I got very tired of manually ignoring “bin”, “obj” folders and various files (e.g. _Resharper*) when using Svn.

So I looked for a better solution –  something similar to Git’s .gitignore.

Reading up on some svn documentation resulted in the below function that will look for ignore definitions (similar to .gitignore) in a given .svnignore file and apply these to all folders recursively.

$psd = Split-Path (Get-Variable MyInvocation).Value.MyCommand.Path            

function Ignore-Svn {            
    param(  [parameter(Mandatory = $true)]            
            $svnIgnoreFile = "$psd\.svnignore",            
            [switch] $recurse)            

    $fullPath = (Resolve-Path $path)            
    if($recurse) { $recFlag = "-R" }            
 svn propset svn:ignore $fullPath -F $svnIgnoreFile $recFlag            

Here is my .svnignore file:
Finally in order to add all new files that are not ignored, we can use the following function:

function Add-Svn {            
 svn st | %{ if ($_ -match "\?\s+(.*)") { svn add $matches[1] } }            

  1. #1 by Doug on September 5, 2010 - 12:45 am

    Nice functions. A Verb-Noun is preferred for the function name. This leverages the learning that goes into the base set of cmdlets. Get-Verb to see a list of verbs.

    Perhaps Set-SVNIgnore and Add-SVNFiles?

    • #2 by Thorsten Lorenz on September 5, 2010 - 1:33 pm

      I understand, that my naming is inconsistent with the built-in cmdlets, but I’d like to just type svn_ and then be able to tab through the options.
      If I name it verb first, I’d have to remember what functions I have available for each different tool.
      So for tool related scripts I’ll stick to the tool_verb convention for now.

      • #3 by Doug on September 5, 2010 - 6:52 pm

        Understood. At least use a hyphen 🙂

      • #4 by Thorsten Lorenz on September 12, 2010 - 4:29 pm

        After learning a bit more about PowerShell (http://www.computerperformance.co.uk/powershell/index.htm) and the idea of accelerating learning via consistency, I now heed your advice.
        Especially since I discovered that I can always list all svn related cmdlets via: “Get-Command -noun svn” or even shorter gcm -no svn
        I also found that using a hyphen is necessary in order for PowerTab to give me intellisense on my cmdlets.

  2. #5 by Doug on September 12, 2010 - 4:37 pm


    You can also use wildcards with Get-Command

    gcm *svn

    Plus, if they are scripts you are running from a directory you can use wildcards too


    That will cycle through your scripts,

  1. PowerShell and .svnignore » Lab49 Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: