示例#1
0
        public static BranchTree GetRootTfsBranchForRemotePath(this ITfsHelper tfs, string remoteTfsPath, bool searchExactPath = true)
        {
            var branches    = tfs.GetBranches();
            var branchTrees = branches.Aggregate(new Dictionary <string, BranchTree>(StringComparer.OrdinalIgnoreCase), (dict, branch) => dict.Tap(d => d.Add(branch.Path, new BranchTree(branch))));

            foreach (var branch in branchTrees.Values)
            {
                if (!branch.IsRoot)
                {
                    //in some strange cases there might be a branch which is not marked as IsRoot
                    //but the parent for this branch is missing.
                    if (branchTrees.ContainsKey(branch.ParentPath))
                    {
                        branchTrees[branch.ParentPath].ChildBranches.Add(branch);
                    }
                }
            }
            var roots = branchTrees.Values.Where(b => b.IsRoot);

            return(roots.FirstOrDefault(b =>
            {
                var visitor = new BranchTreeContainsPathVisitor(remoteTfsPath, searchExactPath);
                b.AcceptVisitor(visitor);
                return visitor.Found;
            }));
        }
        public void ExactMatch_WithTrailingSlash_IsNotFound()
        {
            var visitor = new BranchTreeContainsPathVisitor(@"$/Scratch/Source/Main/", true);

            branch.AcceptVisitor(visitor);

            Assert.False(visitor.Found);
        }
        public void InexactMatch_WithoutTrailingSlash_IsFound()
        {
            var visitor = new BranchTreeContainsPathVisitor(@"$/Scratch/Source/Main", false);

            branch.AcceptVisitor(visitor);

            Assert.True(visitor.Found);
        }