internal MergeProcessor(ObjectRepositoryMerge objectRepositoryMerge,
                                ComputeTreeChangesFactory computeTreeChangesFactory, GitHooks hooks)
        {
            _merge = objectRepositoryMerge ?? throw new ArgumentNullException(nameof(objectRepositoryMerge));

            _computeTreeChangesFactory = computeTreeChangesFactory ?? throw new ArgumentNullException(nameof(computeTreeChangesFactory));
            _hooks = hooks ?? throw new ArgumentNullException(nameof(hooks));
        }
        internal RebaseProcessor(ObjectRepositoryRebase objectRepositoryRebase,
                                 ComputeTreeChangesFactory computeTreeChangesFactory, ObjectRepositorySerializerFactory serializerFactory)
        {
            if (serializerFactory == null)
            {
                throw new ArgumentNullException(nameof(serializerFactory));
            }

            _rebase = objectRepositoryRebase ?? throw new ArgumentNullException(nameof(objectRepositoryRebase));

            _computeTreeChangesFactory = computeTreeChangesFactory ?? throw new ArgumentNullException(nameof(computeTreeChangesFactory));
            _serializer = serializerFactory(new ModelObjectSerializationContext(objectRepositoryRebase.Repository.Container));
        }
Beispiel #3
0
        internal CherryPickProcessor(ObjectRepositoryCherryPick objectRepositoryCherryPick,
                                     ComputeTreeChangesFactory computeTreeChangesFactory, ObjectRepositorySerializerFactory serializerFactory)
        {
            if (serializerFactory == null)
            {
                throw new ArgumentNullException(nameof(serializerFactory));
            }

            _cherryPick = objectRepositoryCherryPick ?? throw new ArgumentNullException(nameof(objectRepositoryCherryPick));

            _computeTreeChangesFactory = computeTreeChangesFactory ?? throw new ArgumentNullException(nameof(computeTreeChangesFactory));
            _serializer = serializerFactory(new ModelObjectSerializationContext(objectRepositoryCherryPick.Repository.Container));
        }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectRepositoryContainer{TRepository}"/> class.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="repositoryLoader">The repository loader.</param>
        /// <param name="computeTreeChangesFactory">The <see cref="IComputeTreeChanges"/> factory.</param>
        /// <param name="objectRepositoryMergeFactory">The <see cref="IObjectRepositoryMerge"/> factory.</param>
        /// <param name="objectRepositoryRebaseFactory">The <see cref="IObjectRepositoryRebase"/> factory.</param>
        /// <param name="objectRepositoryCherryPickFactory">The <see cref="IObjectRepositoryCherryPick"/> factory.</param>
        /// <param name="repositoryProvider">The repository provider.</param>
        /// <param name="hooks">The hooks.</param>
        /// <param name="serializerFactory">The <see cref="IObjectRepositorySerializer"/> factory.</param>
        /// <param name="logger">The logger.</param>
        public ObjectRepositoryContainer(string path,
                                         IObjectRepositoryLoader repositoryLoader, ComputeTreeChangesFactory computeTreeChangesFactory,
                                         ObjectRepositoryMergeFactory objectRepositoryMergeFactory, ObjectRepositoryRebaseFactory objectRepositoryRebaseFactory,
                                         ObjectRepositoryCherryPickFactory objectRepositoryCherryPickFactory,
                                         IRepositoryProvider repositoryProvider, GitHooks hooks,
                                         ObjectRepositorySerializerFactory serializerFactory, ILogger <ObjectRepositoryContainer> logger)
        {
            _repositoryLoader                  = repositoryLoader ?? throw new ArgumentNullException(nameof(repositoryLoader));
            _computeTreeChangesFactory         = computeTreeChangesFactory ?? throw new ArgumentNullException(nameof(computeTreeChangesFactory));
            _objectRepositoryMergeFactory      = objectRepositoryMergeFactory ?? throw new ArgumentNullException(nameof(objectRepositoryMergeFactory));
            _objectRepositoryRebaseFactory     = objectRepositoryRebaseFactory ?? throw new ArgumentNullException(nameof(objectRepositoryRebaseFactory));
            _objectRepositoryCherryPickFactory = objectRepositoryCherryPickFactory ?? throw new ArgumentNullException(nameof(objectRepositoryCherryPickFactory));
            _repositoryProvider                = repositoryProvider ?? throw new ArgumentNullException(nameof(repositoryProvider));
            _hooks             = hooks ?? throw new ArgumentNullException(nameof(hooks));
            _serializerFactory = serializerFactory ?? throw new ArgumentNullException(nameof(serializerFactory));
            _logger            = logger ?? throw new ArgumentNullException(nameof(logger));

            Path = path ?? throw new ArgumentNullException(nameof(path));
            Directory.CreateDirectory(path);

            Repositories = LoadRepositories();

            _logger.ContainerCreated(path);
        }
