Run() public method

Shows help for git-tfs as a whole (i.e. a list of commands).
public Run ( ) : int
return int
Ejemplo n.º 1
0
 public int Run(string commitish)
 {
     if (VerifyAllRemotes)
     {
         _helper.Run(this);
         return(GitTfsExitCodes.Help);
     }
     return(RunFromCommitish(commitish));
 }
Ejemplo n.º 2
0
        public int Run()
        {
            if (CloneAllBranches && NoFetch)
            {
                throw new GitTfsException("error: --nofetch cannot be used with --all");
            }

            if (!CloneAllBranches)
            {
                _helper.Run(this);
                return(GitTfsExitCodes.Help);
            }

            var defaultRemote = InitFromDefaultRemote();

            var allRemotes = _globals.Repository.ReadAllTfsRemotes();

            var rootBranch = defaultRemote.Tfs.GetRootTfsBranchForRemotePath(defaultRemote.TfsRepositoryPath);

            if (rootBranch == null)
            {
                throw new GitTfsException(string.Format("error: Init all the branches is only possible when 'git tfs clone' was done from the trunk!!! '{0}' is not a TFS branch!", defaultRemote.TfsRepositoryPath));
            }
            if (defaultRemote.TfsRepositoryPath.ToLower() != rootBranch.Path.ToLower())
            {
                throw new GitTfsException(string.Format("error: Init all the branches is only possible when 'git tfs clone' was done from the trunk!!! Please clone again from '{0}'...", rootBranch.Path));
            }

            var childBranchPaths = rootBranch.GetAllChildren().Select(b => b.Path).ToList();

            if (childBranchPaths.Any())
            {
                _stdout.WriteLine("Tfs branches found:");
                foreach (var tfsBranchPath in childBranchPaths)
                {
                    _stdout.WriteLine("- " + tfsBranchPath);
                }

                foreach (var tfsBranchPath in childBranchPaths)
                {
                    var result = CreateBranch(defaultRemote, tfsBranchPath, allRemotes);
                    if (result < 0)
                    {
                        return(result);
                    }
                }
            }
            else
            {
                _stdout.WriteLine("No other Tfs branches found.");
            }
            return(GitTfsExitCodes.OK);
        }
Ejemplo n.º 3
0
        public int Run(string tfsBranchPath, string gitBranchNameExpected)
        {
            if (!CloneAllBranches && tfsBranchPath == null)
            {
                _helper.Run(this);
                return(GitTfsExitCodes.Help);
            }

            if (CloneAllBranches)
            {
                return(CloneAll(tfsBranchPath));
            }
            else
            {
                return(CloneBranch(tfsBranchPath, gitBranchNameExpected));
            }
        }
Ejemplo n.º 4
0
        public int Run()
        {
            //[Temporary] Remove in the next version!
            if (!DontDisplayObsoleteMessage)
            {
                _stdout.WriteLine("WARNING: This command is obsolete and will be removed in the next version. Use 'branch --init' instead!");
            }

            if (CloneAllBranches && NoFetch)
            {
                throw new GitTfsException("error: --nofetch cannot be used with --all");
            }

            if (!CloneAllBranches)
            {
                _helper.Run(this);
                return(GitTfsExitCodes.Help);
            }

            var defaultRemote = InitFromDefaultRemote();

            var rootBranch = defaultRemote.Tfs.GetRootTfsBranchForRemotePath(defaultRemote.TfsRepositoryPath);

            if (rootBranch == null)
            {
                throw new GitTfsException(string.Format("error: Init all the branches is only possible when 'git tfs clone' was done from the trunk!!! '{0}' is not a TFS branch!", defaultRemote.TfsRepositoryPath));
            }
            if (defaultRemote.TfsRepositoryPath.ToLower() != rootBranch.Path.ToLower())
            {
                throw new GitTfsException(string.Format("error: Init all the branches is only possible when 'git tfs clone' was done from the trunk!!! Please clone again from '{0}'...", rootBranch.Path));
            }

            var childBranchPaths = rootBranch.GetAllChildren().Select(b => new BranchDatas {
                TfsRepositoryPath = b.Path
            }).ToList();

            if (childBranchPaths.Any())
            {
                _stdout.WriteLine("Tfs branches found:");
                foreach (var tfsBranchPath in childBranchPaths)
                {
                    _stdout.WriteLine("- " + tfsBranchPath.TfsRepositoryPath);
                    tfsBranchPath.RootChangesetId = defaultRemote.Tfs.GetRootChangesetForBranch(tfsBranchPath.TfsRepositoryPath);
                }
                childBranchPaths.Add(new BranchDatas {
                    TfsRepositoryPath = defaultRemote.TfsRepositoryPath, TfsRemote = defaultRemote, RootChangesetId = -1
                });

                bool isSomethingDone;
                do
                {
                    isSomethingDone = false;
                    var branchesToFetch = childBranchPaths.Where(b => !b.IsEntirelyFetched).ToList();
                    foreach (var tfsBranch in branchesToFetch)
                    {
                        Trace.WriteLine("=> Working on TFS branch : " + tfsBranch.TfsRepositoryPath);
                        if (tfsBranch.TfsRemote == null)
                        {
                            var sha1RootCommit = _globals.Repository.FindCommitHashByChangesetId(tfsBranch.RootChangesetId);
                            if (sha1RootCommit != null)
                            {
                                tfsBranch.TfsRemote = CreateBranch(defaultRemote, tfsBranch.TfsRepositoryPath, sha1RootCommit);
                                isSomethingDone     = true;
                            }
                        }
                        if (tfsBranch.TfsRemote != null)
                        {
                            var lastFetchedChangesetId = tfsBranch.TfsRemote.MaxChangesetId;
                            Trace.WriteLine("Fetching remote :" + tfsBranch.TfsRemote.Id);
                            var fetchResult = FetchRemote(tfsBranch.TfsRemote, true);
                            tfsBranch.IsEntirelyFetched = fetchResult.IsSuccess;
                            if (lastFetchedChangesetId != fetchResult.LastFetchedChangesetId)
                            {
                                isSomethingDone = true;
                            }
                        }
                    }
                } while (childBranchPaths.Any(b => !b.IsEntirelyFetched) && isSomethingDone);

                if (childBranchPaths.Any(b => !b.IsEntirelyFetched))
                {
                    _stdout.WriteLine("warning: Some Tfs branches could not have been initialized:");
                    foreach (var branchNotInited in childBranchPaths.Where(b => !b.IsEntirelyFetched))
                    {
                        _stdout.WriteLine("- " + branchNotInited.TfsRepositoryPath);
                    }
                    _stdout.WriteLine("\nPlease report this case to the git-tfs developpers! (report here : https://github.com/git-tfs/git-tfs/issues/461 )");
                }
            }
            else
            {
                _stdout.WriteLine("No other Tfs branches found.");
            }
            return(GitTfsExitCodes.OK);
        }