Update: Jeffrey Snover shows how to significantly tighten up my scripts. I love having the pros reading my blog. :)
I have a few very simple scripts that I use to drive TortoiseSVN from my PowerShell command line. I like Tortoise's GUI, but my mouse aversion means I want to use the command line to show pieces of it.
You'll notice they all have one thing in common: using the registry to find the executable path they want. This is what I love about PowerShell: these types of things weren't easily doable from cmd.exe.
Enjoy!
tdiff.ps1 (used to diff arbitrary files with TortoiseMerge):
if ($args.Length -lt 2) {
write-host "usage: tdiff <file1> <file2>"
return
}
if ((test-path "HKLM:\Software\TortoiseSVN") -eq $false) {
write-host -foregroundColor Red "Error: Could not find TortoiseMerge.exe"
return
}
$tortoiseKey = get-itemproperty "HKLM:\Software\TortoiseSVN"
if ($tortoiseKey -eq $null) {
write-host -foregroundColor Red "Error: Could not find TortoiseMerge.exe"
return
}
$tortoise = $tortoiseKey.TMergePath
if ($tortoise -eq $null) {
write-host -foregroundColor Red "Error: Could not find TortoiseMerge.exe"
return
}
$commandLine = '/base:"' + $args[0] + '" /mine:"' + $args[1] + '"'
& $tortoise $commandLine
tmerge.ps1 (used to merge arbitrary files with TortoiseMerge):
if ($args.Length -lt 3) {
write-host "usage: tmerge <base> <theirs> <mine>"
return
}
if ((test-path "HKLM:\Software\TortoiseSVN") -eq $false) {
write-host -foregroundColor Red "Error: Could not find TortoiseMerge.exe"
return
}
$tortoiseKey = get-itemproperty "HKLM:\Software\TortoiseSVN"
if ($tortoiseKey -eq $null) {
write-host -foregroundColor Red "Error: Could not find TortoiseMerge.exe"
return
}
$tortoise = $tortoiseKey.TMergePath
if ($tortoise -eq $null) {
write-host -foregroundColor Red "Error: Could not find TortoiseMerge.exe"
return
}
$commandLine = '/base:"' + $args[0] + '" /theirs:"' + $args[1] + '" /mine:"' + $args[2] + '"'
& $tortoise $commandLine
tsvn.ps1 (can run argument-less commands; i.e., "tsvn commit" launches the commit GUI from the current directory):
if ($args.Length -lt 1) {
write-host "usage: tsvn <command>"
return
}
if ((test-path "HKLM:\Software\TortoiseSVN") -eq $false) {
write-host -foregroundColor Red "Error: Could not find TortoiseProc.exe"
return
}
$tortoiseKey = get-itemproperty "HKLM:\Software\TortoiseSVN"
if ($tortoiseKey -eq $null) {
write-host -foregroundColor Red "Error: Could not find TortoiseProc.exe"
return
}
$tortoise = $tortoiseKey.ProcPath
if ($tortoise -eq $null) {
write-host -foregroundColor Red "Error: Could not find TortoiseProc.exe"
return
}
$commandLine = '/command:' + $args[0] + ' /notempfile /path:"' + ((get-location).Path) + '"'
& $tortoise $commandLine