El Blanco's Office 2007 Blog

Tuesday, March 11, 2008

TFS Source Control Comparisons and Whitespace

Not a usual post about SharePoint or Office, but something that I hope may help some people who find the same issue I did with TFS. I found a problem today with Team Foundation Server (TFS) when trying to compare some changes I had made against the latest version held within source control – by default it appears as if TFS uses diffmerge.exe and passes the /ignorespace option which means that changes that consist solely of whitespace are ignored and the files are deemed to be identical.

Consider the following example where you have a source file in TFS containing the following line of code:

String example = "this is an example string";

You then check out the file and edited the file to add extra whitespace at the start of the string as shown below:

String example = " this is an example string";

Within TFS, if you do a comparison of the file, TFS tells you that the file is identical to the latest version that is checked in on the TFS server. Clearly this is not the case, and it due to the fact that by default TFS passes the /ignorespace option to the diffmerge.exe tool it uses to compare files.

To solve this issue follow the steps below to specify a custom tool to use for comparing files (note, we're still going to use the standard diffmerge.exe tool, but we're not going to specify the /ignorespace option):

  1. Within VS.NET 2005 select the "Tools -> Options" menu item.
  2. Expand the "Source Control" node and select "Visual Studio Team Foundation Server".
  3. Click the "Configure User Tools…" button then click the "Add" button to add a new tool.
  4. Configure the settings for the tool to be the following:
    1. Extension: set this to be ".*" i.e. dot star.
    2. Operation: ensure this is set to "Compare".
    3. Command: set this to be "C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\diffmerge.exe" which is the default path to the diffmerge.exe tool.
    4. Arguments: leave this as standard i.e. leave this as "%1 %2".
  5. Click OK all the way back up the dialog hierarchy to save the settings.

If you now compare the file that we previously modified and added the whitespace to, TFS will correctly show that the files differ on the modified line of code.


Post a Comment

<< Home