Ejemplo n.º 1
0
        private IEnumerable <ITfsBranch> GetChildBranchesForSpecificSubBranch()
        {
            var mergeRelationships = _vcs.QueryMergeRelationships(ServerPath);

            return(mergeRelationships
                   .Where(mr => !mr.IsDeleted && !String.IsNullOrWhiteSpace(mr.Item))
                   .Select(mr => new TfsBranch(_vcs, mr.Item, true)));
        }
Ejemplo n.º 2
0
        private TrackMergeInfo GetTrackMergeInfo(VersionControlServer versionControl,
            IEnumerable<ExtendedMerge> allTrackMerges,
            string sourcePath)
        {
            var result = new TrackMergeInfo
            {
                FromOriginalToSourceBranches = new List<string>(),
            };
            var trackMerges = allTrackMerges.Where(m => m.TargetItem.Item == sourcePath).ToArray();
            if (!trackMerges.IsNullOrEmpty())
            {
                var changesetIds = trackMerges.Select(t => t.SourceChangeset.ChangesetId).ToArray();
                var mergeSourceBranches = _changesetService.GetAssociatedBranches(changesetIds)
                    .Select(b => b.Item)
                    .Distinct()
                    .ToArray();

                if (mergeSourceBranches.Length == 1)
                {
                    result.FromOriginalToSourceBranches.Add(mergeSourceBranches[0]);

                    var sourceFolder = trackMerges.First().SourceItem.Item.ServerItem;
                    var comment = trackMerges.First().SourceChangeset.Comment;
                    if (trackMerges.Length > 1)
                    {
                        foreach (var merge in trackMerges.Skip(1))
                            sourceFolder = FindShareFolder(sourceFolder, merge.SourceItem.Item.ServerItem);
                        comment = "source changeset has several comments";
                    }

                    var sourceMergesRelationships = versionControl.QueryMergeRelationships(sourceFolder)
                    .Where(r => !r.IsDeleted)
                    .ToArray();

                    var sourceTrackMerges = versionControl.TrackMerges(changesetIds,
                        new ItemIdentifier(sourceFolder),
                        sourceMergesRelationships,
                        null);

                    var sourceTrackMergeInfo = GetTrackMergeInfo(versionControl, sourceTrackMerges, sourceFolder);

                    if (!sourceTrackMergeInfo.FromOriginalToSourceBranches.IsNullOrEmpty())
                    {
                        result.FromOriginalToSourceBranches.AddRange(sourceTrackMergeInfo.FromOriginalToSourceBranches);
                        result.OriginalComment = sourceTrackMergeInfo.OriginalComment;
                        result.OriginaBranch = sourceTrackMergeInfo.OriginaBranch;
                    }
                    else
                    {
                        result.OriginalComment = comment;
                        result.OriginaBranch = mergeSourceBranches[0];
                    }
                }
                else
                {
                    result.FromOriginalToSourceBranches.Add("multi");
                    result.OriginaBranch = "multi";
                    result.OriginalComment = "source changeset has several comments";
                }
            }

            return result;
        }
Ejemplo n.º 3
0
        private static List<MergeRelation> GetMergeRelationships(List<PendingChange> pendingChanges, string[] targetBranches, VersionControlServer versionControl)
        {
            var mergeRelationships = new List<MergeRelation>();

            foreach (var pendingChange in pendingChanges)
            {
                if (pendingChange.IsAdd || pendingChange.IsBranch)
                {
                    var parentFolder = ExtractFolder(pendingChange.ChangeType, pendingChange.ServerItem, pendingChange.ItemType);
                    var parentFolderRelationships = versionControl.QueryMergeRelationships(parentFolder);
                    if (parentFolderRelationships != null)
                    {
                        foreach (var parentFolderRelationship in parentFolderRelationships.Where(r => !r.IsDeleted))
                        {
                            mergeRelationships.Add(new MergeRelation
                            {
                                Item = pendingChange.ServerItem,
                                Source = parentFolder,
                                Target = parentFolderRelationship.Item,
                                TargetItemType = ItemType.Folder,
                                GetLatesPath = parentFolderRelationship.Item,
                                Recursively = pendingChange.ItemType == ItemType.Folder
                            });
                        }
                    }
                }
                else if (pendingChange.IsRename)
                {
                    var shareFolder = FindShareFolder(pendingChange.ServerItem, pendingChange.SourceServerItem);
                    var shareFolderRelationships = versionControl.QueryMergeRelationships(shareFolder);
                    var sourceRelationships = versionControl.QueryMergeRelationships(pendingChange.SourceServerItem) ?? new ItemIdentifier[0];
                    if (shareFolderRelationships != null)
                    {
                        foreach (var shareFolderRelationship in shareFolderRelationships.Where(r => !r.IsDeleted))
                        {
                            var targetBranch =
                                targetBranches.FirstOrDefault(branch => shareFolderRelationship.Item.Contains(branch));
                            if (targetBranch != null)
                            {
                                var sourceRelationship = sourceRelationships
                                    .FirstOrDefault(r => r.Item.Contains(targetBranch));
                                mergeRelationships.Add(new MergeRelation
                                {
                                    Item = pendingChange.ServerItem,
                                    Source = shareFolder,
                                    Target = shareFolderRelationship.Item,
                                    TargetItemType = ItemType.Folder,
                                    GetLatesPath = sourceRelationship != null ? sourceRelationship.Item : null,
                                    Recursively = true
                                });
                            }
                        }
                    }
                }
                else
                {
                    var changeRelationShips = versionControl.QueryMergeRelationships(pendingChange.ServerItem);
                    if (changeRelationShips != null)
                    {
                        foreach (var changeRelationShip in changeRelationShips.Where(r => !r.IsDeleted))
                        {
                            mergeRelationships.Add(new MergeRelation
                            {
                                Item = pendingChange.ServerItem,
                                Source = pendingChange.ServerItem,
                                Target = changeRelationShip.Item,
                                TargetItemType = pendingChange.ItemType,
                                GetLatesPath = changeRelationShip.Item
                            });
                        }
                    }
                }
            }
            return mergeRelationships;
        }
Ejemplo n.º 4
0
 private static List<ItemIdentifier> GetMergesRelationships(string sourceTopFolder, VersionControlServer versionControl)
 {
     return versionControl.QueryMergeRelationships(sourceTopFolder)
         .Where(r => !r.IsDeleted)
         .ToList();
 }