Search in sources :

Example 21 with GitLogEntry

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);
}
Also used : GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry)

Example 22 with GitLogEntry

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");
}
Also used : Path(java.nio.file.Path) Writer(com.google.copybara.Destination.Writer) GitTestUtil(com.google.copybara.testing.git.GitTestUtil) Iterables(com.google.common.collect.Iterables) DummyRevision(com.google.copybara.testing.DummyRevision) Assert.assertThrows(org.junit.Assert.assertThrows) TransformResult(com.google.copybara.TransformResult) DummyOrigin(com.google.copybara.testing.DummyOrigin) RunWith(org.junit.runner.RunWith) RepoException(com.google.copybara.exception.RepoException) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) MessageType(com.google.copybara.util.console.Message.MessageType) WriterContext(com.google.copybara.WriterContext) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Strategy(com.google.copybara.git.GitIntegrateChanges.Strategy) GitTestUtil.getGitEnv(com.google.copybara.testing.git.GitTestUtil.getGitEnv) CannotResolveRevisionException(com.google.copybara.exception.CannotResolveRevisionException) GitTesting(com.google.copybara.git.testing.GitTesting) TransformResults(com.google.copybara.testing.TransformResults) Path(java.nio.file.Path) Before(org.junit.Before) DEFAULT_TIMEOUT(com.google.copybara.util.CommandRunner.DEFAULT_TIMEOUT) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) ValidationException(com.google.copybara.exception.ValidationException) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) DestinationStatus(com.google.copybara.Destination.DestinationStatus) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Glob(com.google.copybara.util.Glob) FAKE_MERGE_AND_INCLUDE_FILES(com.google.copybara.git.GitIntegrateChanges.Strategy.FAKE_MERGE_AND_INCLUDE_FILES) Optional(java.util.Optional) INCLUDE_FILES(com.google.copybara.git.GitIntegrateChanges.Strategy.INCLUDE_FILES) FAKE_MERGE(com.google.copybara.git.GitIntegrateChanges.Strategy.FAKE_MERGE) Joiner(com.google.common.base.Joiner) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) Test(org.junit.Test)

Example 23 with GitLogEntry

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()));
}
Also used : Path(java.nio.file.Path) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) Test(org.junit.Test)

Example 24 with GitLogEntry

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()));
}
Also used : Path(java.nio.file.Path) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) Test(org.junit.Test)

Example 25 with GitLogEntry

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()));
}
Also used : Path(java.nio.file.Path) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) Test(org.junit.Test)

Aggregations

GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)29 Test (org.junit.Test)19 Path (java.nio.file.Path)12 DummyRevision (com.google.copybara.testing.DummyRevision)9 ImmutableList (com.google.common.collect.ImmutableList)6 WriterContext (com.google.copybara.WriterContext)6 Iterables (com.google.common.collect.Iterables)5 CannotResolveRevisionException (com.google.copybara.exception.CannotResolveRevisionException)5 RepoException (com.google.copybara.exception.RepoException)5 ValidationException (com.google.copybara.exception.ValidationException)5 Glob (com.google.copybara.util.Glob)5 IOException (java.io.IOException)5 Optional (java.util.Optional)5 Joiner (com.google.common.base.Joiner)4 DestinationStatus (com.google.copybara.Destination.DestinationStatus)4 Author (com.google.copybara.authoring.Author)4 Lists (com.google.common.collect.Lists)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)3 Writer (com.google.copybara.Destination.Writer)3