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; }
public IRepository EnsureRepository(RepositoryType repositoryType) { if (repositoryType == RepositoryType.Mercurial) { if (IsGitRepository) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_MismatchRepository, repositoryType, RepositoryType.Git, _environment.RepositoryPath)); } FileSystemHelpers.EnsureDirectory(_environment.RepositoryPath); var hgRepository = new HgRepository(_environment.RepositoryPath, _environment.SiteRootPath, _settings, _traceFactory); if (!hgRepository.Exists) { hgRepository.Initialize(); } return hgRepository; } else { if (IsHgRepository) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_MismatchRepository, repositoryType, RepositoryType.Mercurial, _environment.RepositoryPath)); } var gitRepository = new GitExeRepository(_environment.RepositoryPath, _environment.SiteRootPath, _settings, _traceFactory); if (!gitRepository.Exists) { gitRepository.Initialize(); } return gitRepository; } }
public void HgRepositoryCanFetchBranchFromRemoteRepository() { const string repositoryName = "fetchTest"; using (TestRepository testRepository = GetRepository(repositoryName)) { // Arrange string remoteRepository = "https://[email protected]/kudutest/hellomercurial"; string helloTextPath = Path.Combine(testRepository.PhysicalPath, "Hello.txt"); var hgRepo = new HgRepository(testRepository.PhysicalPath, "", new MockDeploymentSettingsManager(), NullTracerFactory.Instance); hgRepo.Initialize(); // Act - 1 hgRepo.FetchWithoutConflict(remoteRepository, remoteAlias: null, branchName: "default"); // Assert - 1 Assert.Equal("Hello mercurial!", File.ReadAllText(helloTextPath)); Assert.Equal("e2ff43634d31a70383142a4b3940baff8b6386ee", hgRepo.CurrentId); // Act - 2 // Make uncommitted changes File.WriteAllText(helloTextPath, "uncommitted changes"); // Act - 2 hgRepo.FetchWithoutConflict(remoteRepository, remoteAlias: null, branchName: "test"); // Assert - 2 Assert.Equal("This is a commit from test", File.ReadAllText(helloTextPath)); Assert.Equal("7648ca7e03987b5d4204fcb283c687dada051ce5", hgRepo.CurrentId); } }
public void ChangeLogFromHgRepositoryAreAccurate() { const string repositoryName = "changeLog"; using (TestRepository testRepository = GetRepository(repositoryName)) { // Arrange string helloTextPath = Path.Combine(testRepository.PhysicalPath, "Hello.txt"); var hgRepo = new HgRepository(testRepository.PhysicalPath, "", new MockDeploymentSettingsManager(), NullTracerFactory.Instance); // Act hgRepo.Initialize(); File.WriteAllText(helloTextPath, "Hello world"); hgRepo.AddFile(helloTextPath); hgRepo.Commit("First commit"); File.AppendAllText(helloTextPath, "Hello again"); hgRepo.Commit("Second commit"); List<ChangeSet> changes = hgRepo.GetChanges().ToList(); // Assert - 1 Assert.Equal(2, changes.Count()); var lastChange = changes[0]; Assert.Equal("Second commit", lastChange.Message); } }
public void FetchWithoutConflictOnEmptyRepoReturnsFalse() { using (TestRepository testRepository = GetRepository()) { // Arrange var hgRepo = new HgRepository(testRepository.PhysicalPath, "", new MockDeploymentSettingsManager(), NullTracerFactory.Instance); // Act hgRepo.Initialize(); Assert.Throws<BranchNotFoundException>(() => hgRepo.FetchWithoutConflict("https://bitbucket.org/kudutest/emptyhgrepo", "default")); } }
//[Fact] public void FetchWithoutConflictOnHgEmptyRepo() { // Arrange var executable = new Mock<IExecutable>(); executable.Setup(e => e.EnvironmentVariables).Returns(new Dictionary<string, string>()); executable.Setup(e => e.Execute(It.IsAny<ITracer>(), "pull {0} --branch {1} --noninteractive", It.IsAny<object[]>())) .Callback((ITracer tracer, string arguments, object[] args) => { throw new CommandLineException("hg.exe", "pull", "abort: unknown branch 'default'!"); }); var hgRepository = new HgRepository(executable.Object, @"x:\some-path", Mock.Of<ITraceFactory>()); // Act Assert.Throws<BranchNotFoundException>(() => hgRepository.FetchWithoutConflict("https://some-remote", "default")); }
public void FetchWithoutConflictOnEmptyRepoReturnsFalse() { using (TestRepository testRepository = GetRepository()) { // Arrange var hgRepo = new HgRepository(testRepository.PhysicalPath, "", new MockDeploymentSettingsManager(), NullTracerFactory.Instance); // Act hgRepo.Initialize(); var ex = Assert.Throws<InvalidOperationException>(() => hgRepo.FetchWithoutConflict("https://bitbucket.org/kudutest/emptyhgrepo", "default")); // Assert Assert.Contains("Could not fetch remote branch 'default'. Verify that the branch exists in the repository.", ex.Message); } }
public void HgGetChangeSetReturnsNullIfIdDoesNotExist() { // Arrange using (TestRepository testRepository = GetRepository()) { var hgRepo = new HgRepository(testRepository.PhysicalPath, "", new MockDeploymentSettingsManager(), NullTracerFactory.Instance); hgRepo.Initialize(); // Act var changeset = hgRepo.GetChangeSet("does-not-exist"); // Assert Assert.Null(changeset); } }
//[Fact] public void FetchWithoutConflictsRetriesWithRecoveryIfInitialFetchFails() { // Arrange var executable = new Mock<IExecutable>(); executable.Setup(e => e.EnvironmentVariables).Returns(new Dictionary<string, string>()); executable.Setup(e => e.Execute(It.IsAny<ITracer>(), "pull {0} --branch {1} --noninteractive", It.IsAny<object[]>())) .Throws(new CommandLineException("hg.exe", "", "Fetching\r\nabort: abandoned transaction found - run hg recover!\r\n") { ExitCode = 255 }) .Verifiable(); executable.Setup(e => e.Execute(It.IsAny<ITracer>(), "recover")) .Verifiable(); var hgRepository = new HgRepository(executable.Object, @"x:\some-path", Mock.Of<ITraceFactory>()); // Act and Assert Assert.Throws<CommandLineException>(() => hgRepository.FetchWithoutConflict("https://some-remote", "default")); executable.Verify(e => e.Execute(It.IsAny<ITracer>(), "pull {0} --branch {1} --noninteractive", It.IsAny<object[]>()), Times.Exactly(2)); executable.Verify(e => e.Execute(It.IsAny<ITracer>(), "recover", It.IsAny<object[]>()), Times.Once()); }
public void FetchWithoutConflictsDoesNotExecuteRecoverIfFirstAttemptSucceeds() { // Arrange var executable = new Mock<IExecutable>(); executable.Setup(e => e.EnvironmentVariables).Returns(new Dictionary<string, string>()); executable.Setup(e => e.Execute(It.IsAny<ITracer>(), "pull {0} --branch {1} --noninteractive", It.IsAny<object[]>())) .Returns(Tuple.Create("foo", "bar")) .Verifiable(); executable.Setup(e => e.Execute(It.IsAny<ITracer>(), "recover")) .Verifiable(); var hgRepository = new HgRepository(executable.Object, @"x:\some-path", Mock.Of<ITraceFactory>()); // Act hgRepository.FetchWithoutConflict("https://some-remote", "external", "default"); // Assert executable.Verify(e => e.Execute(It.IsAny<ITracer>(), "pull {0} --branch {1} --noninteractive", It.IsAny<object[]>()), Times.Once()); executable.Verify(e => e.Execute(It.IsAny<ITracer>(), "recover", It.IsAny<object[]>()), Times.Never()); }
public void HgExecutableClonesRepository() { const string expectedId = "e2ff43634d31a70383142a4b3940baff8b6386ee"; const string source = "https://[email protected]/kudutest/hellomercurial"; // Arrange using (TestRepository testRepository = GetRepository(source)) { string helloTextPath = Path.Combine(testRepository.PhysicalPath, "Hello.txt"); string hgFolderPath = Path.Combine(testRepository.PhysicalPath, ".hg"); var hgRepo = new HgRepository(testRepository.PhysicalPath, "", new MockDeploymentSettingsManager(), NullTracerFactory.Instance); // Act hgRepo.Clone(source); string actualId = hgRepo.CurrentId; // Assert Assert.True(File.Exists(helloTextPath)); Assert.True(Directory.Exists(hgFolderPath)); Assert.Equal(expectedId, actualId); } }