public string GetBranchParentPath(string path, int changesetId)
        {
            var itemSpec          = new[] { new tfs.ItemSpec(path, tfs.RecursionType.None) };
            var versionSpec       = new tfs.ChangesetVersionSpec(changesetId);
            var branchHistoryTree = _versionControlServer.GetBranchHistory(itemSpec, versionSpec);

            if (branchHistoryTree.Count() > 0 && branchHistoryTree[0].Count() > 0)
            {
                return(branchHistoryTree[0][0].Relative.BranchToItem.ServerItem);
            }

            return(null);
        }
        private void FetchChangesets(VersionControlServer server, string path, VersionSpec version)
        {
            var changesets = server.QueryHistory(path, version, 0, RecursionType.None, null, null, version, int.MaxValue, true, false, true, false);
            foreach (Changeset changeset in changesets)
            {
                if (changeset.Changes.Length != 1)
                {
                    throw new InvalidOperationException("Expected exactly 1 change, but got " + changeset.Changes.Length + " for ChangesetId " + changeset.ChangesetId);
                }

                this.changesets.Add(changeset);
                filenames.Add(null);
                manualResetEvents.Add(null);

                var change = changeset.Changes[0];
                if (change.ChangeType.HasFlag(ChangeType.Branch))
                {
                    var item = server.GetBranchHistory(new[] {new ItemSpec(change.Item.ServerItem, RecursionType.None)}, new ChangesetVersionSpec(changeset.ChangesetId))[0][0].GetRequestedItem().Relative.BranchFromItem;
                    if (item != null)
                    {
                        FetchChangesets(server, item.ServerItem, new ChangesetVersionSpec(item.ChangesetId));
                    }
                }
            }
        }