TFS 2010 API: get old name / location of renamed / moved item

I am writing an application that pulls changes from TFS and exports a csv file that describes the latest changes to use in a script to paste these changes into ClearCase. However, β€œlast” does not necessarily mean the latter. If the file was added and then edited, I only need to know that the file was added and get the latest version so that my script knows how to handle it correctly. Most of this is pretty straight forward. I get to files that have been renamed or moved, since I do not want to show this item as deleted, and another item added. To maintain ClearCase integrity, I need to have in the CSV file that the item has been moved or renamed, along with the old location and the new location.

So the problem I am facing is to trace the renamed (or moved) file back to the previous name or location so that I can match it with the new location / name. Where in the API can I get this information?

+4
source share
2 answers

Here is your answer: http://social.msdn.microsoft.com/Forums/en/tfsgeneral/thread/f9c7e7b4-b05f-4d3e-b8ea-cfbd316ef737 Using QueryHistory, you can find out that the item has been renamed and then using your previous set of changes (earlier than the one that says it was renamed), you can find its previous name.

+2
source

You will need to use VersionControlServer.QueryHistory in a manner similar to the following method. Pay particular attention to SlotMode , which must be false in order for renames to be executed.

 private static void PrintNames(VersionControlServer vcs, Change change) { //The key here is to be sure Slot Mode is enabled. IEnumerable<Changeset> queryHistory = vcs.QueryHistory( new QueryHistoryParameters(change.Item.ServerItem, RecursionType.None) { IncludeChanges = true, SlotMode = false, VersionEnd = new ChangesetVersionSpec(change.Item.ChangesetId) }); string name = string.Empty; var changes = queryHistory.SelectMany(changeset => changeset.Changes); foreach (var chng in changes) { if (name != chng.Item.ServerItem) { name = chng.Item.ServerItem; Console.WriteLine(name); } } } 

EDIT: Moved another solution. What follows is when I tested a clean Rename change, but it broke when I got tired of the Rename and Edit changes.

This is probably the most efficient way to get the previous name. Although it works (TFS2013 API vs TFS2012 install), it looks like an error to me.

 private static string GetPreviousServerItem(VersionControlServer vcs, Item item) { Change[] changes = vcs.GetChangesForChangeset( item.ChangesetId, includeDownloadInfo: false, pageSize: int.MaxValue, lastItem: new ItemSpec(item.ServerItem, RecursionType.None)); string previousServerItem = changes.Single().Item.ServerItem; //Yep, this passes Trace.Assert(item.ServerItem != previousServerItem); return previousServerItem; } 

It will be used as:

 if (change.ChangeType.HasFlag(ChangeType.Rename)) { string oldServerPath = GetPreviousServerItem(vcs, change.Item); // ... } 
+1
source

Source: https://habr.com/ru/post/1392112/


All Articles