Question

Given: TFS server with m > n changesets in team project X.

I am using TFS API and would like to get the n latest changesets of that branch.

I think I should be using VersionControlServer.QueryHistory, but I don't understand how I can specify that I want all commits from main (default) branch of project X, but none from any other branch or from another team project in the collection.

Was it helpful?

Solution

If you only want changes in $/Project/Some/Path, then that should be the first argument to QueryHistory. For example:

QueryHistory("$/Project/Some/Path", RecursionType.Full, 5);

Will show the most recent 5 changesets that affected $/Project/Some/Path.

OTHER TIPS

This worked for me - I had to use the QueryHistoryParameters overload and set SortAscending = false in order to get the latest changeset id and not the first changesetid.

var p = new QueryHistoryParameters(item.ServerItem, RecursionType.Full) {SortAscending = false};
var q = versionControl.QueryHistory(p);
var lastCs = q.FirstOrDefault();

if (lastCs != null)
    item.LastChangesetId = lastCs.ChangesetId;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top