Search in sources :

Example 11 with GitSubmoduleRepos

use of com.thoughtworks.go.helper.GitSubmoduleRepos in project gocd by gocd.

the class GitMaterialUpdaterTest method shouldRemoveChangesToModifiedFilesInsideSubmodulesBeforeUpdating.

@Test
public void shouldRemoveChangesToModifiedFilesInsideSubmodulesBeforeUpdating() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
    String submoduleDirectoryName = "local-submodule";
    File remoteSubmoduleLocation = submoduleRepos.addSubmodule(SUBMODULE, submoduleDirectoryName);
    GitMaterial material = new GitMaterial(submoduleRepos.projectRepositoryUrl(), true);
    updateTo(material, new RevisionContext(new StringRevision("origin/HEAD")), JobResult.Passed);
    /* Simulate a local modification of file inside submodule, on agent side. */
    File fileInSubmodule = allFilesIn(new File(workingDir, submoduleDirectoryName), "file-").get(0);
    FileUtils.writeStringToFile(fileInSubmodule, "Some other new content.", UTF_8);
    /* Commit a change to the file on the repo. */
    List<Modification> modifications = submoduleRepos.modifyOneFileInSubmoduleAndUpdateMainRepo(remoteSubmoduleLocation, submoduleDirectoryName, fileInSubmodule.getName(), "NEW CONTENT OF FILE");
    updateTo(material, new RevisionContext(new StringRevision(modifications.get(0).getRevision())), JobResult.Passed);
    assertThat(FileUtils.readFileToString(fileInSubmodule, UTF_8), Matchers.is("NEW CONTENT OF FILE"));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) Test(org.junit.Test)

Example 12 with GitSubmoduleRepos

use of com.thoughtworks.go.helper.GitSubmoduleRepos in project gocd by gocd.

the class GitMaterialUpdaterTest method shouldAllowSubmoduleUrlstoChange.

@Test
public void shouldAllowSubmoduleUrlstoChange() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
    String submoduleDirectoryName = "local-submodule";
    submoduleRepos.addSubmodule(SUBMODULE, submoduleDirectoryName);
    GitMaterial material = new GitMaterial(submoduleRepos.projectRepositoryUrl(), true);
    updateTo(material, new RevisionContext(new StringRevision("origin/HEAD")), JobResult.Passed);
    submoduleRepos.changeSubmoduleUrl(submoduleDirectoryName);
    updateTo(material, new RevisionContext(new StringRevision("origin/HEAD")), JobResult.Passed);
    assertThat(console.output(), containsString("Synchronizing submodule url for 'local-submodule'"));
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 13 with GitSubmoduleRepos

use of com.thoughtworks.go.helper.GitSubmoduleRepos in project gocd by gocd.

the class GitMaterialUpdaterTest method shouldCleanUnversionedFilesInsideSubmodulesBeforeUpdating.

@Test
public void shouldCleanUnversionedFilesInsideSubmodulesBeforeUpdating() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
    String submoduleDirectoryName = "local-submodule";
    submoduleRepos.addSubmodule(SUBMODULE, submoduleDirectoryName);
    GitMaterial material = new GitMaterial(submoduleRepos.projectRepositoryUrl(), true);
    updateTo(material, new RevisionContext(new StringRevision("origin/HEAD")), JobResult.Passed);
    File unversionedFile = new File(new File(workingDir, submoduleDirectoryName), "unversioned_file.txt");
    FileUtils.writeStringToFile(unversionedFile, "this is an unversioned file. lets see you deleting me.. come on.. I dare you!!!!", UTF_8);
    updateTo(material, new RevisionContext(new StringRevision("origin/HEAD")), JobResult.Passed);
    assertThat(unversionedFile.exists(), Matchers.is(false));
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) Test(org.junit.Test)

Example 14 with GitSubmoduleRepos

use of com.thoughtworks.go.helper.GitSubmoduleRepos in project gocd by gocd.

the class GitMaterialUpdaterTest method shouldRemoveSubmoduleFolderFromWorkingDirWhenSubmoduleIsRemovedFromRepo.

@Test
public void shouldRemoveSubmoduleFolderFromWorkingDirWhenSubmoduleIsRemovedFromRepo() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
    submoduleRepos.addSubmodule(SUBMODULE, "sub1");
    GitMaterial gitMaterial = new GitMaterial(submoduleRepos.mainRepo().getUrl(), true);
    StringRevision revision = new StringRevision("origin/master");
    updateTo(gitMaterial, new RevisionContext(revision), JobResult.Passed);
    assertThat(new File(workingDir, "sub1"), exists());
    submoduleRepos.removeSubmodule("sub1");
    updateTo(gitMaterial, new RevisionContext(revision), JobResult.Passed);
    assertThat(new File(workingDir, "sub1"), not(exists()));
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) File(java.io.File) Test(org.junit.Test)

Example 15 with GitSubmoduleRepos

use of com.thoughtworks.go.helper.GitSubmoduleRepos in project gocd by gocd.

the class GitCommandTest method shouldBombForResetWorkingDirWhenSubmoduleUpdateFails.

@Test
public void shouldBombForResetWorkingDirWhenSubmoduleUpdateFails() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
    File submoduleFolder = submoduleRepos.addSubmodule(SUBMODULE, "sub1");
    GitCommand gitWithSubmodule = new GitCommand(null, createTempWorkingDirectory(), GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null);
    gitWithSubmodule.clone(inMemoryConsumer(), submoduleRepos.mainRepo().getUrl());
    FileUtils.deleteDirectory(submoduleFolder);
    assertThat(submoduleFolder.exists(), is(false));
    try {
        gitWithSubmodule.resetWorkingDir(new SysOutStreamConsumer(), new StringRevision("HEAD"));
        fail("should have failed for non 0 return code");
    } catch (Exception e) {
        assertThat(e.getMessage(), new RegexMatcher(String.format("[Cc]lone of '%s' into submodule path '((.*)[\\/])?sub1' failed", Pattern.quote(submoduleFolder.getAbsolutePath()))));
    }
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) SysOutStreamConsumer(com.thoughtworks.go.mail.SysOutStreamConsumer) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) RegexMatcher(com.thoughtworks.go.matchers.RegexMatcher) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) File(java.io.File) CommandLineException(com.thoughtworks.go.util.command.CommandLineException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

GitSubmoduleRepos (com.thoughtworks.go.helper.GitSubmoduleRepos)21 Test (org.junit.Test)20 File (java.io.File)13 StringRevision (com.thoughtworks.go.domain.materials.mercurial.StringRevision)11 InMemoryStreamConsumer (com.thoughtworks.go.util.command.InMemoryStreamConsumer)8 StringContains.containsString (org.hamcrest.core.StringContains.containsString)7 RevisionContext (com.thoughtworks.go.domain.materials.RevisionContext)6 RandomAccessFile (java.io.RandomAccessFile)5 ModifiedFile (com.thoughtworks.go.domain.materials.ModifiedFile)4 RegexMatcher (com.thoughtworks.go.matchers.RegexMatcher)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Materials (com.thoughtworks.go.config.materials.Materials)2 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)2 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)2 Modification (com.thoughtworks.go.domain.materials.Modification)2 Matcher (java.util.regex.Matcher)2 SysOutStreamConsumer (com.thoughtworks.go.mail.SysOutStreamConsumer)1 CommandLineException (com.thoughtworks.go.util.command.CommandLineException)1 IOException (java.io.IOException)1 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)1