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, 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, branchName: "test");

                // Assert - 2
                Assert.Equal("This is a commit from test", File.ReadAllText(helloTextPath));
                Assert.Equal("7648ca7e03987b5d4204fcb283c687dada051ce5", hgRepo.CurrentId);
            }
        }
示例#2
0
        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"));
        }
示例#4
0
        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);
            }
        }
        //[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());
        }
示例#6
0
        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());
        }