Search in sources :

Example 1 with GitSubmoduleRepos

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

the class GitMaterialTest method shouldRemoveSubmoduleFolderFromWorkingDirWhenSubmoduleIsRemovedFromRepo.

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

Example 2 with GitSubmoduleRepos

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

the class MaterialDatabaseGitWithSubmodulesUpdaterTest method repo.

protected TestRepo repo() throws Exception {
    GitSubmoduleRepos testRepoWithExternal = new GitSubmoduleRepos(temporaryFolder);
    testRepoWithExternal.addSubmodule("submodule-1", "sub1");
    return testRepoWithExternal;
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos)

Example 3 with GitSubmoduleRepos

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

the class GitCommandTest method shouldCleanUnversionedFilesInsideSubmodulesBeforeUpdating.

@Test
public void shouldCleanUnversionedFilesInsideSubmodulesBeforeUpdating() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
    String submoduleDirectoryName = "local-submodule";
    submoduleRepos.addSubmodule(SUBMODULE, submoduleDirectoryName);
    File cloneDirectory = createTempWorkingDirectory();
    GitCommand clonedCopy = new GitCommand(null, cloneDirectory, GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null);
    InMemoryStreamConsumer outputStreamConsumer = inMemoryConsumer();
    // Clone repository without submodules
    clonedCopy.clone(outputStreamConsumer, submoduleRepos.mainRepo().getUrl());
    // Pull submodules to working copy - Pipeline counter 1
    clonedCopy.resetWorkingDir(outputStreamConsumer, new StringRevision("HEAD"));
    File unversionedFile = new File(new File(cloneDirectory, submoduleDirectoryName), "unversioned_file.txt");
    FileUtils.writeStringToFile(unversionedFile, "this is an unversioned file. lets see you deleting me.. come on.. I dare you!!!!", UTF_8);
    // Should clean unversioned file on next fetch - Pipeline counter 2
    clonedCopy.resetWorkingDir(outputStreamConsumer, new StringRevision("HEAD"));
    assertThat(unversionedFile.exists(), is(false));
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) StringContains.containsString(org.hamcrest.core.StringContains.containsString) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) File(java.io.File) Test(org.junit.Test)

Example 4 with GitSubmoduleRepos

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

the class GitCommandTest method shouldRemoveChangesToModifiedFilesInsideSubmodulesBeforeUpdating.

@Test
public void shouldRemoveChangesToModifiedFilesInsideSubmodulesBeforeUpdating() throws Exception {
    InMemoryStreamConsumer outputStreamConsumer = inMemoryConsumer();
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
    String submoduleDirectoryName = "local-submodule";
    File cloneDirectory = createTempWorkingDirectory();
    File remoteSubmoduleLocation = submoduleRepos.addSubmodule(SUBMODULE, submoduleDirectoryName);
    /* Simulate an agent checkout of code. */
    GitCommand clonedCopy = new GitCommand(null, cloneDirectory, GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null);
    clonedCopy.clone(outputStreamConsumer, submoduleRepos.mainRepo().getUrl());
    clonedCopy.resetWorkingDir(outputStreamConsumer, new StringRevision("HEAD"));
    /* Simulate a local modification of file inside submodule, on agent side. */
    File fileInSubmodule = allFilesIn(new File(cloneDirectory, 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");
    /* Simulate start of a new build on agent. */
    clonedCopy.fetch(outputStreamConsumer);
    clonedCopy.resetWorkingDir(outputStreamConsumer, new StringRevision(modifications.get(0).getRevision()));
    assertThat(FileUtils.readFileToString(fileInSubmodule, UTF_8), is("NEW CONTENT OF FILE"));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) File(java.io.File) Test(org.junit.Test)

Example 5 with GitSubmoduleRepos

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

the class GitCommandTest method shouldAllowSubmoduleUrlstoChange.

@Test
public void shouldAllowSubmoduleUrlstoChange() throws Exception {
    InMemoryStreamConsumer outputStreamConsumer = inMemoryConsumer();
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
    String submoduleDirectoryName = "local-submodule";
    File cloneDirectory = createTempWorkingDirectory();
    File remoteSubmoduleLocation = submoduleRepos.addSubmodule(SUBMODULE, submoduleDirectoryName);
    GitCommand clonedCopy = new GitCommand(null, cloneDirectory, GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null);
    clonedCopy.clone(outputStreamConsumer, submoduleRepos.mainRepo().getUrl());
    clonedCopy.fetchAndResetToHead(outputStreamConsumer);
    submoduleRepos.changeSubmoduleUrl(submoduleDirectoryName);
    clonedCopy.fetchAndResetToHead(outputStreamConsumer);
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) File(java.io.File) Test(org.junit.Test)

Aggregations

GitSubmoduleRepos (com.thoughtworks.go.helper.GitSubmoduleRepos)17 Test (org.junit.Test)16 StringRevision (com.thoughtworks.go.domain.materials.mercurial.StringRevision)11 File (java.io.File)9 InMemoryStreamConsumer (com.thoughtworks.go.util.command.InMemoryStreamConsumer)8 StringContains.containsString (org.hamcrest.core.StringContains.containsString)7 RevisionContext (com.thoughtworks.go.domain.materials.RevisionContext)6 ModifiedFile (com.thoughtworks.go.domain.materials.ModifiedFile)4 RegexMatcher (com.thoughtworks.go.matchers.RegexMatcher)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 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 RandomAccessFile (java.io.RandomAccessFile)1 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)1 ExpectedException (org.junit.rules.ExpectedException)1