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