use of com.google.copybara.git.GitRepository.GitLogEntry in project copybara by google.
the class GitDestinationIntegrateTest method testGitHubSemiFakeMerge.
@Test
public void testGitHubSemiFakeMerge() throws ValidationException, IOException, RepoException {
Path workTree = Files.createTempDirectory("test");
GitRepository repo = gitUtil.mockRemoteRepo("github.com/example/test_repo").withWorkTree(workTree);
GitRevision firstChange = singleChange(workTree, repo, "ignore_me", "Feature1 change");
GitRevision secondChange = singleChange(workTree, repo, "ignore_me2", "Feature2 change");
repo.simpleCommand("update-ref", "refs/pull/20/head", secondChange.getSha1());
GitDestination destination = destinationWithDefaultIntegrates();
GitLogEntry previous = createBaseDestinationChange(destination);
GitHubPrIntegrateLabel labelObj = new GitHubPrIntegrateLabel(repo, options.general, "example/test_repo", 20, "some_user:1234-foo.bar.baz%3", secondChange.getSha1());
assertThat(labelObj.getProjectId()).isEqualTo("example/test_repo");
assertThat(labelObj.getPrNumber()).isEqualTo(20L);
assertThat(labelObj.getOriginBranch()).isEqualTo("some_user:1234-foo.bar.baz%3");
assertThat(labelObj.mergeMessage(ImmutableList.of())).isEqualTo("Merge pull request #20 from some_user:1234-foo.bar.baz%3\n");
String label = labelObj.toString();
assertThat(label).isEqualTo("https://github.com/example/test_repo/pull/20" + " from some_user:1234-foo.bar.baz%3 " + secondChange.getSha1());
migrateOriginChange(destination, "Test change\n" + "\n" + GitModule.DEFAULT_INTEGRATE_LABEL + "=" + label + "\n", "some content");
// Make sure commit adds new text
String showResult = git("--git-dir", repoGitDir.toString(), "show", primaryBranch);
assertThat(showResult).contains("some content");
GitTesting.assertThatCheckout(repo(), primaryBranch).containsFile("test.txt", "some content").containsFile("ignore_me", "").containsFile("ignore_me2", "").containsNoMoreFiles();
GitLogEntry merge = getLastMigratedChange(primaryBranch);
assertThat(merge.getBody()).isEqualTo("Merge pull request #20 from some_user:1234-foo.bar.baz%3\n" + "\n" + "DummyOrigin-RevId: test\n");
assertThat(Lists.transform(merge.getParents(), GitRevision::getSha1)).isEqualTo(Lists.newArrayList(previous.getCommit().getSha1(), secondChange.getSha1()));
assertThat(console.getMessages().stream().filter(e -> e.getType() == MessageType.WARNING).collect(Collectors.toList())).isEmpty();
label = new GitHubPrIntegrateLabel(repo, options.general, "example/test_repo", 20, "some_user:branch", firstChange.getSha1()).toString();
assertThat(label).isEqualTo("https://github.com/example/test_repo/pull/20" + " from some_user:branch " + firstChange.getSha1());
repo().withWorkTree(workTree).simpleCommand("reset", "--hard", "HEAD~1");
migrateOriginChange(destination, "Test change\n" + "\n" + GitModule.DEFAULT_INTEGRATE_LABEL + "=" + label + "\n", "some content");
assertThat(console.getMessages().stream().filter(e -> e.getType() == MessageType.WARNING).findAny().get().getText()).contains("has more changes after " + firstChange.getSha1());
}
use of com.google.copybara.git.GitRepository.GitLogEntry in project copybara by google.
the class GitDestinationIntegrateTest method createBaseDestinationChange.
private GitLogEntry createBaseDestinationChange(GitDestination destination) throws IOException, RepoException, ValidationException {
migrateOriginChange(destination, "Base change\n", "not important");
GitLogEntry previous = getLastMigratedChange(primaryBranch);
console.clearMessages();
return previous;
}
use of com.google.copybara.git.GitRepository.GitLogEntry 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.git.GitRepository.GitLogEntry in project copybara by google.
the class GitDestinationTest method checkLocalRepo.
private GitRepository checkLocalRepo(boolean dryRun) throws Exception {
fetch = primaryBranch;
push = primaryBranch;
Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
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");
String baseline = repo().withWorkTree(scratchTree).simpleCommand("rev-parse", "HEAD").getStdout().trim();
Path localPath = Files.createTempDirectory("local_repo");
options.gitDestination.localRepoPath = localPath.toString();
Writer<GitRevision> writer = newWriter(dryRun);
process(writer, new DummyRevision("origin_ref1"));
// Path localPath = Files.createTempDirectory("local_repo");
GitRepository localRepo = GitRepository.newRepo(/*verbose*/
true, localPath, getEnv()).init();
assertThatCheckout(localRepo, primaryBranch).containsFile("test.txt", "some content").containsNoMoreFiles();
Files.write(workdir.resolve("test.txt"), "another content".getBytes(UTF_8));
processWithBaseline(writer, destinationFiles, new DummyRevision("origin_ref2"), baseline);
assertThatCheckout(localRepo, primaryBranch).containsFile("test.txt", "another content").containsNoMoreFiles();
for (String ref : ImmutableList.of("HEAD", "copybara/local")) {
ImmutableList<GitLogEntry> entries = localRepo.log(ref).run();
assertThat(entries.get(0).getBody()).isEqualTo("" + "test summary\n" + "\n" + "DummyOrigin-RevId: origin_ref2\n");
assertThat(entries.get(1).getBody()).isEqualTo("" + "test summary\n" + "\n" + "DummyOrigin-RevId: origin_ref1\n");
assertThat(entries.get(2).getBody()).isEqualTo("change\n");
}
return localRepo;
}
use of com.google.copybara.git.GitRepository.GitLogEntry in project copybara by google.
the class GitDestinationTest method testCheckerDescription_withDefault.
@Test
public void testCheckerDescription_withDefault() throws Exception {
runDescriptionChecker(new DummyChecker(ImmutableSet.of("BAD"), "Message for failures"));
ImmutableList<GitLogEntry> head = repo().log(primaryBranch).withLimit(1).run();
assertThat(head).isNotEmpty();
assertThat(head.get(0).getBody()).isEqualTo("" + "Message for failures\n" + "\n" + "DummyOrigin-RevId: ref2\n");
assertThat(head.get(0).getAuthor()).isEqualTo(new Author("Dont", "rewri@te.me"));
}
Aggregations