Search in sources :

Example 46 with DummyRevision

use of com.google.copybara.testing.DummyRevision in project copybara by google.

the class GitDestinationTest method processCommitDeletesAndAddsFiles.

@Test
public void processCommitDeletesAndAddsFiles() throws Exception {
    fetch = "pullFromBar";
    push = "pushToFoo";
    Files.write(workdir.resolve("deleted_file"), "deleted content".getBytes(UTF_8));
    process(firstCommitWriter(), new DummyRevision("origin_ref"));
    git("--git-dir", repoGitDir.toString(), "branch", "pullFromBar", "pushToFoo");
    workdir = Files.createTempDirectory("workdir2");
    Files.write(workdir.resolve("1.txt"), "content 1".getBytes(UTF_8));
    Files.createDirectories(workdir.resolve("subdir"));
    Files.write(workdir.resolve("subdir/2.txt"), "content 2".getBytes(UTF_8));
    process(newWriter(), new DummyRevision("origin_ref"));
    // Make sure original file was deleted.
    assertFilesInDir(2, "pushToFoo", ".");
    assertFilesInDir(1, "pushToFoo", "subdir");
    // Make sure both commits are present.
    assertCommitCount(2, "pushToFoo");
    assertCommitHasOrigin("pushToFoo", "origin_ref");
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 47 with DummyRevision

use of com.google.copybara.testing.DummyRevision in project copybara by google.

the class GitDestinationTest method testChangeDescriptionEmpty_setRevId.

@Test
public void testChangeDescriptionEmpty_setRevId() 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(ValidationException.class, () -> writer.write(TransformResults.of(workdir, originRef).withSummary("").withLabelFinder(s -> ImmutableList.of()).withSetRevId(false), Glob.createGlob(ImmutableList.of("**"), ImmutableList.of("test.txt")), console));
    assertThat(e).hasMessageThat().contains("Change description is empty");
}
Also used : Path(java.nio.file.Path) TransformResult(com.google.copybara.TransformResult) ZonedDateTime(java.time.ZonedDateTime) DestinationEffect(com.google.copybara.DestinationEffect) WriterContext(com.google.copybara.WriterContext) VisitResult(com.google.copybara.ChangeVisitable.VisitResult) Author(com.google.copybara.authoring.Author) GitTestUtil.getGitEnv(com.google.copybara.testing.git.GitTestUtil.getGitEnv) Change(com.google.copybara.Change) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) ZoneOffset(java.time.ZoneOffset) GitTesting(com.google.copybara.git.testing.GitTesting) Path(java.nio.file.Path) DEFAULT_TIMEOUT(com.google.copybara.util.CommandRunner.DEFAULT_TIMEOUT) Type(com.google.copybara.DestinationEffect.Type) ImmutableSet(com.google.common.collect.ImmutableSet) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) ImmutableMap(com.google.common.collect.ImmutableMap) GitTesting.assertThatCheckout(com.google.copybara.git.testing.GitTesting.assertThatCheckout) DestinationStatus(com.google.copybara.Destination.DestinationStatus) Instant(java.time.Instant) ZoneId(java.time.ZoneId) CheckerException(com.google.copybara.checks.CheckerException) List(java.util.List) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) Writer(com.google.copybara.Destination.Writer) DummyRevision(com.google.copybara.testing.DummyRevision) Assert.assertThrows(org.junit.Assert.assertThrows) 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) Changes(com.google.copybara.Changes) ChangeMessage(com.google.copybara.ChangeMessage) ArrayList(java.util.ArrayList) Truth(com.google.common.truth.Truth) ImmutableList(com.google.common.collect.ImmutableList) TransformResults(com.google.copybara.testing.TransformResults) CommandOutput(com.google.copybara.util.CommandOutput) Nullable(javax.annotation.Nullable) Before(org.junit.Before) Functions(com.google.common.base.Functions) ChangeMessage.parseMessage(com.google.copybara.ChangeMessage.parseMessage) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) DummyChecker(com.google.copybara.testing.DummyChecker) ValidationException(com.google.copybara.exception.ValidationException) UserPassword(com.google.copybara.git.GitCredential.UserPassword) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Maps(com.google.common.collect.Maps) Baseline(com.google.copybara.Origin.Baseline) Glob(com.google.copybara.util.Glob) TransformWorks(com.google.copybara.testing.TransformWorks) GitTestUtil.writeFile(com.google.copybara.testing.git.GitTestUtil.writeFile) WriterContext(com.google.copybara.WriterContext) ValidationException(com.google.copybara.exception.ValidationException) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 48 with DummyRevision

use of com.google.copybara.testing.DummyRevision in project copybara by google.

the class GitDestinationTest method excludedDestinationPathsIgnoreGitTreeFiles.

