Example #1
0
        public IRepository EnsureRepository(RepositoryType repositoryType)
        {
            // Validate if conflicting with existing repository
            RepositoryType existingType;
            if (TryGetExistingRepositoryType(out existingType) && existingType != repositoryType)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_MismatchRepository, repositoryType, existingType, _environment.RepositoryPath));
            }

            IRepository repository;
            if (repositoryType == RepositoryType.None)
            {
                repository = new NullRepository(_environment, _traceFactory, _httpContext);
            }
            else if (repositoryType == RepositoryType.Mercurial)
            {
                FileSystemHelpers.EnsureDirectory(_environment.RepositoryPath);
                repository = new HgRepository(_environment.RepositoryPath, _environment.RootPath, _settings, _traceFactory);
            }
            else
            {
                repository = CreateGitRepositoryInstance();
            }

            if (!repository.Exists)
            {
                repository.Initialize();
            }
            return repository;
        }
Example #2
0
        public IRepository EnsureRepository(RepositoryType repositoryType)
        {
            // Validate if conflicting with existing repository
            RepositoryType existingType;

            if (TryGetExistingRepositoryType(out existingType) && existingType != repositoryType)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_MismatchRepository, repositoryType, existingType, _environment.RepositoryPath));
            }

            IRepository repository;

            if (repositoryType == RepositoryType.None)
            {
                repository = new NullRepository(_environment, _traceFactory);
            }
            else if (repositoryType == RepositoryType.Mercurial)
            {
                FileSystemHelpers.EnsureDirectory(_environment.RepositoryPath);
                repository = new HgRepository(_environment.RepositoryPath, _environment.RootPath, _settings, _traceFactory);
            }
            else
            {
                repository = CreateGitRepositoryInstance();
            }

            if (!repository.Exists)
            {
                repository.Initialize();
            }
            return(repository);
        }
Example #3
0
        public void NullRepositoryCommitTests()
        {
            // arrange
            var settings = MockSettings();
            var environment = MockEnviroment(@"x:\site", settings.Object);
            var traceFactory = MockTraceFactory();
            var httpContext = MockHttpContext();

            // test
            var repository = new NullRepository(environment.Object, traceFactory.Object, httpContext.Object);

            // Assert
            Assert.Equal(RepositoryType.None, repository.RepositoryType);
            Assert.Equal(environment.Object.RepositoryPath, repository.RepositoryPath);
            Assert.Null(repository.CurrentId);
            Assert.Throws<InvalidOperationException>(() => repository.GetChangeSet("dummy"));
            Assert.Throws<InvalidOperationException>(() => repository.GetChangeSet("master"));

            // Simple commit
            var message = "this is testing";
            var author = "john doe";
            var email = "*****@*****.**";
            var success = repository.Commit(message, author + " <" + email + ">");

            // Assert
            Assert.True(success);
            Assert.NotNull(repository.CurrentId);

            // Validate changeset
            var changeSet = repository.GetChangeSet(repository.CurrentId);

            // Assert
            Assert.NotNull(changeSet);
            Assert.Equal(message, changeSet.Message);
            Assert.Equal(author, changeSet.AuthorName);
            Assert.Equal(email, changeSet.AuthorEmail);
            Assert.True(changeSet.IsReadOnly);
            Assert.Equal(repository.CurrentId, changeSet.Id);
            Assert.Throws<InvalidOperationException>(() => repository.GetChangeSet("dummy"));
            Assert.Same(changeSet, repository.GetChangeSet("master"));
            Assert.Same(changeSet, repository.GetChangeSet(repository.CurrentId));
        }