Example #1
0
        private void InitializeBranches(IGitTfsRemote defaultRemote, List <BranchDatas> childBranchPaths)
        {
            _stdout.WriteLine("Tfs branches found:");
            var branchesToProcess = new List <BranchDatas>();

            foreach (var tfsBranchPath in childBranchPaths)
            {
                _stdout.WriteLine("- " + tfsBranchPath.TfsRepositoryPath);
                var branchDatas = new BranchDatas
                {
                    TfsRepositoryPath = tfsBranchPath.TfsRepositoryPath,
                    TfsRemote         = _globals.Repository.ReadAllTfsRemotes().FirstOrDefault(r => r.TfsRepositoryPath == tfsBranchPath.TfsRepositoryPath)
                };
                try
                {
                    branchDatas.CreationBranchData = defaultRemote.Tfs.GetRootChangesetForBranch(tfsBranchPath.TfsRepositoryPath);
                }
                catch (Exception ex)
                {
                    branchDatas.Error = ex;
                }

                branchesToProcess.Add(branchDatas);
            }
            branchesToProcess.Add(new BranchDatas {
                TfsRepositoryPath = defaultRemote.TfsRepositoryPath, TfsRemote = defaultRemote, RootChangesetId = -1
            });

            bool isSomethingDone;

            do
            {
                isSomethingDone = false;
                var branchesToFetch = branchesToProcess.Where(b => !b.IsEntirelyFetched && b.Error == null).ToList();
                foreach (var tfsBranch in branchesToFetch)
                {
                    _stdout.WriteLine("=> Working on TFS branch : " + tfsBranch.TfsRepositoryPath);
                    if (tfsBranch.TfsRemote == null)
                    {
                        try
                        {
                            IFetchResult fetchResult;
                            tfsBranch.TfsRemote = InitBranchSupportingRename(tfsBranch.TfsRepositoryPath, null, tfsBranch.CreationBranchData, defaultRemote,
                                                                             out fetchResult);
                            if (tfsBranch.TfsRemote != null)
                            {
                                tfsBranch.IsEntirelyFetched = fetchResult.IsSuccess;
                                isSomethingDone             = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            _stdout.WriteLine("error: an error occurs when initializing the branch. Branch is ignored and continuing...");
                            tfsBranch.Error = ex;
                        }
                    }
                    else
                    {
                        try
                        {
                            var lastFetchedChangesetId = tfsBranch.TfsRemote.MaxChangesetId;
                            Trace.WriteLine("Fetching remote :" + tfsBranch.TfsRemote.Id);
                            var fetchResult = FetchRemote(tfsBranch.TfsRemote, true);
                            tfsBranch.IsEntirelyFetched = fetchResult.IsSuccess;
                            if (fetchResult.NewChangesetCount != 0)
                            {
                                isSomethingDone = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            _stdout.WriteLine("error: an error occurs when fetching changeset. Fetching is stopped and continuing...");
                            tfsBranch.Error = ex;
                        }
                    }
                }
            } while (branchesToProcess.Any(b => !b.IsEntirelyFetched && b.Error == null) && isSomethingDone);

            _globals.Repository.GarbageCollect();

            if (branchesToProcess.Any(b => !b.IsEntirelyFetched))
            {
                _stdout.WriteLine("warning: Some Tfs branches could not have been initialized:");
                foreach (var branchNotInited in branchesToProcess.Where(b => !b.IsEntirelyFetched))
                {
                    _stdout.WriteLine("- " + branchNotInited.TfsRepositoryPath);
                }
                _stdout.WriteLine("\nPlease report this case to the git-tfs developers! (report here : https://github.com/git-tfs/git-tfs/issues/461 )");
            }
            if (branchesToProcess.Any(b => b.Error != null))
            {
                _stdout.WriteLine("warning: Some Tfs branches could not have been initialized or entirely fetched due to errors:");
                foreach (var branchWithErrors in branchesToProcess.Where(b => b.Error != null))
                {
                    _stdout.WriteLine("- " + branchWithErrors.TfsRepositoryPath);
                    if (_globals.DebugOutput)
                    {
                        Trace.WriteLine("   =>error:" + branchWithErrors.Error);
                    }
                    else
                    {
                        _stdout.WriteLine("   =>error:" + branchWithErrors.Error.Message);
                    }
                }
                _stdout.WriteLine("\nPlease report this case to the git-tfs developers! (report here : https://github.com/git-tfs/git-tfs/issues )");
            }
        }
Example #2
0
        private void InitializeBranches(IGitTfsRemote defaultRemote, List<BranchDatas> childBranchPaths)
        {
            _stdout.WriteLine("Tfs branches found:");
            var branchesToProcess = new List<BranchDatas>();
            foreach (var tfsBranchPath in childBranchPaths)
            {
                _stdout.WriteLine("- " + tfsBranchPath.TfsRepositoryPath);
                var branchDatas = new BranchDatas
                    {
                        TfsRepositoryPath = tfsBranchPath.TfsRepositoryPath,
                        TfsRemote = _globals.Repository.ReadAllTfsRemotes().FirstOrDefault(r => r.TfsRepositoryPath == tfsBranchPath.TfsRepositoryPath)
                    };
                try
                {
                    branchDatas.CreationBranchData = defaultRemote.Tfs.GetRootChangesetForBranch(tfsBranchPath.TfsRepositoryPath);
                }
                catch (Exception ex)
                {
                    branchDatas.Error = ex;
                }

                branchesToProcess.Add(branchDatas);
            }
            branchesToProcess.Add(new BranchDatas { TfsRepositoryPath = defaultRemote.TfsRepositoryPath, TfsRemote = defaultRemote, RootChangesetId = -1 });

            bool isSomethingDone;
            do
            {
                isSomethingDone = false;
                var branchesToFetch = branchesToProcess.Where(b => !b.IsEntirelyFetched && b.Error == null).ToList();
                foreach (var tfsBranch in branchesToFetch)
                {
                    _stdout.WriteLine("=> Working on TFS branch : " + tfsBranch.TfsRepositoryPath);
                    if (tfsBranch.TfsRemote == null || tfsBranch.TfsRemote.MaxChangesetId == 0)
                    {
                        try
                        {
                            IFetchResult fetchResult;
                            tfsBranch.TfsRemote = InitBranchSupportingRename(tfsBranch.TfsRepositoryPath, null, tfsBranch.CreationBranchData, defaultRemote,
                                                                             out fetchResult);
                            if (tfsBranch.TfsRemote != null)
                            {
                                tfsBranch.IsEntirelyFetched = fetchResult.IsSuccess;
                                isSomethingDone = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            _stdout.WriteLine("error: an error occurs when initializing the branch. Branch is ignored and continuing...");
                            tfsBranch.Error = ex;
                        }
                    }
                    else
                    {
                        try
                        {
                            var lastFetchedChangesetId = tfsBranch.TfsRemote.MaxChangesetId;
                            Trace.WriteLine("Fetching remote :" + tfsBranch.TfsRemote.Id);
                            var fetchResult = FetchRemote(tfsBranch.TfsRemote, true);
                            tfsBranch.IsEntirelyFetched = fetchResult.IsSuccess;
                            if (fetchResult.NewChangesetCount != 0)
                                isSomethingDone = true;
                        }
                        catch (Exception ex)
                        {
                            _stdout.WriteLine("error: an error occurs when fetching changeset. Fetching is stopped and continuing...");
                            tfsBranch.Error = ex;
                        }
                    }
                }
            } while (branchesToProcess.Any(b => !b.IsEntirelyFetched && b.Error == null) && isSomethingDone);

            _globals.Repository.GarbageCollect();

            if (branchesToProcess.Any(b => !b.IsEntirelyFetched))
            {
                _stdout.WriteLine("warning: Some Tfs branches could not have been initialized:");
                foreach (var branchNotInited in branchesToProcess.Where(b => !b.IsEntirelyFetched))
                {
                    _stdout.WriteLine("- " + branchNotInited.TfsRepositoryPath);
                }
                _stdout.WriteLine("\nPlease report this case to the git-tfs developers! (report here : https://github.com/git-tfs/git-tfs/issues/461 )");
            }
            if (branchesToProcess.Any(b => b.Error != null))
            {
                _stdout.WriteLine("warning: Some Tfs branches could not have been initialized or entirely fetched due to errors:");
                foreach (var branchWithErrors in branchesToProcess.Where(b => b.Error != null))
                {
                    _stdout.WriteLine("- " + branchWithErrors.TfsRepositoryPath);
                    if (_globals.DebugOutput)
                        Trace.WriteLine("   =>error:" + branchWithErrors.Error);
                    else
                        _stdout.WriteLine("   =>error:" + branchWithErrors.Error.Message);
                }
                _stdout.WriteLine("\nPlease report this case to the git-tfs developers! (report here : https://github.com/git-tfs/git-tfs/issues )");
            }
        }