コード例 #1
0
        public void VisitProject_ShouldReturn_Success()
        {
            var instance = new ListAllBranchesVisitor();
            var code     = instance.VisitProject(Lib2Directory, Lib2Config);

            Assert.AreEqual(ReturnCode.Success, code, "Invalid Return Code");
        }
コード例 #2
0
        public void VisitDependency_ShouldReturn_Success_WhenListAllBranches_Succeeds()
        {
            const string WORKING_DIR = @"C:\test\dir";

            var fileSystem = Container.Resolve <IFileSystem>();
            var git        = Container.Resolve <IGit>();

            fileSystem.Arrange(f => f.Path.GetFullPath(Arg.AnyString))
            .Returns(WORKING_DIR);

            git.Arrange(g => g.ListAllBranches())
            .Returns(ReturnCode.Success)
            .MustBeCalled();

            var instance = new ListAllBranchesVisitor();
            var code     = instance.VisitDependency(Lib2Directory, Lib1Dependency);

            git.Assert();
            Assert.AreEqual(ReturnCode.Success, code, "Invalid Return Code");
            Assert.AreEqual(WORKING_DIR, git.WorkingDirectory, "Invalid working directory");
        }
コード例 #3
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <returns>The return code.</returns>
        public ReturnCode Execute()
        {
            bool[] flags =
            {
                _options.Delete,
                _options.ListMerged
            };

            // only one mutually exclusive flag can be set.
            if (flags.Count(b => b) > 1)
            {
                return(ReturnCode.InvalidArguments);
            }

            // force delete can only be specified if delete is specified.
            if (!_options.Delete && _options.ForceDelete)
            {
                return(ReturnCode.InvalidArguments);
            }

            // if delete is specified the branch name must also be specified.
            if (_options.Delete && string.IsNullOrEmpty(_options.BranchName))
            {
                return(ReturnCode.InvalidArguments);
            }

            if (_options.ListMerged && !string.IsNullOrEmpty(_options.BranchName))
            {
                return(ReturnCode.InvalidArguments);
            }

            IVisitor          visitor;
            string            successMessage;
            Func <ReturnCode> postTraverse = null;

            if (_options.Delete)
            {
                visitor        = new DeleteBranchVisitor(_options.BranchName, _options.ForceDelete);
                successMessage = $"Successfully deleted the {_options.BranchName} branch from all repositories.";
            }
            else if (_options.ListMerged)
            {
                visitor        = new ListMergedBranchesVisitor();
                successMessage = string.Empty;
                postTraverse   = () =>
                {
                    _git.WorkingDirectory = _options.Directory;
                    return(_git.ListMergedBranches());
                };
            }
            else if (!string.IsNullOrEmpty(_options.BranchName))
            {
                visitor        = new CreateBranchVisitor(_options.BranchName);
                successMessage = $"Successfully created the {_options.BranchName} branch in all repositories.";
            }
            else
            {
                visitor        = new ListAllBranchesVisitor();
                successMessage = string.Empty;
                postTraverse   = () =>
                {
                    _git.WorkingDirectory = _options.Directory;
                    return(_git.ListAllBranches());
                };
            }

            _algorithm.TraverseDependencies(visitor, _options.Directory);

            var code = visitor.ReturnCode;

            if (code == ReturnCode.Success && postTraverse != null)
            {
                var origColor = _console.ForegroundColor;
                _console.ForegroundColor = ConsoleColor.Green;
                _console.WriteLine("project:");
                _console.WriteLine($"    dir: {_options.Directory}");
                _console.WriteLine();
                _console.ForegroundColor = origColor;

                code = postTraverse();
            }

            if (code == ReturnCode.Success)
            {
                _console.WriteLine(successMessage);
            }


            return(visitor.ReturnCode);
        }