use of com.google.copybara.WriterContext in project copybara by google.
the class GerritDestinationTest method testGerritSubmit.
@Test
public void testGerritSubmit() throws Exception {
options.gerrit.gerritChangeId = null;
fetch = "master";
pushToRefsFor = "master";
writeFile(workdir, "file", "some content");
options.setForce(true);
url = "https://localhost:33333/foo/bar";
GitRepository repo = gitUtil.mockRemoteRepo("localhost:33333/foo/bar");
mockNoChangesFound();
DummyRevision originRef = new DummyRevision("origin_ref");
GerritDestination destination = destination("submit = True");
Glob glob = Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths);
WriterContext writerContext = new WriterContext("GerritDestinationTest", "test", false, originRef, Glob.ALL_FILES.roots());
List<DestinationEffect> result = destination.newWriter(writerContext).write(TransformResults.of(workdir, originRef).withSummary("Test message").withIdentity(originRef.asString()), glob, console);
assertThat(result).hasSize(1);
assertThat(result.get(0).getErrors()).isEmpty();
String changeId = lastCommitChangeIdLineForRef("origin_ref", repo, "refs/heads/master").replace("Change-Id: ", "").trim();
assertThat(changeId).isNotNull();
assertThat(destination.getType()).isEqualTo("git.destination");
assertThat(destination.describe(glob).get("fetch")).isEqualTo(ImmutableSet.of("master"));
assertThat(destination.describe(glob).get("push")).isEqualTo(ImmutableSet.of("master"));
}
use of com.google.copybara.WriterContext in project copybara by google.
the class GerritDestinationTest method gerritSubmit_alreadySubmittable.
@Test
public void gerritSubmit_alreadySubmittable() throws Exception {
options.gerrit.gerritChangeId = null;
fetch = "master";
writeFile(workdir, "file", "some content");
url = BASE_URL + "/foo/bar";
repoGitDir = gitUtil.mockRemoteRepo("user:SECRET@copybara-not-real.com/foo/bar").getGitDir();
gitUtil.mockApi(eq("GET"), startsWith(BASE_URL + "/changes/"), mockResponse("[" + "{" + " change_id : \"Iaaaaaaaaaabbbbbbbbbbccccccccccdddddddddd\"," + " status : \"NEW\"," + " submittable : true" + "}]"));
AtomicBoolean submitCalled = new AtomicBoolean(false);
gitUtil.mockApi(eq("POST"), matches(BASE_URL + "/changes/.*/revisions/.*/review"), mockResponseWithStatus("Change should not be voted on", 500));
gitUtil.mockApi(eq("POST"), matches(BASE_URL + "/changes/.*/submit"), mockResponseAndValidateRequest("{" + " change_id : \"Iaaaaaaaaaabbbbbbbbbbccccccccccdddddddddd\"," + " status : \"submitted\"" + "}", new MockRequestAssertion("Always true with side-effect", s -> {
submitCalled.set(true);
return true;
})));
options.setForce(true);
DummyRevision originRef = new DummyRevision("origin_ref");
GerritDestination destination = destination("submit = True", "gerrit_submit = True");
Glob glob = Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths);
WriterContext writerContext = new WriterContext("GerritDestinationTest", "test", false, originRef, Glob.ALL_FILES.roots());
List<DestinationEffect> result = destination.newWriter(writerContext).write(TransformResults.of(workdir, originRef).withSummary("Test message").withIdentity(originRef.asString()), glob, console);
assertThat(submitCalled.get()).isTrue();
assertThat(result).hasSize(1);
assertThat(result.get(0).getErrors()).isEmpty();
}
use of com.google.copybara.WriterContext in project copybara by google.
the class GerritDestinationTest method testDisableNotifications.
@Test
public void testDisableNotifications() throws Exception {
pushToRefsFor = "master";
fetch = "master";
options.setForce(true);
Path workTree = Files.createTempDirectory("populate");
GitRepository repo = repo().withWorkTree(workTree);
writeFile(workTree, "file.txt", "some content");
repo.add().all().run();
repo.simpleCommand("commit", "-m", "Some commit");
writeFile(workdir, "file.txt", "new content");
DummyRevision originRef = new DummyRevision("origin_ref");
WriterContext writerContext = new WriterContext("GerritDestination", "TEST", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
ImmutableList<DestinationEffect> result = destination("submit = False", "notify = 'NONE'").newWriter(writerContext).write(TransformResults.of(workdir, originRef).withIdentity(originRef.asString()), Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths), console);
assertThat(result).hasSize(1);
assertThatGerritCheckout(repo(), "refs/for/master%notify=NONE,hashtag=copybara_id_origin_ref_commiter@email").containsFile("file.txt", "new content").containsNoMoreFiles();
}
use of com.google.copybara.WriterContext 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.WriterContext 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");
}
Aggregations