Beispiel #5
0
        public void ResolveDiffsPageDeletion(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message, ComputeTreeChangesFactory computeTreeChangesFactory)
        {
            // Arrange
            sut = container.AddRepository(sut, signature, message);
            var page = sut.Applications[0].Pages[1];
            var modifiedApplication = sut.With(c => c.Remove(sut.Applications[0], a => a.Pages, page));
            var commit = container.Commit(modifiedApplication, signature, message);

            // Act
            var changes = computeTreeChangesFactory(container, sut.RepositoryDescription)
                          .Compare(sut.CommitId, commit.CommitId)
                          .SkipIndexChanges();

            // Assert
            Assert.That(changes.Modified, Is.Empty);
            Assert.That(changes.Added, Is.Empty);
            Assert.That(changes, Has.Count.EqualTo(ModelCustomization.DefaultFieldPerPageCount + 1));
            var pageDeletion = changes.Deleted.FirstOrDefault(o => o.Old is Page);

            Assert.That(pageDeletion, Is.Not.Null);
            Assert.That(pageDeletion.New, Is.Null);
            Assert.That(pageDeletion.Old.Name, Is.EqualTo(page.Name));
        }
Beispiel #6
0
        public void ResolveDiffsFieldDeletion(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message, ComputeTreeChangesFactory computeTreeChangesFactory)
        {
            // Arrange
            sut = container.AddRepository(sut, signature, message);
            var page         = sut.Applications[0].Pages[0];
            var field        = page.Fields[5];
            var modifiedPage = sut.With(c => c.Remove(page, p => p.Fields, field));
            var commit       = container.Commit(modifiedPage, signature, message);

            // Act
            var changes = computeTreeChangesFactory(container, sut.RepositoryDescription)
                          .Compare(sut.CommitId, commit.CommitId)
                          .SkipIndexChanges();

            // Assert
            Assert.That(changes, Has.Count.EqualTo(1));
            Assert.That(changes[0].Status, Is.EqualTo(ChangeKind.Deleted));
            Assert.That(changes[0].New, Is.Null);
            Assert.That(changes[0].Old.Name, Is.EqualTo(field.Name));
        }
Beispiel #7
0
        public void ResolveDiffsFieldAddition(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, IServiceProvider serviceProvider, Signature signature, string message, ComputeTreeChangesFactory computeTreeChangesFactory)
        {
            // Arrange
            sut = container.AddRepository(sut, signature, message);
            var field        = new Field(serviceProvider, UniqueId.CreateNew(), "foo", FieldContent.Default);
            var modifiedPage = sut.With(c => c.Add(sut.Applications[0].Pages[0], p => p.Fields, field));
            var commit       = container.Commit(modifiedPage, signature, message);

            // Act
            var changes = computeTreeChangesFactory(container, sut.RepositoryDescription)
                          .Compare(sut.CommitId, commit.CommitId)
                          .SkipIndexChanges();

            // Assert
            Assert.That(changes, Has.Count.EqualTo(1));
            Assert.That(changes[0].Status, Is.EqualTo(ChangeKind.Added));
            Assert.That(changes[0].Old, Is.Null);
            Assert.That(changes[0].New.Name, Is.EqualTo(field.Name));
        }
