Example #1
0
        public void NoBranches_PlaysInSequence()
        {
            var file1 = new FileInfo("file1");
            var file2 = new FileInfo("file2");

            var commit0 = new Commit("id0")
            {
                Index = 1
            }
            .WithRevision(file1, "1.1")
            .WithRevision(file2, "1.1");

            var commit1 = new Commit("id1")
            {
                Index = 2
            }
            .WithRevision(file1, "1.2");

            var commit2 = new Commit("id2")
            {
                Index = 3
            }
            .WithRevision(file2, "1.2");

            var commits  = new[] { commit0, commit1, commit2 };
            var branches = new BranchStreamCollection(commits, new Dictionary <string, Commit>());

            var player = new CommitPlayer(MockRepository.GenerateStub <ILogger>(), branches);
            var result = player.Play().ToList();

            Assert.IsTrue(result.SequenceEqual(commits));
        }
Example #2
0
        public void MergeFromParentBranch_Ignore()
        {
            var commits = new List <Commit>()
            {
                new Commit("initial").WithRevision(m_file, "1.1"),
                new Commit("branch1").WithRevision(m_file, "1.1.2.1"),
                new Commit("main1").WithRevision(m_file, "1.2"),
                new Commit("branch2").WithRevision(m_file, "1.1.2.2", mergepoint: "1.2"),
            };

            m_file.WithBranch("branch", "1.1.0.2");

            var branchpoints = new Dictionary <string, Commit>()
            {
                { "branch", commits[0] }
            };

            var streams  = new BranchStreamCollection(commits, branchpoints);
            var resolver = new MergeResolver(m_logger, streams);

            resolver.Resolve();

            Assert.IsTrue(streams["MAIN"].ToList().All(c => c.MergeFrom == null));
            Assert.IsTrue(streams["branch"].ToList().All(c => c.MergeFrom == null));
        }
        public void Roots()
        {
            var streams = new BranchStreamCollection(m_commits, m_branchpoints);

            Assert.IsTrue(streams["MAIN"] == m_commits[0]);
            Assert.IsTrue(streams["branch"] == m_commits[1]);
        }
        public void Heads()
        {
            var streams = new BranchStreamCollection(m_commits, m_branchpoints);

            Assert.IsTrue(streams.Head("MAIN") == m_commits[2]);
            Assert.IsTrue(streams.Head("branch") == m_commits[1]);
        }
