Search in sources :

Example 26 with DummyRevision

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

the class GitDestinationTest method processWithBaselineNotFound.

@Test
public void processWithBaselineNotFound() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    DummyRevision ref = new DummyRevision("origin_ref");
    Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
    process(firstCommitWriter(), ref);
    Files.write(workdir.resolve("test.txt"), "more content".getBytes(UTF_8));
    RepoException thrown = assertThrows(RepoException.class, () -> processWithBaseline(newWriter(), destinationFiles, ref, "I_dont_exist"));
    assertThat(thrown).hasMessageThat().contains("Cannot find baseline 'I_dont_exist' from fetch reference '");
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) RepoException(com.google.copybara.exception.RepoException) Test(org.junit.Test)

Example 27 with DummyRevision

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

the class GitDestinationTest method testTagWithExistingAndWarningMsg.

@Test
public void testTagWithExistingAndWarningMsg() throws Exception {
    WriterContext writerContext = setUpForTestingTag();
    // push existing tag with tagMsg
    evalDestinationWithTag(tagMsg).newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("ref2")), destinationFiles, console);
    CommandOutput commandOutput = repo().simpleCommand("tag", "-n9");
    console.assertThat().onceInLog(MessageType.WARNING, ".*Tag " + tagName + " exists. To overwrite it please use flag '--git-tag-overwrite'.*");
    assertThat(commandOutput.getStdout()).matches(".*" + tagName + ".*test summary\n" + ".*\n" + ".*DummyOrigin-RevId: ref2\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 28 with DummyRevision

use of com.google.copybara.testing.DummyRevision 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;
}
Also used : Path(java.nio.file.Path) DummyRevision(com.google.copybara.testing.DummyRevision) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry)

Example 29 with DummyRevision

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

the class GitDestinationTest method testTagWithMsg.

@Test
public void testTagWithMsg() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    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);
    Changes changes = new Changes(ImmutableList.of(new Change<>(new DummyRevision("ref2"), new Author("foo", "foo@foo.com"), "message", ZonedDateTime.now(ZoneOffset.UTC), ImmutableListMultimap.of("my_label", "12345"))), ImmutableList.of());
    Files.write(workdir.resolve("test.txt"), "some content 2".getBytes(UTF_8));
    evalDestinationWithTag(tagMsg).newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("ref2")).withChanges(changes), destinationFiles, console);
    CommandOutput commandOutput = repo().simpleCommand("tag", "-n9");
    assertThat(commandOutput.getStdout()).matches(".*test_v1.*" + tagMsg + "\n");
}
Also used : Changes(com.google.copybara.Changes) WriterContext(com.google.copybara.WriterContext) CommandOutput(com.google.copybara.util.CommandOutput) DummyRevision(com.google.copybara.testing.DummyRevision) Author(com.google.copybara.authoring.Author) Change(com.google.copybara.Change) Test(org.junit.Test)

Example 30 with DummyRevision

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

the class GitDestinationTest method process_autoDetect.

@Test
public void process_autoDetect() throws Exception {
    push = primaryBranch;
    fetch = primaryBranch;
    Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
    process(firstCommitWriter(), new DummyRevision("origin_ref"));
    Files.write(workdir.resolve("test.txt"), "other content".getBytes(UTF_8));
    primaryBranchMigration = "True";
    push = "master";
    fetch = "master";
    // primaryBranch = repo().getPrimaryBranch(url);
    process(newWriter(), new DummyRevision("process_autoDetect"));
    // Make sure commit adds new text
    String showResult = git("--git-dir", repoGitDir.toString(), "show", primaryBranch);
    assertThat(showResult).contains("other content");
    assertFilesInDir(1, primaryBranch, ".");
    assertCommitCount(2, primaryBranch);
    assertCommitHasOrigin(primaryBranch, "process_autoDetect");
}
Also used : 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