use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GitDestinationIntegrateTest method testDestinationStatus.
/**
* Checks that we can correctly read destination status (last fake merge commit created) after
* an integration.
*
* <p>Don't change the file paths or contents of this test. It needs to be like this to generate
* an empty diff with the feature branch (pure fake-merge).
*/
@Test
public void testDestinationStatus() throws ValidationException, IOException, RepoException {
destinationFiles = Glob.createGlob(ImmutableList.of("foo/**"));
Path gitDir = Files.createTempDirectory("gitdir");
Path repoPath = Files.createTempDirectory("workdir");
GitRepository repo = GitRepository.newBareRepo(gitDir, getGitEnv(), /*verbose=*/
true, DEFAULT_TIMEOUT, /*noVerify=*/
false).init().withWorkTree(repoPath);
singleChange(repoPath, repo, "base.txt", "first change");
repo.simpleCommand("branch", "feature1");
repo.forceCheckout("feature1");
GitRevision feature = singleChange(repoPath, repo, "foo/a", "Feature 1 change");
repo.forceCheckout(primaryBranch);
// Just so that the migration doesn't fail since the git repo is a non-bare repo.
repo.forceCheckout("feature1");
GitDestination destination = destination("url = 'file://" + repo.getGitDir() + "'", String.format("push='%s'", primaryBranch));
migrateOriginChange(destination, "Test change\n" + "\n" + GitModule.DEFAULT_INTEGRATE_LABEL + "=file://" + repo.getGitDir().toString() + " feature1\n", "foo/a", "", "the_rev");
GitLogEntry featureMerge = getLastMigratedChange(primaryBranch, repo);
assertThat(featureMerge.getBody()).isEqualTo("Merge of " + feature.getSha1() + "\n" + "\n" + DummyOrigin.LABEL_NAME + ": the_rev\n");
WriterContext writerContext = new WriterContext("piper_to_github", "TEST", false, new DummyRevision("feature"), Glob.ALL_FILES.roots());
DestinationStatus destinationStatus = destination.newWriter(writerContext).getDestinationStatus(destinationFiles, DummyOrigin.LABEL_NAME);
assertWithMessage(gitDir.toString()).that(destinationStatus.getBaseline()).isEqualTo("the_rev");
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GitDestinationTest method canExcludeDestinationPathFromWorkflow.
@Test
public void canExcludeDestinationPathFromWorkflow() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
Path scratchTree = Files.createTempDirectory("GitDestinationTest-scratchTree");
Files.write(scratchTree.resolve("excluded.txt"), "some content".getBytes(UTF_8));
repo().withWorkTree(scratchTree).add().files("excluded.txt").run();
repo().withWorkTree(scratchTree).simpleCommand("commit", "-m", "message");
Files.write(workdir.resolve("normal_file.txt"), "some more content".getBytes(UTF_8));
destinationFiles = Glob.createGlob(ImmutableList.of("**"), ImmutableList.of("excluded.txt"));
process(newWriter(), new DummyRevision("ref"));
assertThatCheckout(repo(), primaryBranch).containsFile("excluded.txt", "some content").containsFile("normal_file.txt", "some more content").containsNoMoreFiles();
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GitDestinationTest method testChangeDescriptionEmpty_empty_commit.
@Test
public void testChangeDescriptionEmpty_empty_commit() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
Path scratchTree = Files.createTempDirectory("GitDestinationTest-testLocalRepo");
Files.write(scratchTree.resolve("foo"), "foo\n".getBytes(UTF_8));
repo().withWorkTree(scratchTree).add().force().files("foo").run();
repo().withWorkTree(scratchTree).simpleCommand("commit", "-a", "-m", "change");
DummyRevision originRef = new DummyRevision("origin_ref");
WriterContext writerContext = new WriterContext("GitDestinationTest", "test", true, new DummyRevision("origin_ref1"), Glob.ALL_FILES.roots());
Writer<GitRevision> writer = destination().newWriter(writerContext);
ValidationException e = assertThrows(EmptyChangeException.class, () -> writer.write(TransformResults.of(workdir, originRef).withSummary("").withLabelFinder(s -> ImmutableList.of()).withSetRevId(false), Glob.createGlob(ImmutableList.of("nothing_to_be_found"), ImmutableList.of("test.txt")), console));
assertThat(e).hasMessageThat().contains("Migration of the revision resulted in an empty change");
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GitDestinationTest method processWithBaseline.
@Test
public void processWithBaseline() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
DummyRevision ref = new DummyRevision("origin_ref");
Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
Files.write(workdir.resolve("excluded"), "some content".getBytes(UTF_8));
process(firstCommitWriter(), ref);
String firstCommit = repo().parseRef("HEAD");
Files.write(workdir.resolve("test.txt"), "new content".getBytes(UTF_8));
process(newWriter(), ref);
// Lets exclude now 'excluded' so that we check that the rebase correctly ignores
// the missing file (IOW, it doesn't delete the file in the commit).
destinationFiles = Glob.createGlob(ImmutableList.of("**"), ImmutableList.of("excluded"));
Files.delete(workdir.resolve("excluded"));
Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
Files.write(workdir.resolve("other.txt"), "other file".getBytes(UTF_8));
processWithBaseline(newWriter(), destinationFiles, ref, firstCommit);
assertThatCheckout(repo(), primaryBranch).containsFile("test.txt", "new content").containsFile("other.txt", "other file").containsFile("excluded", "some content").containsNoMoreFiles();
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GitDestinationTest method processWithBaseline_noRebase.
@Test
public void processWithBaseline_noRebase() throws Exception {
options.gitDestination.noRebase = true;
options.setForce(true);
fetch = primaryBranch;
push = primaryBranch;
DummyRevision ref = new DummyRevision("origin_ref");
Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
Files.write(workdir.resolve("excluded"), "some content".getBytes(UTF_8));
process(firstCommitWriter(), ref);
String firstCommit = repo().parseRef(primaryBranch);
Files.write(workdir.resolve("test.txt"), "new content".getBytes(UTF_8));
process(newWriter(), ref);
// Lets exclude now 'excluded' so that we check that the rebase correctly ignores
// the missing file (IOW, it doesn't delete the file in the commit).
destinationFiles = Glob.createGlob(ImmutableList.of("**"), ImmutableList.of("excluded"));
Files.delete(workdir.resolve("excluded"));
Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
Files.write(workdir.resolve("other.txt"), "other file".getBytes(UTF_8));
push = "refs/heads/my_branch";
processWithBaseline(newWriter(), destinationFiles, ref, firstCommit);
assertThatCheckout(repo(), "refs/heads/my_branch").containsFile("test.txt", "some content").containsFile("other.txt", "other file").containsFile("excluded", "some content").containsNoMoreFiles();
}
Aggregations