public void GetMetaInfoTest()
        {
            // Prepare
            var     mock    = new Mock <ICommandRunner>();
            Options options = new Options()
            {
                SubpathToTrunk  = "subpath",
                IncludeMetaData = true,
                NoBranches      = false,
                NoTags          = false,
                RootIsTrunk     = false,
                Exclude         = new List <string>()
                {
                    "ex1",
                    "ex2"
                },
                Tags = new List <string>()
                {
                    "tag1",
                    "tag2"
                },
                Branches = new List <string>()
                {
                    "branch1",
                    "branch2"
                }
            };

            var standardOutput = "*branch1";

            mock.Setup(f => f.Run("git", "branch -l --no-color", out standardOutput))
            .Returns(0);

            standardOutput = "svn/tags/branch2";
            mock.Setup(f => f.Run("git", "branch -r --no-color", out standardOutput))
            .Returns(0);

            IGrabber grabber = CreateGrabber(options, mock.Object);

            // Act
            grabber.FetchBranches();
            var actual = grabber.GetMetaInfo();

            // Assert
            Assert.Equal(new List <string>()
            {
                "svn/tags/branch2"
            }, actual.Tags);
            Assert.Equal(new List <string>()
            {
                "branch1"
            }, actual.LocalBranches);
            Assert.Equal(new List <string>()
            {
                "svn/tags/branch2"
            }, actual.RemoteBranches);
        }
Exemple #2
0
        public void Run(IGrabber grabber, IFixer fixer)
        {
            if (grabber == null)
            {
                throw new ArgumentNullException("grabber");
            }

            if (fixer == null)
            {
                throw new ArgumentNullException("fixer");
            }

            try
            {
                PreRunPrepare();

                if (Options.Rebase)
                {
                    grabber.FetchBranches();
                }
                else if (!string.IsNullOrWhiteSpace(Options.RebaseBranch))
                {
                    grabber.FetchRebaseBraches();
                }
                else
                {
                    grabber.Clone();
                }

                fixer.FixBranches();
                fixer.FixTags();
                fixer.FixTrunk();
                fixer.OptimizeRepos();
            }
            finally
            {
                PostRunCleanup();
            }
        }
        public void FetchBranchesOneRemoteBranchTest()
        {
            // Prepare
            var mock           = new Mock <ICommandRunner>();
            var standardOutput = "origin/master";

            mock.Setup(f => f.Run("git", "branch -r --no-color", out standardOutput))
            .Returns(0);
            IGrabber grabber = CreateGrabber(new Options(), mock.Object);

            List <string> expected = new List <string>(new string[] {
                "origin/master"
            });

            // Act
            grabber.FetchBranches();

            var actual = grabber.GetMetaInfo().RemoteBranches;

            // Assert
            Assert.Equal(expected, actual);
        }
        public void FetchBranchesHasOneTagTest()
        {
            // Prepare
            var mock           = new Mock <ICommandRunner>();
            var standardOutput = $"origin/master{Environment.NewLine}origin/dev{Environment.NewLine}svn/tags/v1.0.0";

            mock.Setup(f => f.Run("git", "branch -r --no-color", out standardOutput))
            .Returns(0);
            IGrabber grabber = CreateGrabber(new Options(), mock.Object);

            List <string> expected = new List <string>(new string[] {
                "svn/tags/v1.0.0"
            });

            // Act
            grabber.FetchBranches();

            var actual = grabber.GetMetaInfo().Tags;

            // Assert
            Assert.Equal(expected, actual);
        }
        public void FetchBranchesMultipleLocalBranchesTest()
        {
            // Prepare
            var mock           = new Mock <ICommandRunner>();
            var standardOutput = $"*master{Environment.NewLine}dev{Environment.NewLine}test";

            mock.Setup(f => f.Run("git", "branch -l --no-color", out standardOutput))
            .Returns(0);
            IGrabber grabber = CreateGrabber(new Options(), mock.Object);

            List <string> expected = new List <string>(new string[] {
                "master",
                "dev",
                "test"
            });

            // Act
            grabber.FetchBranches();

            var actual = grabber.GetMetaInfo().LocalBranches;

            // Assert
            Assert.Equal(expected, actual);
        }
        public void Run(
            IGrabber grabber,
            IFixer fixer,
            IStaleSvnBranchDeleter svnBranchDeleter,
            IGitPusher gitPusher,
            ILockBreaker lockBreaker
            )
        {
            if (grabber == null)
            {
                throw new ArgumentNullException(nameof(grabber));
            }

            if (fixer == null)
            {
                throw new ArgumentNullException(nameof(fixer));
            }

            if (svnBranchDeleter == null)
            {
                throw new ArgumentNullException(nameof(svnBranchDeleter));
            }

            if (lockBreaker == null)
            {
                throw new ArgumentNullException(nameof(lockBreaker));
            }

            try
            {
                PreRunPrepare();

                lockBreaker.BreakLocksIfEnabled();

                if (Options.Rebase)
                {
                    grabber.FetchBranches();
                }
                else if (!string.IsNullOrWhiteSpace(Options.RebaseBranch))
                {
                    grabber.FetchRebaseBraches();
                }
                else
                {
                    grabber.Clone();
                }

                fixer.FixBranches();
                fixer.FixTags();
                fixer.FixTrunk();
                fixer.OptimizeRepos();

                if (Options.StaleSvnBranchPurgeOption != StaleSvnBranchPurgeOptions.nothing)
                {
                    IEnumerable <string> svnBranches = svnBranchDeleter.QueryHeadSvnBranches();

                    IEnumerable <string> gitBranchesToPurge = svnBranchDeleter.GetGitBranchesToPurge(svnBranches);
                    svnBranches = null;

                    svnBranchDeleter.PurgeGitBranches(gitBranchesToPurge);
                    gitBranchesToPurge = null;

                    if (Options.StaleSvnBranchPurgeOption == StaleSvnBranchPurgeOptions.delete_local_and_remote)
                    {
                        gitPusher.PushPrune();
                    }
                }

                if (Options.PushWhenDone)
                {
                    gitPusher.PushAll();
                }
            }
            finally
            {
                PostRunCleanup();
            }
        }