use of com.google.copybara.git.GitRepository.GitLogEntry in project copybara by google.
the class GitTesting method assertAuthorTimestamp.
/**
* Asserts that the author timestamp of a certain commit equals {@code timestamp}.
*/
public static void assertAuthorTimestamp(GitRepository repo, String commitRef, ZonedDateTime timestamp) throws RepoException {
GitLogEntry commit = Iterables.getOnlyElement(repo.log(commitRef).withLimit(1).run());
assertThat(commit.getAuthorDate()).isEquivalentAccordingToCompareTo(timestamp);
}
use of com.google.copybara.git.GitRepository.GitLogEntry in project copybara by google.
the class GitDestinationIntegrateTest method testGerritSemiFakeMerge.
@Test
public void testGerritSemiFakeMerge() throws ValidationException, IOException, RepoException {
Path workTree = Files.createTempDirectory("test");
GitRepository repo = gitUtil.mockRemoteRepo("example.com/gerrit").withWorkTree(workTree);
String label = new GerritIntegrateLabel(repo, options.general, "https://example.com/gerrit", 1020, 1, CHANGE_ID).toString();
assertThat(label).isEqualTo("gerrit https://example.com/gerrit 1020 Patch Set 1 " + CHANGE_ID);
GitRevision firstChange = singleChange(workTree, repo, "ignore_me", "Feature1 change");
GitRevision secondChange = singleChange(workTree, repo, "ignore_me2", "Feature2 change");
GitTestUtil.createFakeGerritNodeDbMeta(repo, 1020, CHANGE_ID);
repo.simpleCommand("update-ref", "refs/changes/20/1020/1", firstChange.getSha1());
repo.simpleCommand("update-ref", "refs/changes/20/1020/2", secondChange.getSha1());
GitDestination destination = destinationWithDefaultIntegrates();
GitLogEntry previous = createBaseDestinationChange(destination);
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", "").containsNoMoreFiles();
GitLogEntry merge = getLastMigratedChange(primaryBranch);
assertThat(merge.getBody()).isEqualTo("Merge Gerrit change 1020 Patch Set 1\n" + "\n" + "DummyOrigin-RevId: test\n" + "Change-Id: " + CHANGE_ID + "\n");
assertThat(Lists.transform(merge.getParents(), GitRevision::getSha1)).isEqualTo(Lists.newArrayList(previous.getCommit().getSha1(), firstChange.getSha1()));
assertThat(console.getMessages().stream().filter(e -> e.getType() == MessageType.WARNING).findAny().get().getText()).contains("Change 1020 has more patch sets after Patch Set 1." + " Latest is Patch Set 2. Not all changes might be migrated");
}
use of com.google.copybara.git.GitRepository.GitLogEntry in project copybara by google.
the class GitDestinationIntegrateTest method testIncludeFiles.
@Test
public void testIncludeFiles() throws ValidationException, IOException, RepoException {
Path repoPath = Files.createTempDirectory("test");
GitRepository repo = GitRepository.newRepo(/*verbose*/
true, repoPath, getGitEnv()).init();
singleChange(repoPath, repo, "ignore_me", "Feature1 change");
repo.simpleCommand("branch", "feature1");
singleChange(repoPath, repo, "ignore_me2", "Feature2 change");
repo.simpleCommand("branch", "feature2");
GitDestination destination = destination(INCLUDE_FILES);
migrateOriginChange(destination, "Base change\n", "not important");
GitLogEntry previous = getLastMigratedChange(primaryBranch);
migrateOriginChange(destination, "Test change\n" + "\n" + GitModule.DEFAULT_INTEGRATE_LABEL + "=file://" + repo.getWorkTree().toString() + " feature1\n" + GitModule.DEFAULT_INTEGRATE_LABEL + "=file://" + repo.getWorkTree().toString() + " feature2\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 afterChange = getLastMigratedChange(primaryBranch);
assertThat(afterChange.getBody()).isEqualTo("Test change\n" + "\n" + DummyOrigin.LABEL_NAME + ": test\n");
assertThat(Lists.transform(afterChange.getParents(), GitRevision::getSha1)).isEqualTo(Lists.newArrayList(previous.getCommit().getSha1()));
}
use of com.google.copybara.git.GitRepository.GitLogEntry in project copybara by google.
the class GitDestinationIntegrateTest method testIncludeFilesOutdatedBranch.
@Test
public void testIncludeFilesOutdatedBranch() throws Exception {
Path repoPath = Files.createTempDirectory("test");
GitRepository repo = repo().withWorkTree(repoPath);
singleChange(repoPath, repo, "ignore_base.txt", "original", "base change");
repo.simpleCommand("branch", "feature");
singleChange(repoPath, repo, "ignore_base.txt", "modified", "more changes");
repo.forceCheckout("feature");
singleChange(repoPath, repo, "ignore_but_changed.txt", "feature", "external change");
singleChange(repoPath, repo, "feature_file.txt", "feature", "internal change");
GitRevision prHead = repo.resolveReference("HEAD");
GitDestination destination = destination(FAKE_MERGE_AND_INCLUDE_FILES);
migrateOriginChange(destination, "Base change\n", "test.txt", "not important", "test");
GitLogEntry previous = getLastMigratedChange(primaryBranch);
migrateOriginChange(destination, "Test change\n" + "\n" + GitModule.DEFAULT_INTEGRATE_LABEL + "=file://" + repo.getGitDir().toString() + " feature\n", "feature_file.txt", "feature modified", "test");
// Make sure commit adds new text
String showResult = git("--git-dir", repoGitDir.toString(), "show", primaryBranch);
assertThat(showResult).contains("Merge of ");
GitTesting.assertThatCheckout(repo, primaryBranch).containsFile("test.txt", "not important").containsFile("ignore_base.txt", "modified").containsFile("ignore_but_changed.txt", "feature").containsFile("feature_file.txt", "feature modified").containsNoMoreFiles();
GitLogEntry afterChange = getLastMigratedChange(primaryBranch);
assertThat(afterChange.getBody()).isEqualTo("Merge of " + prHead.getSha1() + "\n" + "\n" + DummyOrigin.LABEL_NAME + ": test\n");
assertThat(Lists.transform(afterChange.getParents(), GitRevision::getSha1)).isEqualTo(Lists.newArrayList(previous.getCommit().getSha1(), prHead.getSha1()));
}
use of com.google.copybara.git.GitRepository.GitLogEntry in project copybara by google.
the class GitDestinationIntegrateTest method testFakeMerge.
@Test
public void testFakeMerge() throws ValidationException, IOException, RepoException {
Path repoPath = Files.createTempDirectory("test");
GitRepository repo = GitRepository.newRepo(/*verbose*/
true, repoPath, getGitEnv()).init();
GitRevision feature1 = singleChange(repoPath, repo, "ignore_me", "Feature1 change");
repo.simpleCommand("branch", "feature1");
GitRevision feature2 = singleChange(repoPath, repo, "ignore_me2", "Feature2 change");
repo.simpleCommand("branch", "feature2");
GitDestination destination = destination(FAKE_MERGE);
migrateOriginChange(destination, "Base change\n", "not important");
GitLogEntry previous = getLastMigratedChange(primaryBranch);
migrateOriginChange(destination, "Test change\n" + "\n" + GitModule.DEFAULT_INTEGRATE_LABEL + "=file://" + repo.getWorkTree().toString() + " feature1\n" + GitModule.DEFAULT_INTEGRATE_LABEL + "=file://" + repo.getWorkTree().toString() + " feature2\n", "some content");
// Make sure commit adds new text
String showResult = git("--git-dir", repoGitDir.toString(), "show", primaryBranch + "^1");
assertThat(showResult).contains("some content");
GitTesting.assertThatCheckout(repo(), primaryBranch).containsFile("test.txt", "some content").containsNoMoreFiles();
GitLogEntry feature1Merge = getLastMigratedChange(primaryBranch + "^1");
assertThat(feature1Merge.getBody()).isEqualTo("Merge of " + feature1.getSha1() + "\n" + "\n" + DummyOrigin.LABEL_NAME + ": test\n");
assertThat(Lists.transform(feature1Merge.getParents(), GitRevision::getSha1)).isEqualTo(Lists.newArrayList(previous.getCommit().getSha1(), feature1.getSha1()));
GitLogEntry feature2Merge = getLastMigratedChange(primaryBranch);
assertThat(feature2Merge.getBody()).isEqualTo("Merge of " + feature2.getSha1() + "\n" + "\n" + DummyOrigin.LABEL_NAME + ": test\n");
assertThat(feature1Merge.getFiles()).containsExactly("test.txt");
assertThat(Lists.transform(feature2Merge.getParents(), GitRevision::getSha1)).isEqualTo(Lists.newArrayList(feature1Merge.getCommit().getSha1(), feature2.getSha1()));
}
Aggregations