Example #5
0
        public void CrossedMerge_LongerHistoryOnMergeDestination()
        {
            var commits = new List <Commit>()
            {
                new Commit("initial1").WithRevision(m_file, "1.1"),
                new Commit("initial2").WithRevision(m_file, "1.2"),
                new Commit("initial3").WithRevision(m_file, "1.3"),
                new Commit("branch1").WithRevision(m_file, "1.3.2.1"),
                new Commit("branch2").WithRevision(m_file, "1.3.2.2"),
                new Commit("merge1").WithRevision(m_file, "1.4", mergepoint: "1.3.2.2"),
                new Commit("merge2").WithRevision(m_file, "1.5", mergepoint: "1.3.2.1"),
            };

            m_file.WithBranch("branch", "1.3.0.2");

            var branchpoints = new Dictionary <string, Commit>()
            {
                { "branch", commits[0] }
            };

            var streams  = new BranchStreamCollection(commits, branchpoints);
            var resolver = new MergeResolver(m_logger, streams);

            resolver.Resolve();

            Assert.IsTrue(streams["MAIN"].ToList().Select(c => c.CommitId).SequenceEqual("initial1", "initial2", "initial3", "merge1", "merge2"));
            Assert.IsTrue(streams["branch"].ToList().Select(c => c.CommitId).SequenceEqual("branch2", "branch1"));
        }
        public void CreateHeadOnlyCommits_MessageSet()
        {
            var f1            = new FileInfo("file1").WithBranch("branch1", "1.1.0.2");
            var f2            = new FileInfo("file2").WithBranch("branch1", "1.1.0.2");
            var mainCommit1   = new Commit("c1").WithRevision(f1, "1.1").WithRevision(f2, "1.1");
            var branchCommit1 = new Commit("c2").WithRevision(f1, "1.1.2.1").WithRevision(f2, "1.1.2.1");

            var branchpoints = new Dictionary <string, Commit>()
            {
                { "branch1", mainCommit1 },
            };

            IEnumerable <Commit> commits = new[] { mainCommit1, branchCommit1 };
            var streams = new BranchStreamCollection(commits, branchpoints);

            // rename branch1
            var renamer = new Renamer();

            renamer.AddRule(new RenameRule(@"^MAIN$", "master"));
            renamer.AddRule(new RenameRule(@"^branch(\d)", "BRANCH#$1"));
            m_config.Stub(c => c.BranchRename).Return(renamer);

            m_config.Stub(c => c.IncludeFile("file1")).Return(true);
            m_config.Stub(c => c.IncludeFile("file2")).Return(false);
            m_config.Stub(c => c.IsHeadOnly("file1")).Return(false);
            m_config.Stub(c => c.IsHeadOnly("file2")).Return(true);

            var filter = new ExclusionFilter(m_log, m_config);

            commits = filter.Filter(commits).ToListIfNeeded();

            filter.CreateHeadOnlyCommits(new[] { "MAIN", "branch1" }, streams, AllFiles(f1, f2));
            Assert.AreEqual(streams.Head("MAIN").Message, "Adding head-only files to master");
            Assert.AreEqual(streams.Head("branch1").Message, "Adding head-only files to BRANCH#1");
        }
        public void CreateHeadOnlyCommits_FileDeletedInMerge()
        {
            var f1            = new FileInfo("file1").WithBranch("branch1", "1.1.0.2");
            var f2            = new FileInfo("file2").WithBranch("branch1", "1.1.0.2");
            var mainCommit1   = new Commit("c1").WithRevision(f1, "1.1").WithRevision(f2, "1.1");
            var branchCommit1 = new Commit("c2").WithRevision(f1, "1.1.2.1").WithRevision(f2, "1.1.2.1");
            var mainCommit2   = new Commit("c3").WithRevision(f1, "1.2", mergepoint: "1.1.2.1").WithRevision(f2, "1.2", mergepoint: "1.1.2.1");
            var mainCommit3   = new Commit("c4").WithRevision(f2, "1.3", isDead: true);

            var branchpoints = new Dictionary <string, Commit>()
            {
                { "branch1", mainCommit1 },
            };

            IEnumerable <Commit> commits = new[] { mainCommit1, branchCommit1, mainCommit2, mainCommit3 };
            var streams = new BranchStreamCollection(commits, branchpoints);

            m_config.Stub(c => c.IncludeFile("file1")).Return(false);
            m_config.Stub(c => c.IncludeFile("file2")).Return(false);
            m_config.Stub(c => c.IsHeadOnly("file1")).Return(true);
            m_config.Stub(c => c.IsHeadOnly("file2")).Return(true);
            m_config.Stub(c => c.BranchRename).Return(new Renamer());

            var filter = new ExclusionFilter(m_log, m_config);

            commits = filter.Filter(commits).ToListIfNeeded();

            filter.CreateHeadOnlyCommits(new[] { "MAIN", "branch1" }, streams, AllFiles(f1, f2));

            var mainHead = streams.Head("MAIN");

            Assert.IsTrue(mainHead.CommitId == "headonly-MAIN");
            Assert.IsTrue(mainHead.Where(r => !r.IsDead).Single().File.Name == "file1");
            Assert.IsTrue(mainHead.Where(r => r.IsDead).Single().File.Name == "file2");
        }
        public void CreateHeadOnlyCommits_MergeFromBranch()
        {
            var f1            = new FileInfo("file1").WithBranch("branch1", "1.1.0.2");
            var f2            = new FileInfo("file2").WithBranch("branch1", "1.1.0.2");
            var mainCommit1   = new Commit("c1").WithRevision(f1, "1.1").WithRevision(f2, "1.1");
            var branchCommit1 = new Commit("c2").WithRevision(f1, "1.1.2.1").WithRevision(f2, "1.1.2.1");
            var mainCommit2   = new Commit("c3").WithRevision(f1, "1.2", mergepoint: "1.1.2.1").WithRevision(f2, "1.2", mergepoint: "1.1.2.1");

            var branchpoints = new Dictionary <string, Commit>()
            {
                { "branch1", mainCommit2 },
            };

            IEnumerable <Commit> commits = new[] { mainCommit1, branchCommit1, mainCommit2 };
            var streams = new BranchStreamCollection(commits, branchpoints);

            m_config.Stub(c => c.IncludeFile("file1")).Return(true);
            m_config.Stub(c => c.IncludeFile("file2")).Return(false);
            m_config.Stub(c => c.IsHeadOnly("file1")).Return(false);
            m_config.Stub(c => c.IsHeadOnly("file2")).Return(true);
            m_config.Stub(c => c.BranchRename).Return(new Renamer());

            var filter = new ExclusionFilter(m_log, m_config);

            commits = filter.Filter(commits).ToListIfNeeded();

            filter.CreateHeadOnlyCommits(new[] { "MAIN", "branch1" }, streams, AllFiles(f1, f2));
            Assert.AreEqual(streams.Head("MAIN").CommitId, "headonly-MAIN", "Commit created on HEAD");
            Assert.AreEqual(streams.Head("branch1").CommitId, "headonly-branch1", "Commit created on branch1");
            Assert.AreSame(streams.Head("MAIN").MergeFrom, streams.Head("branch1"), "Merge from branch1 to HEAD");
        }
        public void Construct()
        {
            var streams = new BranchStreamCollection(m_commits, m_branchpoints);

            Assert.IsTrue(streams["MAIN"].ToList().Select(c => c.CommitId).SequenceEqual("1", "3"));
            Assert.IsTrue(streams["branch"].ToList().Single().CommitId == "2");
            Assert.IsTrue(streams.Verify());
        }
        public void Construct_IgnoredBranch()
        {
            // remove 'branch' from the list of branchpoints, simulating an ignored branch
            m_branchpoints.Remove("branch");
            var streams = new BranchStreamCollection(m_commits, m_branchpoints);

            Assert.IsFalse(streams["branch"].ToList().Any());
        }
        public void MoveCommit_ToItself()
        {
            var streams = new BranchStreamCollection(m_commits, m_branchpoints);

            streams.MoveCommit(m_commits[2], m_commits[2]);

            Assert.IsTrue(streams["MAIN"].ToList().SequenceEqual(m_commits[0], m_commits[2]));
            Assert.IsTrue(streams.Verify());
        }
        public void AppendCommit_ToBranch()
        {
            var streams = new BranchStreamCollection(m_commits, m_branchpoints);

            var commit = new Commit("new").WithRevision(m_f1, "1.1.2.2");

            streams.AppendCommit(commit);

            Assert.AreSame(streams.Head("branch"), commit);
            Assert.AreSame(streams["branch"].Successor, commit);
            Assert.IsTrue(commit.Index > streams["MAIN"].Index, "Index set");
        }
        public void MoveCommit_FromStart()
        {
            m_commits.Add(new Commit("4").WithRevision(m_f1, "1.1.2.2"));
            m_commits.Add(new Commit("5").WithRevision(m_f1, "1.1.2.3"));
            var streams = new BranchStreamCollection(m_commits, m_branchpoints);

            streams.MoveCommit(m_commits[1], m_commits[4]);

            Assert.IsTrue(streams["branch"].CommitId == "4");
            Assert.IsTrue(streams["branch"].ToList().Select(c => c.CommitId).SequenceEqual("4", "5", "2"));
            Assert.IsTrue(streams.Verify());
        }
        public void MoveCommit_ToEnd()
        {
            m_commits.Add(new Commit("4").WithRevision(m_f1, "1.3"));
            m_commits.Add(new Commit("5").WithRevision(m_f1, "1.4"));
            var streams = new BranchStreamCollection(m_commits, m_branchpoints);

            streams.MoveCommit(m_commits[3], m_commits[4]);

            Assert.IsTrue(streams["MAIN"].ToList().Select(c => c.CommitId).SequenceEqual("1", "3", "5", "4"));
            Assert.IsTrue(streams.Head("MAIN").CommitId == "4");
            Assert.IsTrue(streams.Verify());
        }
