TortoiseSVN + Command Line
TortoiseSVN is a well loved shell integration tool, and if you’re into both the Windows and the Subversion, chances are excellent that you’re already using it. But did you know this brilliant GUI has a dark side? What else would I love about Tortoise but its command line support! I finally dug in and made some powershell friendly wrappers around the commands I cared about.
If you’re often hanging around the command line, as I do, it’s such a drag to open an explorer window, just so you can right click on a file to bring up the visual diff. (If you can read complex diffs without the need for a gui, you’re a better dev than I) How lovely to simply type
tdiff myFile.txt
and have the visual diff launch. Or the visual log viewer, or the interactive commit dialog. I find they go hand in hand with the already brilliant svn command set.
You can also get fancy. How about bringing up the diff and/or conflict dialog for every modified or conflicted file. Perfect for code review situations
svn status | select-string "^[MC]" | %{ tdiff $_.Line.SubString(7) }
As you’re about to see, I’m not doing much besides wrapping what’s already there. The key points are the /notempfile (if you don’t, path might be deleted according to the docs), and that the path must be a full path. Enjoy the idea or the code, which ever you take away
$TortoiseProc = 'C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe'
function myExpandPath($path, $prefix="path")
{
if ($path -match "^((https?)|(svn(\+ssh)?)|(file))\:\/\/") {
#path has been fully specified (e.g. http://server/foo or file:///C:/foo)
return "/$prefix" + ":""$path"""
} else {
#path is a local name
return "/$prefix" + ":""" + (Get-Item $path).FullName + '"'
}
}
function RepoBrowser-TortoiseSvn ($path=".")
{
&$TortoiseProc "/command:repobrowser" (myExpandPath $path) "/notempfile"
}
function Commit-TortoiseSvn ($path=".")
{
&$TortoiseProc "/command:commit" (myExpandPath $path) "/notempfile"
}
function ConflictEditor-TortoiseSvn ($path=".")
{
&$TortoiseProc "/command:conflicteditor" (myExpandPath $path) "/notempfile"
}
function Diff-TortoiseSvn ($path=".", $path2)
{
if ($path2 -ne $null) {
$path2 = myExpandPath $path2 -prefix 'path2'
}
&$TortoiseProc "/command:diff" (myExpandPath $path) $path2 "/notempfile"
}
function SmartDiff-TortoiseSvn ($path=".", $path2)
{
#If a file in conflict, use ConflictEditor, otherwise use Diff
if (($path2 -eq $null) -and
(!(get-item $path).PsIsContainer) -and
((svn status $path)[0] -eq 'C')) {
return ConflictEditor-TortoiseSvn $path
}
return Diff-TortoiseSvn -path:$path -path2:$path2
}
function Status-TortoiseSvn ($path=".")
{
&$TortoiseProc "/command:repostatus" (myExpandPath $path) "/notempfile"
}
function Log-TortoiseSvn ($path=".")
{
&$TortoiseProc "/command:log" (myExpandPath $path) "/notempfile" $strictSwitch
}
Set-Alias tstatus Status-TortoiseSvn
Set-Alias tdiff SmartDiff-TortoiseSvn
Set-Alias tbrowse RepoBrowser-TortoiseSvn
Set-Alias tcommit Commit-TortoiseSvn
Set-Alias tlog Log-TortoiseSvn