Uhh… is this thing on (still)?

Apparently blog posts don’t write themselves. Hmm. Whatever. Here’s a PowerShell script that will update all projects that are under source control in a directory (the directory is set inside the script):

# Directory of projects under source control
$projectsDir = 'C:\Dev\Third Party'

function Progress([string]$projectName, [system.action]$update)
{
    $activity = "Updating projects in " + $projectsDir + "..."
    $status = "Updating " + $projectName
    write-progress -activity $activity -status $status
    $update.Invoke()
}

# VCS update directory-command dictionary
$commands = new-object 'system.collections.generic.dictionary[string,system.action]'
$commands.Add(".svn", { svn update })
$commands.Add(".git", { git pull })
$commands.Add(".hg", { hg pull })

# Main
clear
cd $projectsDir
$dirs = ls | Where { $_.psIsContainer -eq $true }
foreach ($dir in $dirs)
{
    cd $dir
    $subdirs = ls -force
    
    foreach ($subdir in $subdirs)
    {
        if ($commands.ContainsKey($subdir.Name))
        {
            Progress $dir $commands[$subdir.Name]
        }
    }

    cd ..
}

You can add more $commands for your favorite VCS, if you wish. Note that this will only update one level of subdirectories (to stay compatible with Subversion… I think.)

Advertisements
Leave a comment

2 Comments

  1. Wow cool script, too bad I already knew it because I’m the one who wrote it and this is simply a comment by myself on my own blog which only I read. The only thing more frustrating is the nigh-complete lack of customizability of this WordPress theme! Craptastic!

    Reply
  2. Jack Mehoff

     /  March 8, 2010

    Sam, if you don’t know how this is, you have forgotten a classic Chris Farley quote, and I apparently haven’t been using it lately. Will use it at some point soon. I read your blog and have no idea what it means. Did you realize using and suing are anagrams?

    Reply

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: