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");
}
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");
}
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();
}
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");
}
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");
}
Aggregations