Beispiel #8
0
        public void ResolveDiffsPageNameUpdate(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message, ComputeTreeChangesFactory computeTreeChangesFactory)
        {
            // Arrange
            sut = container.AddRepository(sut, signature, message);
            var modifiedPage = sut.With(sut.Applications[0].Pages[0], p => p.Name, "modified");
            var commit       = container.Commit(modifiedPage.Repository, signature, message);

            // Act
            var changes = computeTreeChangesFactory(container, sut.RepositoryDescription)
                          .Compare(sut.CommitId, commit.CommitId)
                          .SkipIndexChanges();

            // Assert
            Assert.That(changes, Has.Count.EqualTo(1));
            Assert.That(changes[0].Status, Is.EqualTo(ChangeKind.Modified));
            Assert.That(changes[0].Old.Name, Is.EqualTo(sut.Applications[0].Pages[0].Name));
            Assert.That(changes[0].New.Name, Is.EqualTo(modifiedPage.Name));
        }
Beispiel #9
0
        public void ResolveDiffsBlobUpdate(BlobRepository sut, IObjectRepositoryContainer <BlobRepository> container, Signature signature, string message, ComputeTreeChangesFactory computeTreeChangesFactory)
        {
            // Arrange
            sut = container.AddRepository(sut, signature, message);
            var modified = sut.With(sut, r => r.Blob, new StringBlob("z\nb\nz"));
            var commit   = container.Commit(modified.Repository, signature, message);

            // Act
            var changes = computeTreeChangesFactory(container, sut.RepositoryDescription)
                          .Compare(sut.CommitId, commit.CommitId)
                          .SkipIndexChanges();

            // Assert
            Assert.That(changes, Has.Count.EqualTo(1));
            Assert.That(changes[0].Status, Is.EqualTo(ChangeKind.Modified));
            Assert.That(((BlobRepository)changes[0].Old).Blob, Is.EqualTo(sut.Blob));
            Assert.That(((BlobRepository)changes[0].New).Blob, Is.EqualTo(modified.Blob));
        }