Example #15
0
        public void NestedBranches_PlaysInSequence()
        {
            var now          = DateTime.Now;
            var commits      = CreateNestedBranches();
            var branchpoints = new Dictionary <string, Commit>()
            {
                { "branch0", commits[0] },
                { "branch1", commits[2] }
            };
            var branches = new BranchStreamCollection(commits, branchpoints);

            var player = new CommitPlayer(MockRepository.GenerateStub <ILogger>(), branches);
            var result = player.Play().Select(c => c.CommitId).ToList();

            Assert.IsTrue(result.SequenceEqual(new[] { "id0", "branch0_0", "branch1_0", "branch0_1", "id1" }));
        }
Example #16
0
        public void SingleMergeOnExcludedBranch_NoMergeFilledIn()
        {
            var commits = new List <Commit>()
            {
                new Commit("initial").WithRevision(m_file, "1.1"),
                new Commit("merge").WithRevision(m_file, "1.2", mergepoint: "1.1.2.1"),
            };

            var branchpoints = new Dictionary <string, Commit>()
            {
                { "branch", commits[0] }
            };

            var streams  = new BranchStreamCollection(commits, branchpoints);
            var resolver = new MergeResolver(m_logger, streams);

            resolver.Resolve();

            Assert.IsTrue(streams["MAIN"].ToList().All(c => c.MergeFrom == null));
        }
        public void OrderedBranches()
        {
            Commit subBranchPoint;

            m_commits.AddRange(new[]
            {
                new Commit("4").WithRevision(m_f1, "1.3"),
                new Commit("5").WithRevision(m_f1, "1.1.2.2"),
                subBranchPoint = new Commit("6").WithRevision(m_f1, "1.1.2.3"),
                new Commit("7").WithRevision(m_f1, "1.1.2.3.2.1"),
            });

            m_f1.WithBranch("subbranch", "1.1.2.3.0.2");
            m_branchpoints["subbranch"] = subBranchPoint;
            var streams = new BranchStreamCollection(m_commits, m_branchpoints);

            var orderedBranches = streams.OrderedBranches.ToList();

            Assert.IsTrue(orderedBranches.SequenceEqual("MAIN", "branch", "subbranch"));
        }
