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();
}
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;
}
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;
}
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));
}
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));
}
Aggregations