use of com.google.copybara.config.Migration in project copybara by google.
the class WorkflowTest method testNonReversibleInsideGit.
@Test
public void testNonReversibleInsideGit() throws IOException, ValidationException, RepoException {
origin.singleFileChange(0, "one commit", "foo.txt", "foo\nbar\n");
GitRepository.newRepo(/*verbose*/
true, workdir, getGitEnv()).init();
Path subdir = Files.createDirectory(workdir.resolve("subdir"));
String config = "" + "core.workflow(\n" + " name = 'default',\n" + " origin = testing.origin(),\n" + " destination = testing.destination(),\n" + " transformations = [core.replace('foo', 'bar')],\n" + " authoring = " + authoring + ",\n" + " reversible_check = True,\n" + ")\n";
Migration workflow = loadConfig(config).getMigration("default");
ValidationException e = assertThrows(ValidationException.class, () -> workflow.run(subdir, ImmutableList.of()));
assertThat(e).hasMessageThat().contains("Cannot use 'reversible_check = True' because Copybara temporary directory");
}
use of com.google.copybara.config.Migration in project copybara by google.
the class WorkflowTest method testFirstParentAlreadyImportedInNoFirstParent.
/**
* Regression that test that when using git.origin with first_parent = False, if the first parent
* of a merge is already imported and the merge is a no-op, we detect the import as
* EmptyChangeException instead of detecting the non-first parent as the change to import
*/
@Test
public void testFirstParentAlreadyImportedInNoFirstParent() throws Exception {
Path originPath = Files.createTempDirectory("origin");
GitRepository origin = GitRepository.newRepo(/*verbose*/
true, originPath, getGitEnv()).init();
String primaryBranch = origin.getPrimaryBranch();
options.setForce(false);
options.workflowOptions.initHistory = true;
String config = "core.workflow(" + " name = 'default'," + " origin = git.origin( url = 'file://" + origin.getWorkTree() + "',\n" + " ref = '" + primaryBranch + "',\n" + " first_parent = False),\n" + " destination = testing.destination(),\n" + " authoring = " + authoring + "," + " origin_files = glob(['included/**'])," + " mode = '" + WorkflowMode.SQUASH + "'," + ")\n";
Migration workflow = loadConfig(config).getMigration("default");
addGitFile(originPath, origin, "included/foo.txt", "");
GitRevision lastRev = commit(origin, "last_rev");
workflow.run(workdir, ImmutableList.of());
assertThat(destination.processed.get(0).getOriginRef()).isEqualTo(lastRev);
origin.simpleCommand("checkout", "-b", "feature");
addGitFile(originPath, origin, "included/foo.txt", "SHOULD NOT BE IN PRIMARY");
commit(origin, "feature commit");
origin.simpleCommand("revert", "HEAD");
addGitFile(originPath, origin, "excluded/bar.txt", "don't migrate!");
commit(origin, "excluded commit");
origin.simpleCommand("checkout", primaryBranch);
origin.simpleCommand("merge", "-s", "ours", "feature");
EmptyChangeException e = assertThrows(EmptyChangeException.class, () -> workflow.run(workdir, ImmutableList.of()));
assertThat(e).hasMessageThat().matches("No changes from " + lastRev.getSha1() + " up to .* match any origin_files.*");
}
use of com.google.copybara.config.Migration in project copybara by google.
the class WorkflowTest method testHgOriginNoFlags.
@Test
public void testHgOriginNoFlags() throws Exception {
Path originPath = Files.createTempDirectory("origin");
HgRepository origin = new HgRepository(originPath, true, DEFAULT_TIMEOUT).init();
Path destinationPath = Files.createTempDirectory("destination");
GitRepository destRepo = GitRepository.newBareRepo(destinationPath, getGitEnv(), true, DEFAULT_TIMEOUT, /*noVerify=*/
false).init();
String primaryBranch = destRepo.getPrimaryBranch();
String config = "core.workflow(" + " name = 'default'," + " origin = hg.origin( url = 'file://" + origin.getHgDir() + "', ref = 'default'),\n" + " destination = git.destination(" + " url = 'file://" + destRepo.getGitDir() + "',\n" + " fetch = '" + primaryBranch + "',\n" + " push = '" + primaryBranch + "',\n" + " ),\n" + " authoring = " + authoring + "," + " mode = '" + WorkflowMode.ITERATIVE + "'," + ")\n";
Files.write(originPath.resolve("foo.txt"), "testing foo".getBytes(UTF_8));
origin.hg(originPath, "add", "foo.txt");
origin.hg(originPath, "commit", "-m", "add foo");
options.gitDestination.committerName = "Foo";
options.gitDestination.committerEmail = "foo@foo.com";
options.setWorkdirToRealTempDir();
options.setHomeDir(Files.createTempDirectory("home").toString());
options.workflowOptions.initHistory = true;
Migration workflow = loadConfig(config).getMigration("default");
workflow.run(workdir, ImmutableList.of());
ImmutableList<GitLogEntry> destCommits = destRepo.log("HEAD").run();
assertThat(destCommits).hasSize(1);
assertThat(destCommits.get(0).getBody()).contains("add foo");
Files.write(originPath.resolve("bar.txt"), "testing bar".getBytes(UTF_8));
origin.hg(originPath, "add", "bar.txt");
origin.hg(originPath, "commit", "-m", "add bar");
options.workflowOptions.initHistory = false;
workflow.run(workdir, ImmutableList.of());
destCommits = destRepo.log("HEAD").run();
assertThat(destCommits).hasSize(2);
assertThat(destCommits.get(0).getBody()).contains("add bar");
assertThat(destCommits.get(1).getBody()).contains("add foo");
}
use of com.google.copybara.config.Migration in project copybara by google.
the class GitMirrorTest method testDefaultMirrorInStarlark.
/**
* Starlark version of our native git.mirror implementation
*/
@Test
public void testDefaultMirrorInStarlark() throws Exception {
String cfg = "" + NATIVE_MIRROR_IN_STARLARK_FUNC + "git.mirror(" + " name = 'default'," + " origin = 'file://" + originRepo.getGitDir().toAbsolutePath() + "'," + " destination = 'file://" + destRepo.getGitDir().toAbsolutePath() + "'," + " refspecs = [" + String.format(" 'refs/heads/%s:refs/heads/origin_primary'", primaryBranch) + " ]," + " actions = [native_mirror(refspec = {" + String.format(" 'refs/heads/%s':'refs/heads/origin_primary'", primaryBranch) + "})]," + ")";
Migration mirror = loadMigration(cfg, "default");
mirror.run(workdir, ImmutableList.of());
String origPrimary = originRepo.git(originRepo.getGitDir(), "show-ref", primaryBranch, "-s").getStdout();
String dest = destRepo.git(destRepo.getGitDir(), "show-ref", "origin_primary", "-s").getStdout();
assertThat(dest).isEqualTo(origPrimary);
checkRefDoesntExist("refs/heads/" + primaryBranch);
checkRefDoesntExist("refs/heads/other");
}
use of com.google.copybara.config.Migration in project copybara by google.
the class GitMirrorTest method testMerge.
@Test
public void testMerge() throws Exception {
Migration mirror = mergeInit();
GitLogEntry destChange = repoChange(destRepo, "some_file", "Content", "destination only");
GitLogEntry originChange = repoChange(originRepo, "some_other_file", "Content", "new change");
mirror.run(workdir, ImmutableList.of());
GitLogEntry merge = lastChange(destRepo, primaryBranch);
// It is a merge
assertThat(merge.getParents()).containsExactly(destChange.getCommit(), originChange.getCommit());
// OSS branch is updated with origin version.
assertThat(lastChange(destRepo, "oss").getCommit()).isEqualTo(originChange.getCommit());
}
Aggregations