Пример #1
0
        /// <summary>
        /// Adds the commits of a branch in oldest-to-newest order. and returns the list of commits.
        /// </summary>
        public List <ShallowCommit> AddBranch(Branch branch)
        {
            var commits = RepoUtil.GetPrimaryParents(branch.Tip).Select(ShallowCommit.FromCommit).Reverse().ToList();

            this.branches.Add(commits);
            return(commits);
        }
Пример #2
0
        /// <summary>
        /// Records a list of commits.
        /// </summary>
        private void RecordCommits(Repository repo, IEnumerable <ShallowCommit> commits)
        {
            foreach (var commit in commits)
            {
                if (this.Commits.Contains(commit))
                {
                    continue;
                }

                this.Commits.Add(commit);
                if (commit.Parents.Count() > 1)
                {
                    this.Merges.Add(commit);
                    foreach (var parent in commit.Parents.Skip(1))
                    {
                        this.RecordCommits(repo, RepoUtil.GetPrimaryParents(repo, parent.Sha).Select(ShallowCommit.FromCommit));
                    }
                }
            }
        }
Пример #3
0
        public void TestZipScenarios(ZipScenario scenario)
        {
            var config = new Config {
                Sources = GetTestRepoPaths(scenario.Sources),
                Target  = TestData.GetCleanTempDir(),
                Force   = true,
                Silent  = true
            };
            var zipper = new RepoZipper(config);
            var repo   = zipper.Zip();

            var branches = repo.Branches.Where(b => !b.IsRemote).ToList();

            Assert.That(branches.Select(b => b.FriendlyName),
                        Is.EquivalentTo(scenario.Branches.Keys));

            foreach (var branch in branches)
            {
                var commits = RepoUtil.GetPrimaryParents(branch.Tip).Select(c => c.Message).Reverse();
                Assert.That(commits,
                            Is.EqualTo(scenario.Branches[branch.FriendlyName].Select(sha => (repo.Lookup(sha) as Commit).Message)),
                            "Commits do not match for branch: " + branch.FriendlyName
                            );
            }

            // TODO this may be unified with ZippedRepoTest
            var merges = RepoUtil.GetMerges(branches.Select(b => b.Tip)).ToList();             // just retrieve merges for zipped branches

            Assert.That(merges.Select(m => m.Message), Is.EquivalentTo(scenario.Merges.Select(c => Lookup(repo, c.Sha).Message)));

            // We have to skip the 1st parent as this one may be different
            var actual   = merges.Select(c => c.Parents.Skip(1).Select(p => p.Message));
            var expected = scenario.Merges.Select(c => c.Parents.Skip(1).Select(p => Lookup(repo, p).Message));

            Assert.That(actual, Is.EquivalentTo(expected));
        }