Monday, October 3, 2011

Comparing TFS source branch with destination branch

When a TFS branch is not "enhanced" with visualisations, it can be tricky to determine the version of the source branch.

I recently wanted to find all the changes that had been made in a branch, including some tweaks that had been made when the branch action was initially checked in. The most reliable way to do this is to compare the source branch at the revision that the branch was made with the latest code in the branch. To do this, I wanted to use the following command line:

tf folderdiff "$/SourceBranch;RevisionThatBranchWasTakenFrom" $/DestinationBranch

However, I needed a way to determine RevisionThatBranchWasTakenFrom. Since branching in TFS is essentially copying (the metadata of) each file in the source branch to the destination, there is no single concept of the 'revision' of the source branch at the point when the branch was made (in contrast to Subversion). The best I could come up with was to find the most recent changeset in the source branch before the branch was made. To do this, I used the tf merges command on the destination branch, which lists all the files that have been merged into the destination branch. I have made several assumptions, including that there was a single branch into the destination and no subsequent merges:

tf merges $/SourceBranch /r /showall /format:detailed | % {$_ -match '(\d+) ->' | out-null; $Matches[1]} | sort -Descending | select -first 1

This PowerShell one-liner will return the highest revision number of all the branched files, assuming that nothing untoward happens and it can parse the output of tf merges. In our case, I knew that all the changesets in question had four digits, so the string based sort would work fine.

Now that I had the most recent changeset, I could run the command to get the changes:
tf folderdiff "$/SourceBranch;C12345" $/DestinationBranch

0 comments:

Post a Comment