@Test
public void excludedDestinationPathsIgnoreGitTreeFiles() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    Path scratchTree = Files.createTempDirectory("GitDestinationTest-scratchTree");
    Files.createDirectories(scratchTree.resolve("notgit"));
    Files.write(scratchTree.resolve("notgit/HEAD"), "some content".getBytes(UTF_8));
    repo().withWorkTree(scratchTree).add().files("notgit/HEAD").run();
    repo().withWorkTree(scratchTree).simpleCommand("commit", "-m", "message");
    Files.write(workdir.resolve("normal_file.txt"), "some more content".getBytes(UTF_8));
    // Make sure this glob does not cause .git/HEAD to be added.
    destinationFiles = Glob.createGlob(ImmutableList.of("**"), ImmutableList.of("**/HEAD"));
    process(newWriter(), new DummyRevision("ref"));
    assertThatCheckout(repo(), primaryBranch).containsFile("notgit/HEAD", "some content").containsFile("normal_file.txt", "some more content").containsNoMoreFiles();
}
Also used : Path(java.nio.file.Path) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 49 with DummyRevision

use of com.google.copybara.testing.DummyRevision in project copybara by google.

the class GitDestinationTest method testTagWithLabel.

@Test
public void testTagWithLabel() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    tagName = "tag_${my_tag}";
    tagMsg = "msg_${my_msg}";
    Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
    options.setForce(true);
    WriterContext writerContext = new WriterContext("piper_to_github", "TEST", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
    evalDestination().newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("ref1")), destinationFiles, console);
    options.setForce(false);
    Files.write(workdir.resolve("test.txt"), "some content 2".getBytes(UTF_8));
    evalDestinationWithTag(tagMsg).newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("ref2")).withLabelFinder(Functions.forMap(ImmutableMap.of("my_tag", ImmutableList.of("12345"), "my_msg", ImmutableList.of("2345")))), destinationFiles, console);
    CommandOutput commandOutput = repo().simpleCommand("tag", "-n9");
    assertThat(commandOutput.getStdout()).matches(".*tag_12345.*msg_2345\n");
}
Also used : WriterContext(com.google.copybara.WriterContext) CommandOutput(com.google.copybara.util.CommandOutput) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 50 with DummyRevision

use of com.google.copybara.testing.DummyRevision in project copybara by google.

the class GitDestinationTest method getDestinationStatusForFakeMergeAndNonEmptyRoots.

/**
 * regression to ensure we don't do:
 *
 *     git log -- some_path
 *
 *  This doesn't work for fake merges as the merge is not shown when a path is passed even
 *  with -m.
 */
@Test
public void getDestinationStatusForFakeMergeAndNonEmptyRoots() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    Files.createDirectories(workdir.resolve("dir"));
    Files.write(workdir.resolve("dir/file"), "".getBytes(UTF_8));
    GitRepository repo = repo().withWorkTree(workdir);
    repo.add().files("dir/file").run();
    repo.simpleCommand("commit", "-m", "first commit");
    repo.simpleCommand("branch", "foo");
    Files.write(workdir.resolve("dir/file"), "other".getBytes(UTF_8));
    repo.add().files("dir/file").run();
    repo.simpleCommand("commit", "-m", "first commit");
    repo.forceCheckout("foo");
    Files.write(workdir.resolve("dir/file"), "feature".getBytes(UTF_8));
    repo.add().files("dir/file").run();
    repo.simpleCommand("commit", "-m", "first commit");
    repo.forceCheckout(primaryBranch);
    // Fake merge
    repo.simpleCommand("merge", "-Xours", "foo", "-m", "A fake merge\n\n" + DummyOrigin.LABEL_NAME + ": foo");
    destinationFiles = Glob.createGlob(ImmutableList.of("dir/**"));
    WriterContext writerContext = new WriterContext("piper_to_github", "TEST", false, new DummyRevision("feature"), Glob.ALL_FILES.roots());
    DestinationStatus status = destination().newWriter(writerContext).getDestinationStatus(destinationFiles, DummyOrigin.LABEL_NAME);
    assertThat(status).isNotNull();
    assertThat(status.getBaseline()).isEqualTo("foo");
}
Also used : WriterContext(com.google.copybara.WriterContext) DestinationStatus(com.google.copybara.Destination.DestinationStatus) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Aggregations

DummyRevision (com.google.copybara.testing.DummyRevision)144 Test (org.junit.Test)124 WriterContext (com.google.copybara.WriterContext)58 Path (java.nio.file.Path)29 DestinationEffect (com.google.copybara.DestinationEffect)28 Author (com.google.copybara.authoring.Author)21 Changes (com.google.copybara.Changes)19 Glob (com.google.copybara.util.Glob)19 ValidationException (com.google.copybara.exception.ValidationException)18 IOException (java.io.IOException)16 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)14 TransformResult (com.google.copybara.TransformResult)13 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)13 ZonedDateTime (java.time.ZonedDateTime)13 TransformWork (com.google.copybara.TransformWork)12 RepoException (com.google.copybara.exception.RepoException)12 CheckerException (com.google.copybara.checks.CheckerException)11 DummyChecker (com.google.copybara.testing.DummyChecker)11 FileSubjects.assertThatPath (com.google.copybara.testing.FileSubjects.assertThatPath)11 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)11