Now, the source control component is what it is. Something designed to get companies to (for the love of everything good in the world) quit using Visual Source Safe. No less, no more. Just look at how it operates.
It isn't the most terrible thing in the whole wide world (file_new1.cs.bak.old.2 is the most terrible thing in the whole wide world), but it really hates you if you're trying to work disconnected from the TFS server. Maybe TFS 11 will bring some love in that arena.
I started with a bog-standard installation of TortoiseHg, enabled the rebase extension and added in the MakeWriteable extension. Pay attention to the version numbers that the extension is compatible with. I had to pull the latest version of MakeWriteable out of its source repository, the version compatibility chart on selenic.com was out-of-date when I started (it should be fine now), so just pay attention.
Also, you want to install the TFS Power Tools. I don't know why these don't ship with the TFS client distribution, because they make using TFS much, much better.
I decided to write scripts in PowerShell 2.0, mostly because you don't have to install anything...if you're using an up-to-date OS.
I put this script in my "C:\Users\<username>\" directory, to set up the work environment.
$Env:Project = "C:\src\TeamProject\Main\project" $Env:AnotherProject = "C:\src\TeamProject\Main\AnotherProject" $Env:FxCop = "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop" $Env:DotNetFramework = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319" $Env:NotePadPlusPlus = "C:\Program Files (x86)\Notepad++" $Env:VisualStudio = "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE" $Env:WindowsSDK = "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin" $Env:Path = $Env:Path + ";" + $Env:FxCop + ";" + $Env:DotNetFramework + ";" + $Env:NotePadPlusPlus + ";" + $Env:VisualStudio + ";" + $Env:WindowsSDK Set-Location "C:\Work"
Notice that I have a directory, "C:\Work" that is separate from "C:\src". Don't do your Mercurial controlled work within the directory scope that TFS is using locally. Visual Studio gets completely befuddled by that and tries to add new files to TFS for you. Not helpful.
I created a shortcut on my desktop that targets the following:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NoExit -file C:\Users\<username>\DevelopmentEnvironment.ps1
Despite the path saying "WindowsPowerShell\v1.0", it runs PowerShell 2.0. Also, -NoExit must preceed -file, or else PowerShell -WillExit. Whoever works on PowerShell, thanks for that.
Anyway, double-click the shortcut, and you get powershell console with your development environment properly configured.
I got latest on the TFS-controlled project directory in C:\src\<project>, then created a Mercurial repo using TortoiseHg. This takes a while if the project is of any size. Whoever works on Mercurial, thanks for that. (Equal opportunity whiner.)
I eventually ended up with the following .hgignore file for the repository:
syntax: glob obj\* *.user *.suo _ReSharper* TestResults* bin\* Bin\* *Database\sql *.schemaview *.dbmdl *.sdfWe're using Mrs. Test (MSTest), so I had to exclude *.sdf files. I don't know (in detail) what *.sdf files contain, but Mrs. Test will dutifully make them for you. You don't want them in your source repository.
You should commit the .hgignore with your initial hg commit, in the TFS controlled directory for your project. Next, clone your TFS controlled Mercurial repository to somewhere else. I chose to clone "C:\src\<project>" to "C:\Work\<project>" to get the working Mercurial repository clear of TFS & Visual Studio's watchful eye. At this point, no work will be done in "C:\src" at all. All work will be done in "C:\Work".
I created the following pull script in "C:\Work\project" based on the work Eric Hexter published.
$projectName = "Project"
$ProjectRoot = "C:\src\TeamProject\Main"
$DVCSRoot = "C:\Work"
$tfs = "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\tf.exe"
function pull {
cd $ProjectRoot\$projectName
&$tfs get . -r
hg commit -A -m "from tfs"
cd $DVCSRoot\$projectName
hg pull --rebase
}
pull
The modifications I made to Eric's pull script are mostly superficial, except I am telling TFS to "get . -r", which says get the current directory, and recursively get anything in the child directories below the current. In my experience, TFS just wants to "get" the whole Team Project unless you tell it otherwise. This may or may not be OK, depending on how you use your TFS rig.This is the push script I cobbled together in "C:\Work\project", again derived from Eric's work.
$projectName = "project" $ProjectRoot = "C:\src\TeamProject\Main" $DVCSRoot = "C:\Work" $tfpt = "C:\Program Files (x86)\Microsoft Team Foundation Server 2010 Power Tools\TFPT.EXE" $tfs = "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\tf.exe" hg push cd $ProjectRoot\$projectName &$tfpt scorch /noprompt /recursive /exclude:.hgignore`,.hg`,*.ps1 . hg update -C -y &$tfpt online /adds /deletes /recursive /exclude:.hgignore`,.hg`,_ReSharper*`,bin`,obj`,*.user`,*.suo`,*.ps1`,*.log* . &$tfs checkin cd $DVCSRoot\$projectNameThe scorch command was modified to work starting on the current directory (notice the stealth "current directory" dot on the end) and its child directories.
The online command was modified to detect deletes (it doesn't do this by default), operate on child directories, and to not try to check in a ton of different things. Notice that this command includes the stealth "current directory" dot on the end as well.
If anyone figures out how to make these scripts execute as Mercurial hooks, I'm interested. It would be nice to just use TortoiseHg and not have to drop out to the PowerShell just to pull and push.
Hope this helps someone!
