Search in sources :

Example 6 with StringRevision

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

the class BackupServiceIntegrationTest method shouldBackupConfigRepository.

@Test
public void shouldBackupConfigRepository() throws IOException {
    configHelper.addPipeline("too-unique-to-be-present", "stage-name");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    backupService.startBackup(admin, result);
    assertThat(result.isSuccessful(), is(true));
    assertThat(result.message(localizer), is("Backup completed successfully."));
    File repoZip = backedUpFile("config-repo.zip");
    File repoDir = temporaryFolder.newFolder("expanded-config-repo-backup");
    TestUtils.extractZipToDir(repoZip, repoDir);
    File cloneDir = temporaryFolder.newFolder("cloned-config-repo-backup");
    GitMaterial git = new GitMaterial(repoDir.getAbsolutePath());
    List<Modification> modifications = git.latestModification(cloneDir, subprocessExecutionContext);
    String latestChangeRev = modifications.get(0).getRevision();
    git.checkout(cloneDir, new StringRevision(latestChangeRev), subprocessExecutionContext);
    assertThat(FileUtils.readFileToString(new File(cloneDir, "cruise-config.xml"), UTF_8).indexOf("too-unique-to-be-present"), greaterThan(0));
    StringRevision revision = new StringRevision(latestChangeRev + "~1");
    git.updateTo(new InMemoryStreamConsumer(), cloneDir, new RevisionContext(revision), subprocessExecutionContext);
    assertThat(FileUtils.readFileToString(new File(cloneDir, "cruise-config.xml"), UTF_8).indexOf("too-unique-to-be-present"), is(-1));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Modification(com.thoughtworks.go.domain.materials.Modification) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) Test(org.junit.Test)

Example 7 with StringRevision

use of com.thoughtworks.go.domain.materials.mercurial.StringRevision 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 8 with StringRevision

use of com.thoughtworks.go.domain.materials.mercurial.StringRevision 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 9 with StringRevision

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

the class GitCommandTest method shouldReturnNothingForModificationsSinceIfARebasedCommitSHAIsPassed.

@Test
public void shouldReturnNothingForModificationsSinceIfARebasedCommitSHAIsPassed() throws IOException {
    GitTestRepo remoteRepo = new GitTestRepo(temporaryFolder);
    executeOnGitRepo("git", "remote", "rm", "origin");
    executeOnGitRepo("git", "remote", "add", "origin", remoteRepo.projectRepositoryUrl());
    GitCommand command = new GitCommand(remoteRepo.createMaterial().getFingerprint(), gitLocalRepoDir, "master", false, new HashMap<>(), null);
    Modification modification = remoteRepo.addFileAndAmend("foo", "amendedCommit").get(0);
    assertThat(command.modificationsSince(new StringRevision(modification.getRevision())).isEmpty(), is(true));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) Test(org.junit.Test)

Example 10 with StringRevision

use of com.thoughtworks.go.domain.materials.mercurial.StringRevision 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)

Aggregations

StringRevision (com.thoughtworks.go.domain.materials.mercurial.StringRevision)65 Test (org.junit.Test)35 File (java.io.File)31 Test (org.junit.jupiter.api.Test)23 Modification (com.thoughtworks.go.domain.materials.Modification)17 RevisionContext (com.thoughtworks.go.domain.materials.RevisionContext)17 GitSubmoduleRepos (com.thoughtworks.go.helper.GitSubmoduleRepos)11 GitTestRepo (com.thoughtworks.go.domain.materials.git.GitTestRepo)7 InMemoryStreamConsumer (com.thoughtworks.go.util.command.InMemoryStreamConsumer)6 TestSubprocessExecutionContext (com.thoughtworks.go.domain.materials.TestSubprocessExecutionContext)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 StringContains.containsString (org.hamcrest.core.StringContains.containsString)5 RegexMatcher (com.thoughtworks.go.matchers.RegexMatcher)4 ModifiedFile (com.thoughtworks.go.domain.materials.ModifiedFile)3 JsonValue (com.thoughtworks.go.util.JsonValue)3 Changeset (com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Changeset)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)2 DependencyMaterialRevision (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)2 SysOutStreamConsumer (com.thoughtworks.go.mail.SysOutStreamConsumer)2