Search code examples
c#visual-studio-2010visual-studiotfsshelve

Find all files that differ from shelveset?


I have a shelveset of my rather large solution where one element is working. In my workspace version, it is not - however, other elements are working in my workspace version that are not working in the shelveset. As such, it would be messy and time consuming to merge both versions.

Is there a simple way to do a compare of the shelveset with my workspace solution, returning all files that differ from one another ? I know it is possible to do it one-by-one comparison, however I am not sure where the error has arisen, and finding this would involve comparing a huge number of files, most of which are the exact same.


Solution

  • When you create a shelveset, TFS stores the hash values for files. There are two values, HashValue which is the value of the original item on the server, and UploadHashValue which is the actual value of the item in the shelveset.

    You should then be able to create a new shelveset and compare it to the old:

    var shelvesetOld = vcs.QueryShelvesets("shelveset_old", null).FirstOrDefault();
    var shelvesetOldChanges = vcs.QueryShelvedChanges(shelvesetOld)[0].PendingChanges;
    
    var shelvesetNew = vcs.QueryShelvesets("shelveset_new", null).FirstOrDefault();
    var shelvesetNewChanges = vcs.QueryShelvedChanges(shelvesetNew)[0].PendingChanges;
    
    var differences = new List<PendingChange>();
    foreach (var oldChange in shelvesetOldChanges) {
        var shelvesetNewChange = shelvesetNewChanges.FirstOrDefault(shelvesetChangeSearch => shelvesetChangeSearch.ServerItem.Equals(oldChange.ServerItem));
        if (shelvesetNewChange == null) {
            differences.Add(oldChange);
            continue;
        }
    
        if (!shelvesetNewChange.UploadHashValue.SequenceEqual(oldChange.UploadHashValue)) {
            differences.Add(oldChange);
        }
    }