views:

122

answers:

1

I'm using the TFS Power Toys with PowerShell to get the history of a file. Like so:

$fileName = "$/MyDir/MyFile.cs"     
$results = @(Get-TfsItemHistory $fileName )

I get a nice result set that has many ChangesetId's. However, when I run tf diff (tf diff /version:C36826~C36680 "$/MyDir/MyFile.cs" /format:unified) for some of the ChangesetIds I get:

Item $/MyDir/MyFile.cs;C37400 was not found in source control.

However I can use the compare tool from Visual Studio to compare those two versions of the file. Am I doing something wrong? It doesn't seem to have anything to do with the age of the file, there's instances where the command line diff will show a changeset but not a changeset that happened earlier in the day. When I view those changesets with the gui tool they have many lines that have changed, the changeset isn't empty.

What's up with this thing? Should I submit a bug report? This looks like a bug to me.

Maybe this has something to do with it: the last diff that works gives me "\ No newline at end of file".

+1  A: 

I'll bet the file has been renamed. Luckily you are already using Powershell, so this is fairly straightforward to track down:

tfhistory "$/MyDir/MyFile.cs" -all | select changesetid, @{name="Path"; expression={$_.changes[0].item.serveritem}} | ft -auto

You'll then need to run diff using a slightly more verbose syntax:

tf diff "$/MyOtherDir/MyFile.old.cs;1234" "$/MyDir/MyFile.cs;5678"

[EDIT] The first command should print something like:

C:\workspaces\temp> tfhist rentest2 -all | select changesetid, @{name="Path"; expression={$_.changes[0].item.serveritem}} | ft -auto


ChangesetId Path                       
----------- ----                       
      10725 $/Test-ConchangoV2/rentest2
      10142 $/Test-ConchangoV2/rentest

As you can see, I personally have Get-TfsItemHistory aliased to 'tfhist' for even shorter typing. 'tfhistory' is what the PS console in the Power Tools uses, so that's what I put in my original instructions.

Richard Berg
Is this off the cuff script? There's all sorts of issues when I run it.
jcollum
You were right though, there was a rename that was breaking my script, thanks!
jcollum
The script was off the cuff, but it does work. I've edited the answer to show the output (which is what I expect).
Richard Berg
When i run this 1) tfhistory isn't recognized 2) -all is an unrecognized command for tf history. When I modify it to tf history " $filename | select changesetid, @{name="Path"; expression={$_.changes[0].item.serveritem}} | ft -auto" I get lots of "Select-Object : Cannot index into a null array." errors. Your script sent me in the right direction at least.
jcollum
Are you loading the aliases from the Power Tools console? Start -> MS TFS Power Tools -> PowerShell Console will do it automatically. If not, they're in TfsSnapin.ps1 in the Power Tools install directory, which you can dot-source in your $profile. Or you can use the full cmdlet name "Get-TfsItemHistory."
Richard Berg