Beispiel #10
0
        public void ComputeChangesInLargeRepository(IObjectRepositoryContainer <ObjectRepository> container, IObjectRepositoryLoader loader, ComputeTreeChangesFactory computeTreeChangesFactory)
        {
            // Arrange
            var sut           = loader.LoadFrom(container, RepositoryFixture.BenchmarkRepositoryDescription);
            var fieldToModify = sut.Flatten().OfType <Field>().First(
                f => f.Content.MatchOrDefault(matchLink: l => true));
            var computeTreeChanges = computeTreeChangesFactory(container, RepositoryFixture.BenchmarkRepositoryDescription);
            var stopwatch          = Stopwatch.StartNew();

            // Act
            var modifiedField = sut.With(fieldToModify, f => f.Name, "modified");

            computeTreeChanges.Compare(sut, modifiedField.Repository);

            // Assert
            // Child loading is lazy so root load time should be really short
            Assert.That(stopwatch.Elapsed, Is.LessThan(TimeSpan.FromMilliseconds(300)));
        }
        public void MergeFileDeletionChange(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message, ComputeTreeChangesFactory computeTreeChangesFactory)
        {
            // master:    A---C---D
            //             \     /
            // newBranch:   B---'

            // Arrange
            var a = container.AddRepository(sut, signature, message); // A

            // Act
            a = container.Checkout(a.Id, "newBranch", createNewBranch: true);
            var page       = a.Applications[0].Pages[0];
            var updateName = a.With(c => c.Remove(page, p => p.Fields, page.Fields[1]));

            container.Commit(updateName, signature, message); // B
            a = container.Checkout(a.Id, "master");
            var updateDescription = a.With(a.Applications[0].Pages[0], p => p.Description, "modified description");
            var commitC           = container.Commit(updateDescription.Repository, signature, message); // C
            var mergeCommit       = container.Merge(sut.Id, "newBranch").Apply(signature);              // D

            // Assert
            var changes = computeTreeChangesFactory(container, container[sut.Id].RepositoryDescription)
                          .Compare(commitC.CommitId, mergeCommit)
                          .SkipIndexChanges();

            Assert.That(changes, Has.Count.EqualTo(1));
            Assert.That(changes[0].Status, Is.EqualTo(ChangeKind.Deleted));
            Assert.That(changes[0].Old.Id, Is.EqualTo(page.Fields[1].Id));
        }
        public void MergeFileAdditionChange(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, IServiceProvider serviceProvider, Signature signature, string message, ComputeTreeChangesFactory computeTreeChangesFactory)
        {
            // master:    A---C---D
            //             \     /
            // newBranch:   B---'

            // Arrange
            sut = container.AddRepository(sut, signature, message); // A

            // Act
            sut = container.Checkout(sut.Id, "newBranch", createNewBranch: true);
            var updateName = sut.With(c => c.Add(sut.Applications[0].Pages[0], p => p.Fields, new Field(serviceProvider, UniqueId.CreateNew(), "new field", FieldContent.Default)));

            container.Commit(updateName.Repository, signature, message); // B
            var a = container.Checkout(sut.Id, "master");
            var updateDescription = a.With(a.Applications[0].Pages[0], p => p.Description, "modified description");
            var commitC           = container.Commit(updateDescription.Repository, signature, message); // C
            var mergeCommit       = container.Merge(sut.Id, "newBranch").Apply(signature);              // D

            // Assert
            var changes = computeTreeChangesFactory(container, container[sut.Id].RepositoryDescription)
                          .Compare(commitC.CommitId, mergeCommit)
                          .SkipIndexChanges();

            Assert.That(changes, Has.Count.EqualTo(1));
            Assert.That(changes[0].Status, Is.EqualTo(ChangeKind.Added));
            Assert.That(changes[0].New.Name, Is.EqualTo("new field"));
        }
        public void MergeTwoDifferentPropertiesChanged(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message, ComputeTreeChangesFactory computeTreeChangesFactory)
        {
            // master:    A---C---D
            //             \     /
            // newBranch:   B---'

            // Arrange
            sut = container.AddRepository(sut, signature, message); // A

            // Act
            sut = container.Checkout(sut.Id, "newBranch", createNewBranch: true);
            var updateName = sut.With(sut.Applications[0].Pages[0], p => p.Name, "modified name");

            container.Commit(updateName.Repository, signature, message); // B
            var a = container.Checkout(sut.Id, "master");
            var updateDescription = a.With(a.Applications[0].Pages[0], p => p.Description, "modified description");
            var commitC           = container.Commit(updateDescription.Repository, signature, message); // C
            var mergeCommit       = container.Merge(sut.Id, "newBranch").Apply(signature);              // D

            // Assert
            var changes = computeTreeChangesFactory(container, container[sut.Id].RepositoryDescription)
                          .Compare(commitC.CommitId, mergeCommit)
                          .SkipIndexChanges();

            Assert.That(changes, Has.Count.EqualTo(1));
            Assert.That(changes[0].Status, Is.EqualTo(ChangeKind.Modified));
            Assert.That(changes[0].Old.Name, Is.EqualTo(sut.Applications[0].Pages[0].Name));
            Assert.That(changes[0].New.Name, Is.EqualTo(updateName.Name));
        }
        public void MergeSamePropertyConflict(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message, ComputeTreeChangesFactory computeTreeChangesFactory)
        {
            // master:    A---C---D
            //             \     /
            // newBranch:   B---'

            // Arrange
            var a = container.AddRepository(sut, signature, message); // A

            // Act
            a = container.Checkout(sut.Id, "newBranch", createNewBranch: true);
            var updateName = a.With(a.Applications[0].Pages[0], p => p.Name, "modified name");

            container.Commit(updateName.Repository, signature, message); // B
            a = container.Checkout(sut.Id, "master");
            var updateNameOther = a.With(a.Applications[0].Pages[0], p => p.Name, "yet again modified name");
            var commitC         = container.Commit(updateNameOther.Repository, signature, message); // C
            var merge           = container.Merge(sut.Id, "newBranch");
            var chunk           = merge.ModifiedProperties.Single();

            chunk.Resolve("merged name");
            var mergeCommit = merge.Apply(signature); // D

            // Assert
            var changes = computeTreeChangesFactory(container, container[sut.Id].RepositoryDescription)
                          .Compare(commitC.CommitId, mergeCommit)
                          .SkipIndexChanges();

            Assert.That(changes, Has.Count.EqualTo(1));
            Assert.That(changes[0].Status, Is.EqualTo(ChangeKind.Modified));
            Assert.That(changes[0].Old.Name, Is.EqualTo("yet again modified name"));
            Assert.That(changes[0].New.Name, Is.EqualTo("merged name"));
        }