views:

341

answers:

2

I used to use a different source control tool and it allowed me to get a "diff report": all the changes made to a file between version X and version Y (including lines added/removed between each version, which could be many versions) in one text file. It was pretty handy for situations where you are pretty sure that some code used to be in your file but now it's not (handy for when your BA says to add something and you're thinking "didn't I take that out?!").

The advantage here is that you get one text file that has all the changes to a codebase that you can then search. This is equivalent to doing a compare on every version (10 to 9, 9 to 8 etc) and then saving the results of every compare to a text file.

I don't see any easy way to do this in TFS. Is there a plugin/powertool that does this? The google gave me nothing.

+2  A: 

I'm not aware of any out-of-the-box solution. However, it isn't hard to make one yourself if you have TFS Power Toys and PowerShell. Try this in PowerShell:

Add-PSSnapin Microsoft.TeamFoundation.PowerShell

Get-TfsItemHistory foo.cs | foreach {
  tf diff "foo.cs;C$($_.ChangesetId)" `
          "foo.cs;C$($_.ChangesetId - 1)" `
          /format:unified
}
Pavel Minaev
Well, it's a nice idea. However: "Add-PSSnapin : No Windows PowerShell Snap-ins are available for version 1."So apparently I need PS 2.0. Which doesn't seem to be available for my system.
jcollum
Pavel Minaev
Also, if you are running 64-bit Windows, keep in mind that TFS PowerShell snap-in is 32-bit only, so you need to run 32-bit PowerShell to use it (you should have a separate icon created by PS installer for 32-bit shell).
Pavel Minaev
Ah that did it, I had to modify the install of TFS Power Toys to get it to hook to PowerShell. Now I'm on to a different error, I'll let you know if I can't solve it.
jcollum
Closer: "The term 'tf' is not recognized as a cmdlet, function, operable program, or script file." -- this happens in the loop so I get many many of those on my screen.
jcollum
Are these different from the PsTFS that are on codeplex?
jcollum
Yes, this is different. Anyway, `tf` doesn't come from there - it's not a PowerShell cmdlet, but `tf.exe`, so it's probably simply not in your PATH. It should be in the same folder where `devenv.exe` is - something like `C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE`.
Pavel Minaev
+1  A: 

Pavel got me going in the right direction, but the script I ended up with was a lot more complex. And still might not be correct. I had to account for filename changes.

$snapin = get-pssnapin  | select-string "Microsoft.TeamFoundation.PowerShell"

if ($snapin -eq $null) { 
Write-Host "loading snap in..."  
     Add-PSSnapin Microsoft.TeamFoundation.PowerShell 
  }

$fileName = $args[0]  Write-Host "// File name " $fileName 
$results = @(Get-TfsItemHistory $fileName )  | select changesetid, @{name="Path"; expression={$_.changes[0].item.serveritem}}

$i = 0

$cmdArray = @() 

do {   
   if ( $results[$i+1] -ne "" ) {   
   $cmdArray +=  "tf diff ""{0};{1}"" ""{2};{3}""  /format:unified" -f $results[$i].Path, $results[$i].ChangeSetId, $results[$i+1].Path, $results[$i+1].ChangeSetId   
   } ; 
    $i++ 
} until ($i -ge ($results.length - 1))

foreach ($cmd in $cmdArray) {   
   #Write-Host "// " $cmd   
   iex $cmd  }
jcollum