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
So the first time I check out your blog I see a freaking coding blog... lovely
is this what I can expect?
TortoiseSVN is good. Frustrating to learn on your own but good.
I guess we use this here at Focus. We use it for our login scripts but mainly for source control.
Shaun, I believe Focus is actually using SvnBridge I pointed them towards a while back. Unless something has changed, I believe they're using Team Foundation Server as the actual Source Control repository, but using TortoiseSVN to put a pretty front end on it (and also to avoid IT guys like you being forced to use Visual Studio just to check files in).
Scripts like the one above, and svn scripting in general, could be helpful to you. I don't know what (if any) you'll have to do with svn, but it is highly script-friendly if you find yourself going down that path.
Oh I have no idea what the developers use. I just know on our local computers we use this to check in and out our script files just for IT. It's not company wide what we do.
So yeah maybe they are using something else who knows. I don't care LOL