Exemplo n.º 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;
            }));
        }
Exemplo n.º 2
0
        public int Run(string tfsUrl)
        {
            _tfsHelper.Url      = tfsUrl;
            _tfsHelper.Username = _remoteOptions.Username;
            _tfsHelper.Password = _remoteOptions.Password;
            _tfsHelper.EnsureAuthenticated();

            if (!_tfsHelper.CanGetBranchInformation)
            {
                throw new GitTfsException("error: this version of TFS doesn't support this functionality");
            }

            string convertBranchMessage = "  -> Open 'Source Control Explorer' and for each folder corresponding to a branch, right click on the folder and select 'Branching and Merging' > 'Convert to branch'.";
            var    branches             = _tfsHelper.GetBranches().Where(b => b.IsRoot).ToList();

            if (branches.IsEmpty())
            {
                Trace.TraceWarning("No TFS branches were found!");
                Trace.TraceWarning("\n\nPerhaps you should convert your branch folders into a branch in TFS:");
                Trace.TraceWarning(convertBranchMessage);
            }
            else
            {
                Trace.TraceInformation("TFS branches that could be cloned:");
                foreach (var branchObject in branches.Where(b => b.IsRoot))
                {
                    Branch.WriteRemoteTfsBranchStructure(_tfsHelper, branchObject.Path);
                }
                Trace.TraceInformation("\nCloning root branches (marked by [*]) is recommended!");
                Trace.TraceInformation("\n\nPS:if your branch is not listed here, perhaps you should convert its containing folder into a branch in TFS:");
                Trace.TraceInformation(convertBranchMessage);
            }
            return(GitTfsExitCodes.OK);
        }
Exemplo n.º 3
0
        public int Run(string tfsUrl)
        {
            if (!tfsHelper.CanGetBranchInformation)
            {
                throw new GitTfsException("error: this version of TFS doesn't support this functionnality");
            }

            tfsHelper.Url      = tfsUrl;
            tfsHelper.Username = remoteOptions.Username;
            tfsHelper.Password = remoteOptions.Password;
            tfsHelper.EnsureAuthenticated();
            var branches = tfsHelper.GetBranches().Where(b => b.IsRoot).ToList();

            if (branches.IsEmpty())
            {
                stdout.WriteLine("No TFS branches were found!");
            }
            else
            {
                stdout.WriteLine("TFS branches that could be cloned:");
                foreach (var branchObject in branches.Where(b => b.IsRoot))
                {
                    Branch.WriteRemoteTfsBranchStructure(tfsHelper, stdout, branchObject.Path);
                }
                stdout.WriteLine("\nCloning root branches (marked by [*]) is recommended!");
                stdout.WriteLine("\n\nPS:if your branch is not listed here, perhaps you should convert the containing folder to a branch in TFS.");
            }
            return(GitTfsExitCodes.OK);
        }