use of com.google.copybara.git.GitRepository in project copybara by google.
the class WorkflowTest method testToFolderFlag.
@Test
public void testToFolderFlag() throws Exception {
Path originPath = Files.createTempDirectory("origin");
Path destinationPath = Files.createTempDirectory("destination");
GitRepository origin = GitRepository.newRepo(/*verbose*/
true, originPath, getGitEnv()).init();
GitRepository destination = GitRepository.newRepo(/*verbose*/
true, destinationPath, getGitEnv()).init();
String primaryBranch = origin.getPrimaryBranch();
String config = "core.workflow(" + " name = '" + "default" + "'," + String.format(" origin = git.origin( url = 'file://%s', ref = '%s'),\n", origin.getWorkTree(), primaryBranch) + " destination = git.destination(" + " url = 'file://" + destination.getWorkTree() + "',\n" + " ),\n" + " authoring = " + authoring + "," + " mode = '" + WorkflowMode.ITERATIVE + "'," + ")\n";
Files.write(originPath.resolve("foo.txt"), "change".getBytes(UTF_8));
origin.add().files("foo.txt").run();
origin.commit("Foo <foo@bara.com>", ZonedDateTime.now(ZoneId.systemDefault()), "not important");
String firstCommit = origin.parseRef("HEAD");
options.workflowOptions.toFolder = true;
options.general.squash = true;
Path localFolder = Files.createTempDirectory("local_folder");
options.folderDestination.localFolder = localFolder.toString();
options.setWorkdirToRealTempDir();
// Pass custom HOME directory so that we run an hermetic test and we
// can add custom configuration to $HOME/.gitconfig.
options.setEnvironment(GitTestUtil.getGitEnv().getEnvironment());
options.setHomeDir(Files.createTempDirectory("home").toString());
options.gitDestination.committerName = "Foo";
options.gitDestination.committerEmail = "foo@foo.com";
options.workflowOptions.checkLastRevState = true;
loadConfig(config).getMigration("default").run(Files.createTempDirectory("checkout"), ImmutableList.of());
FileSubjects.assertThatPath(localFolder).containsFile("foo.txt", "change").containsNoMoreFiles();
assertThrows(CannotResolveRevisionException.class, () -> destination.resolveReference("HEAD"));
}
use of com.google.copybara.git.GitRepository in project copybara by google.
the class WorkflowTest method changeRequestEmptyChanges.
@Test
public void changeRequestEmptyChanges() throws Exception {
Path originPath = Files.createTempDirectory("origin");
GitRepository origin = GitRepository.newRepo(/*verbose*/
true, originPath, getGitEnv()).init();
String primaryBranch = origin.getPrimaryBranch();
String config = "def after_all(ctx):\n" + " ctx.destination.message('after_all '" + " + str([e.type + ' '+ e.summary for e in ctx.effects]))\n" + "\n" + "core.workflow(" + " name = 'default'," + String.format(" origin = git.origin( url = 'file://%s', ref = '%s'),\n", origin.getWorkTree(), primaryBranch) + " destination = testing.destination(),\n" + " authoring = " + authoring + "," + " origin_files = glob(['included/**'])," + " mode = '" + WorkflowMode.CHANGE_REQUEST + "'," + " after_workflow = [after_all]" + ")\n";
Migration workflow = loadConfig(config).getMigration("default");
Files.createDirectory(originPath.resolve("included"));
Files.write(originPath.resolve("included/foo.txt"), "a".getBytes(UTF_8));
origin.add().files("included/foo.txt").run();
origin.commit("Foo <foo@bara.com>", ZonedDateTime.now(ZoneId.systemDefault()), "the baseline\n\n" + destination.getLabelNameWhenOrigin() + "=42");
Files.createDirectory(originPath.resolve("excluded"));
Files.write(originPath.resolve("excluded/foo.txt"), "a".getBytes(UTF_8));
origin.add().files("excluded/foo.txt").run();
origin.commit("Foo <foo@bara.com>", ZonedDateTime.now(ZoneId.systemDefault()), "head change");
EmptyChangeException thrown = assertThrows(EmptyChangeException.class, () -> workflow.run(workdir, ImmutableList.of()));
assertThat(thrown).hasMessageThat().contains("doesn't include any change for origin_files = glob(include = [\"included/**\"])");
assertThat(destination.getEndpoint().messages).hasSize(1);
assertThat(destination.getEndpoint().messages.get(0)).containsMatch(".*didn't affect any destination file.*");
}
use of com.google.copybara.git.GitRepository in project copybara by google.
the class WorkflowTest method givenLastRevFlagInfoCommandUsesIt.
@Test
@SuppressWarnings("unchecked")
public void givenLastRevFlagInfoCommandUsesIt() throws Exception {
Path originPath = Files.createTempDirectory("origin");
Path destinationPath = Files.createTempDirectory("destination");
GitRepository origin = GitRepository.newRepo(/*verbose*/
true, originPath, getGitEnv()).init();
GitRepository destination = GitRepository.newRepo(/*verbose*/
true, destinationPath, getGitEnv()).init();
String primaryBranch = origin.getPrimaryBranch();
String config = "core.workflow(" + " name = '" + "default" + "'," + String.format(" origin = git.origin( url = 'file://%s', ref = '%s'),\n", origin.getWorkTree(), primaryBranch) + " destination = git.destination(" + " url = 'file://" + destination.getWorkTree() + "',\n" + " ),\n" + " authoring = " + authoring + "," + " mode = '" + WorkflowMode.ITERATIVE + "'," + ")\n";
Files.write(originPath.resolve("foo.txt"), "not important".getBytes(UTF_8));
origin.add().files("foo.txt").run();
origin.commit("Foo <foo@bara.com>", ZonedDateTime.now(ZoneId.systemDefault()), "not important");
String firstCommit = origin.parseRef("HEAD");
Files.write(destinationPath.resolve("foo.txt"), "not important".getBytes(UTF_8));
destination.add().files("foo.txt").run();
destination.commit("Foo <foo@bara.com>", ZonedDateTime.now(ZoneId.systemDefault()), "not important");
Files.write(originPath.resolve("foo.txt"), "foo".getBytes(UTF_8));
origin.add().files("foo.txt").run();
origin.commit("Foo <foo@bara.com>", ZonedDateTime.now(ZoneId.systemDefault()), "change1");
options.setWorkdirToRealTempDir();
// Pass custom HOME directory so that we run an hermetic test and we
// can add custom configuration to $HOME/.gitconfig.
options.setEnvironment(GitTestUtil.getGitEnv().getEnvironment());
options.setHomeDir(Files.createTempDirectory("home").toString());
options.gitDestination.committerName = "Foo";
options.gitDestination.committerEmail = "foo@foo.com";
options.workflowOptions.checkLastRevState = true;
options.setLastRevision(firstCommit);
Info<Revision> info = (Info<Revision>) loadConfig(config).getMigration("default").getInfo();
verifyInfo(info, "change1\n");
assertThat(info.originDescription().get("url")).containsExactly("file://" + origin.getWorkTree());
assertThat(info.destinationDescription().get("url")).containsExactly("file://" + destination.getWorkTree());
}
use of com.google.copybara.git.GitRepository in project copybara by google.
the class WorkflowTest method testTestWorkflowWithDiffInOriginAndRespondNo.
@Test
public void testTestWorkflowWithDiffInOriginAndRespondNo() throws Exception {
GitRepository remote = GitRepository.newBareRepo(Files.createTempDirectory("gitdir"), getGitEnv(), /*verbose=*/
true, DEFAULT_TIMEOUT, /*noVerify=*/
false).withWorkTree(workdir);
remote.init();
String primaryBranch = remote.getPrimaryBranch();
Files.write(workdir.resolve("foo.txt"), new byte[] {});
remote.add().files("foo.txt").run();
remote.simpleCommand("commit", "foo.txt", "-m", "message_a");
GitRevision lastRev = remote.resolveReference(primaryBranch);
Files.write(workdir.resolve("bar.txt"), "change content".getBytes(UTF_8));
remote.add().files("bar.txt").run();
remote.simpleCommand("commit", "bar.txt", "-m", "message_s");
TestingConsole testingConsole = new TestingConsole().respondNo();
options.workflowOptions.lastRevision = lastRev.getSha1();
options.setWorkdirToRealTempDir().setConsole(testingConsole).setHomeDir(StandardSystemProperty.USER_HOME.value());
Workflow<?, ?> workflow = (Workflow<?, ?>) new SkylarkTestExecutor(options).loadConfig("core.workflow(\n" + " name = 'foo',\n" + " origin = git.origin(url='" + remote.getGitDir() + "'),\n" + " destination = folder.destination(),\n" + " mode = 'ITERATIVE',\n" + " authoring = " + authoring + ",\n" + " transformations = [metadata.replace_message(''),],\n" + ")\n").getMigration("foo");
workflow.getWorkflowOptions().diffInOrigin = true;
ChangeRejectedException e = assertThrows(ChangeRejectedException.class, () -> workflow.run(workdir, ImmutableList.of(primaryBranch)));
assertThat(e.getMessage()).contains("User aborted execution: did not confirm diff in origin changes.");
}
use of com.google.copybara.git.GitRepository in project copybara by google.
the class WorkflowTest method testWorkflowWithEmptyDiffInOrigin.
@Test
public void testWorkflowWithEmptyDiffInOrigin() throws Exception {
GitRepository remote = GitRepository.newBareRepo(Files.createTempDirectory("gitdir"), getGitEnv(), /*verbose=*/
true, DEFAULT_TIMEOUT, /*noVerify=*/
false).withWorkTree(workdir);
remote.init();
String primaryBranch = remote.getPrimaryBranch();
Files.write(workdir.resolve("foo.txt"), new byte[] {});
remote.add().files("foo.txt").run();
remote.simpleCommand("commit", "foo.txt", "-m", "message_a");
GitRevision lastRev = remote.resolveReference(primaryBranch);
Files.write(workdir.resolve("foo.txt"), "change content".getBytes(UTF_8));
remote.add().files("foo.txt").run();
remote.simpleCommand("commit", "foo.txt", "-m", "message_a");
Files.write(workdir.resolve("foo.txt"), new byte[] {});
remote.add().files("foo.txt").run();
remote.simpleCommand("commit", "foo.txt", "-m", "message_a");
TestingConsole testingConsole = new TestingConsole().respondYes();
options.workflowOptions.lastRevision = lastRev.getSha1();
options.general.force = false;
options.setWorkdirToRealTempDir().setConsole(testingConsole).setHomeDir(StandardSystemProperty.USER_HOME.value());
Workflow<?, ?> workflow = (Workflow<?, ?>) new SkylarkTestExecutor(options).loadConfig("core.workflow(\n" + " name = 'foo',\n" + String.format(" origin = git.origin(url='%s', ref='%s'),\n", remote.getGitDir(), primaryBranch) + " destination = folder.destination(),\n" + " mode = 'ITERATIVE',\n" + " authoring = " + authoring + ",\n" + " transformations = [metadata.replace_message(''),],\n" + ")\n").getMigration("foo");
workflow.getWorkflowOptions().diffInOrigin = true;
workflow.run(workdir, ImmutableList.of(primaryBranch));
testingConsole.assertThat().onceInLog(MessageType.WARNING, ".*No difference at diff_in_origin.*");
}
Aggregations