Search in sources :

Example 1 with HgCommand

use of com.thoughtworks.go.domain.materials.mercurial.HgCommand in project gocd by gocd.

the class HgMaterialTest method shouldRefreshWorkingDirectoryIfUsernameInDefaultRemoteUrlIsDifferentFromOneInMaterialUrl.

@Test
void shouldRefreshWorkingDirectoryIfUsernameInDefaultRemoteUrlIsDifferentFromOneInMaterialUrl() throws Exception {
    final HgMaterial material = new HgMaterial("http://some_new_user:pwd@domain:9999/path", null);
    final HgCommand hgCommand = mock(HgCommand.class);
    final ConsoleResult consoleResult = mock(ConsoleResult.class);
    when(consoleResult.outputAsString()).thenReturn("http://user:pwd@domain:9999/path");
    when(hgCommand.workingRepositoryUrl()).thenReturn(consoleResult);
    assertThat((Boolean) ReflectionUtil.invoke(material, "isRepositoryChanged", hgCommand)).isTrue();
}
Also used : HgCommand(com.thoughtworks.go.domain.materials.mercurial.HgCommand) Test(org.junit.jupiter.api.Test)

Example 2 with HgCommand

use of com.thoughtworks.go.domain.materials.mercurial.HgCommand in project gocd by gocd.

the class HgMaterial method hg.

private HgCommand hg(File workingFolder, ConsoleOutputStreamConsumer outputStreamConsumer) throws Exception {
    UrlArgument urlArgument = new HgUrlArgument(urlForCommandLine());
    HgCommand hgCommand = new HgCommand(getFingerprint(), workingFolder, getBranch(), urlArgument.forCommandLine(), secrets());
    if (!isHgRepository(workingFolder) || isRepositoryChanged(hgCommand)) {
        LOGGER.debug("Invalid hg working copy or repository changed. Delete folder: {}", workingFolder);
        FileUtils.deleteQuietly(workingFolder);
    }
    if (!workingFolder.exists()) {
        createParentFolderIfNotExist(workingFolder);
        int returnValue = hgCommand.clone(outputStreamConsumer, urlArgument);
        bombIfFailedToRunCommandLine(returnValue, "Failed to run hg clone command");
    }
    return hgCommand;
}
Also used : HgCommand(com.thoughtworks.go.domain.materials.mercurial.HgCommand)

Example 3 with HgCommand

use of com.thoughtworks.go.domain.materials.mercurial.HgCommand in project gocd by gocd.

the class HgMaterial method hg.

private HgCommand hg(File workingFolder, ProcessOutputStreamConsumer outputStreamConsumer) throws Exception {
    HgCommand hgCommand = new HgCommand(getFingerprint(), workingFolder, getBranch(), getUrl(), secrets());
    if (!isHgRepository(workingFolder) || isRepositoryChanged(hgCommand)) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Invalid hg working copy or repository changed. Delete folder: " + workingFolder);
        }
        FileUtil.deleteFolder(workingFolder);
    }
    if (!workingFolder.exists()) {
        createParentFolderIfNotExist(workingFolder);
        int returnValue = hgCommand.clone(outputStreamConsumer, url);
        bombIfFailedToRunCommandLine(returnValue, "Failed to run hg clone command");
    }
    return hgCommand;
}
Also used : HgCommand(com.thoughtworks.go.domain.materials.mercurial.HgCommand)

Example 4 with HgCommand

use of com.thoughtworks.go.domain.materials.mercurial.HgCommand in project gocd by gocd.

the class HgMaterialTest method shouldNotRefreshWorkingFolderWhenFileProtocolIsUsed.

@Test
public void shouldNotRefreshWorkingFolderWhenFileProtocolIsUsed() throws Exception {
    new HgCommand(null, workingFolder, "default", hgTestRepo.url().forCommandline(), null).clone(inMemoryConsumer(), hgTestRepo.url());
    File testFile = createNewFileInWorkingFolder();
    hgMaterial = MaterialsMother.hgMaterial("file://" + hgTestRepo.projectRepositoryUrl());
    updateMaterial(hgMaterial, new StringRevision("0"));
    String workingUrl = new HgCommand(null, workingFolder, "default", hgTestRepo.url().forCommandline(), null).workingRepositoryUrl().outputAsString();
    assertThat(workingUrl, is(hgTestRepo.projectRepositoryUrl()));
    assertThat(testFile.exists(), is(true));
}
Also used : HgCommand(com.thoughtworks.go.domain.materials.mercurial.HgCommand) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) StringContains.containsString(org.hamcrest.core.StringContains.containsString) File(java.io.File) Test(org.junit.Test)

Example 5 with HgCommand

use of com.thoughtworks.go.domain.materials.mercurial.HgCommand in project gocd by gocd.

the class HgMaterialTest method shouldRefreshWorkingFolderWhenRepositoryChanged.

@Test
public void shouldRefreshWorkingFolderWhenRepositoryChanged() throws Exception {
    new HgCommand(null, workingFolder, "default", hgTestRepo.url().forCommandline(), null).clone(inMemoryConsumer(), hgTestRepo.url());
    File testFile = createNewFileInWorkingFolder();
    HgTestRepo hgTestRepo2 = new HgTestRepo("hgTestRepo2", temporaryFolder);
    hgMaterial = MaterialsMother.hgMaterial(hgTestRepo2.projectRepositoryUrl());
    hgMaterial.latestModification(workingFolder, new TestSubprocessExecutionContext());
    String workingUrl = new HgCommand(null, workingFolder, "default", hgTestRepo.url().forCommandline(), null).workingRepositoryUrl().outputAsString();
    assertThat(workingUrl, is(hgTestRepo2.projectRepositoryUrl()));
    assertThat(testFile.exists(), is(false));
}
Also used : HgCommand(com.thoughtworks.go.domain.materials.mercurial.HgCommand) StringContains.containsString(org.hamcrest.core.StringContains.containsString) HgTestRepo(com.thoughtworks.go.helper.HgTestRepo) File(java.io.File) Test(org.junit.Test)

Aggregations

HgCommand (com.thoughtworks.go.domain.materials.mercurial.HgCommand)7 File (java.io.File)2 StringContains.containsString (org.hamcrest.core.StringContains.containsString)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 StringRevision (com.thoughtworks.go.domain.materials.mercurial.StringRevision)1 HgTestRepo (com.thoughtworks.go.helper.HgTestRepo)1 URISyntaxException (java.net.URISyntaxException)1