Example #18
0
        public void SingleBranch_PlaysInSequence()
        {
            var now   = DateTime.Now;
            var file1 = new FileInfo("file1");
            var file2 = new FileInfo("file2").WithBranch("branch", "1.1.0.2");

            var commit0 = new Commit("id0")
            {
                Index = 1
            }
            .WithRevision(file1, "1.1", time: now)
            .WithRevision(file2, "1.1", time: now);

            var commit1 = new Commit("id1")
            {
                Index = 2
            }
            .WithRevision(file1, "1.2", time: now + TimeSpan.FromMinutes(2))
            .WithRevision(file2, "1.2", time: now + TimeSpan.FromMinutes(2), mergepoint: "1.1.2.1");

            var commit2 = new Commit("branch0")
            {
                Index = 3
            }
            .WithRevision(file2, "1.1.2.1", time: now + TimeSpan.FromMinutes(1));

            var commits      = new[] { commit0, commit1, commit2 };
            var branchpoints = new Dictionary <string, Commit>()
            {
                { "branch", commit0 }
            };
            var branches = new BranchStreamCollection(commits, branchpoints);

            commit1.MergeFrom = commit2;

            var player = new CommitPlayer(MockRepository.GenerateStub <ILogger>(), branches);
            var result = player.Play().Select(c => c.CommitId).ToList();

            Assert.IsTrue(result.SequenceEqual("id0", "branch0", "id1"));
        }
        public void Branches()
        {
            var streams = new BranchStreamCollection(m_commits, m_branchpoints);

            Assert.IsTrue(streams.Branches.OrderBy(x => x, StringComparer.OrdinalIgnoreCase).SequenceEqual("branch", "MAIN"));
        }
		public void CreateHeadOnlyCommits_MergeFromBranch()
		{
			var f1 = new FileInfo("file1").WithBranch("branch1", "1.1.0.2");
			var f2 = new FileInfo("file2").WithBranch("branch1", "1.1.0.2");
			var mainCommit1 = new Commit("c1").WithRevision(f1, "1.1").WithRevision(f2, "1.1");
			var branchCommit1 = new Commit("c2").WithRevision(f1, "1.1.2.1").WithRevision(f2, "1.1.2.1");
			var mainCommit2 = new Commit("c3").WithRevision(f1, "1.2", mergepoint: "1.1.2.1").WithRevision(f2, "1.2", mergepoint: "1.1.2.1");

			var branchpoints = new Dictionary<string, Commit>()
			{
				{ "branch1", mainCommit2 },
			};

			IEnumerable<Commit> commits = new[] { mainCommit1, branchCommit1, mainCommit2 };
			var streams = new BranchStreamCollection(commits, branchpoints);

			m_config.Stub(c => c.IncludeFile("file1")).Return(true);
			m_config.Stub(c => c.IncludeFile("file2")).Return(false);
			m_config.Stub(c => c.IsHeadOnly("file1")).Return(false);
			m_config.Stub(c => c.IsHeadOnly("file2")).Return(true);
			m_config.Stub(c => c.BranchRename).Return(new Renamer());

			var filter = new ExclusionFilter(m_log, m_config);
			commits = filter.Filter(commits).ToListIfNeeded();

			filter.CreateHeadOnlyCommits(new[] { "MAIN", "branch1" }, streams, AllFiles(f1, f2));
			Assert.AreEqual(streams.Head("MAIN").CommitId, "headonly-MAIN", "Commit created on HEAD");
			Assert.AreEqual(streams.Head("branch1").CommitId, "headonly-branch1", "Commit created on branch1");
			Assert.AreSame(streams.Head("MAIN").MergeFrom, streams.Head("branch1"), "Merge from branch1 to HEAD");
		}
        public void Construct_BranchPredecessorSet()
        {
            var streams = new BranchStreamCollection(m_commits, m_branchpoints);

            Assert.IsTrue(streams["branch"].ToList().Single().Predecessor == m_commits[0]);
        }
		public void CreateHeadOnlyCommits_FileDeletedInMerge()
		{
			var f1 = new FileInfo("file1").WithBranch("branch1", "1.1.0.2");
			var f2 = new FileInfo("file2").WithBranch("branch1", "1.1.0.2");
			var mainCommit1 = new Commit("c1").WithRevision(f1, "1.1").WithRevision(f2, "1.1");
			var branchCommit1 = new Commit("c2").WithRevision(f1, "1.1.2.1").WithRevision(f2, "1.1.2.1");
			var mainCommit2 = new Commit("c3").WithRevision(f1, "1.2", mergepoint: "1.1.2.1").WithRevision(f2, "1.2", mergepoint: "1.1.2.1");
			var mainCommit3 = new Commit("c4").WithRevision(f2, "1.3", isDead: true);

			var branchpoints = new Dictionary<string, Commit>()
			{
				{ "branch1", mainCommit1 },
			};

			IEnumerable<Commit> commits = new[] { mainCommit1, branchCommit1, mainCommit2, mainCommit3 };
			var streams = new BranchStreamCollection(commits, branchpoints);

			m_config.Stub(c => c.IncludeFile("file1")).Return(false);
			m_config.Stub(c => c.IncludeFile("file2")).Return(false);
			m_config.Stub(c => c.IsHeadOnly("file1")).Return(true);
			m_config.Stub(c => c.IsHeadOnly("file2")).Return(true);
			m_config.Stub(c => c.BranchRename).Return(new Renamer());

			var filter = new ExclusionFilter(m_log, m_config);
			commits = filter.Filter(commits).ToListIfNeeded();

			filter.CreateHeadOnlyCommits(new[] { "MAIN", "branch1" }, streams, AllFiles(f1, f2));

			var mainHead = streams.Head("MAIN");
			Assert.IsTrue(mainHead.CommitId == "headonly-MAIN");
			Assert.IsTrue(mainHead.Where(r => !r.IsDead).Single().File.Name == "file1");
			Assert.IsTrue(mainHead.Where(r => r.IsDead).Single().File.Name == "file2");
		}
		public void CreateHeadOnlyCommits_MessageSet()
		{
			var f1 = new FileInfo("file1").WithBranch("branch1", "1.1.0.2");
			var f2 = new FileInfo("file2").WithBranch("branch1", "1.1.0.2");
			var mainCommit1 = new Commit("c1").WithRevision(f1, "1.1").WithRevision(f2, "1.1");
			var branchCommit1 = new Commit("c2").WithRevision(f1, "1.1.2.1").WithRevision(f2, "1.1.2.1");

			var branchpoints = new Dictionary<string, Commit>()
			{
				{ "branch1", mainCommit1 },
			};

			IEnumerable<Commit> commits = new[] { mainCommit1, branchCommit1 };
			var streams = new BranchStreamCollection(commits, branchpoints);

			// rename branch1
			var renamer = new Renamer();
			renamer.AddRule(new RenameRule(@"^MAIN$", "master"));
			renamer.AddRule(new RenameRule(@"^branch(\d)", "BRANCH#$1"));
			m_config.Stub(c => c.BranchRename).Return(renamer);

			m_config.Stub(c => c.IncludeFile("file1")).Return(true);
			m_config.Stub(c => c.IncludeFile("file2")).Return(false);
			m_config.Stub(c => c.IsHeadOnly("file1")).Return(false);
			m_config.Stub(c => c.IsHeadOnly("file2")).Return(true);

			var filter = new ExclusionFilter(m_log, m_config);
			commits = filter.Filter(commits).ToListIfNeeded();

			filter.CreateHeadOnlyCommits(new[] { "MAIN", "branch1" }, streams, AllFiles(f1, f2));
			Assert.AreEqual(streams.Head("MAIN").Message, "Adding head-only files to master");
			Assert.AreEqual(streams.Head("branch1").Message, "Adding head-only files to BRANCH#1");
		}
        public void MoveCommit_Backwards()
        {
            var streams = new BranchStreamCollection(m_commits, m_branchpoints);

            streams.MoveCommit(m_commits[2], m_commits[1]);
        }