use of com.google.copybara.Destination.DestinationStatus in project copybara by google.
the class GithubPrDestinationTest method testDestinationStatus.
@Test
public void testDestinationStatus() throws ValidationException, IOException, RepoException {
options.githubDestination.createPullRequest = false;
gitApiMockHttpTransport = GitTestUtil.NO_GITHUB_API_CALLS;
GithubPrDestination d = skylark.eval("r", "r = git.github_pr_destination(" + " url = 'https://github.com/foo'" + ")");
Writer<GitRevision> writer = d.newWriter(Glob.ALL_FILES, /*dryRun=*/
false, "feature", /*oldWriter=*/
null);
GitRepository remote = localHubRepo("foo");
addFiles(remote, "master", "first change\n\nDummyOrigin-RevId: baseline", ImmutableMap.<String, String>builder().put("foo.txt", "").build());
DestinationStatus status = writer.getDestinationStatus("DummyOrigin-RevId");
assertThat(status.getBaseline()).isEqualTo("baseline");
assertThat(status.getPendingChanges()).isEmpty();
Files.write(this.workdir.resolve("test.txt"), "some content".getBytes());
writer.write(TransformResults.of(this.workdir, new DummyRevision("one")), console);
// New writer since after changes it keeps state internally for ITERATIVE mode
status = d.newWriter(Glob.ALL_FILES, /*dryRun=*/
false, "feature", /*oldWriter=*/
null).getDestinationStatus("DummyOrigin-RevId");
assertThat(status.getBaseline()).isEqualTo("baseline");
// Not supported for now as we rewrite the whole branch history.
assertThat(status.getPendingChanges()).isEmpty();
}
use of com.google.copybara.Destination.DestinationStatus in project copybara by google.
the class DestinationStatusVisitor method visit.
@Override
public VisitResult visit(Change<? extends Revision> change) {
ImmutableSet<String> changeFiles = change.getChangeFiles();
if (changeFiles != null) {
if (change.getLabels().containsKey(labelName)) {
for (String file : changeFiles) {
if (pathMatcher.matches(Paths.get('/' + file))) {
String lastRev = Iterables.getLast(change.getLabels().get(labelName));
destinationStatus = new DestinationStatus(lastRev, ImmutableList.of());
return VisitResult.TERMINATE;
}
}
}
}
return VisitResult.CONTINUE;
}
use of com.google.copybara.Destination.DestinationStatus in project copybara by google.
the class GitDestinationIntegrateTest method testDestinationStatus.
/**
* Checks that we can correctly read destination status (last fake merge commit created) after
* an integration.
*
* <p>Don't change the file paths or contents of this test. It needs to be like this to generate
* an empty diff with the feature branch (pure fake-merge).
*/
@Test
public void testDestinationStatus() throws ValidationException, IOException, RepoException {
destinationFiles = Glob.createGlob(ImmutableList.of("foo/**"));
Path gitDir = Files.createTempDirectory("gitdir");
Path repoPath = Files.createTempDirectory("workdir");
GitRepository repo = GitRepository.newBareRepo(gitDir, getGitEnv(), /*verbose=*/
true, DEFAULT_TIMEOUT, /*noVerify=*/
false).init().withWorkTree(repoPath);
singleChange(repoPath, repo, "base.txt", "first change");
repo.simpleCommand("branch", "feature1");
repo.forceCheckout("feature1");
GitRevision feature = singleChange(repoPath, repo, "foo/a", "Feature 1 change");
repo.forceCheckout(primaryBranch);
// Just so that the migration doesn't fail since the git repo is a non-bare repo.
repo.forceCheckout("feature1");
GitDestination destination = destination("url = 'file://" + repo.getGitDir() + "'", String.format("push='%s'", primaryBranch));
migrateOriginChange(destination, "Test change\n" + "\n" + GitModule.DEFAULT_INTEGRATE_LABEL + "=file://" + repo.getGitDir().toString() + " feature1\n", "foo/a", "", "the_rev");
GitLogEntry featureMerge = getLastMigratedChange(primaryBranch, repo);
assertThat(featureMerge.getBody()).isEqualTo("Merge of " + feature.getSha1() + "\n" + "\n" + DummyOrigin.LABEL_NAME + ": the_rev\n");
WriterContext writerContext = new WriterContext("piper_to_github", "TEST", false, new DummyRevision("feature"), Glob.ALL_FILES.roots());
DestinationStatus destinationStatus = destination.newWriter(writerContext).getDestinationStatus(destinationFiles, DummyOrigin.LABEL_NAME);
assertWithMessage(gitDir.toString()).that(destinationStatus.getBaseline()).isEqualTo("the_rev");
}
use of com.google.copybara.Destination.DestinationStatus 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");
}
use of com.google.copybara.Destination.DestinationStatus in project copybara by google.
the class GitHubPrDestinationTest method testDestinationStatus.
@Test
public void testDestinationStatus() throws ValidationException, IOException, RepoException {
options.githubDestination.createPullRequest = false;
gitUtil.mockApi(anyString(), anyString(), new MockLowLevelHttpRequest() {
@Override
public LowLevelHttpResponse execute() throws IOException {
throw new AssertionError("No API calls allowed for this test");
}
});
GitHubPrDestination d = skylark.eval("r", "r = git.github_pr_destination(" + " url = 'https://github.com/foo'," + " destination_ref = 'main'" + ")");
WriterContext writerContext = new WriterContext("piper_to_github", "TEST", false, new DummyRevision("feature", "feature"), Glob.ALL_FILES.roots());
Writer<GitRevision> writer = d.newWriter(writerContext);
GitRepository remote = gitUtil.mockRemoteRepo("github.com/foo");
addFiles(remote, null, "first change\n\nDummyOrigin-RevId: baseline", ImmutableMap.<String, String>builder().put("foo.txt", "").buildOrThrow());
DestinationStatus status = writer.getDestinationStatus(Glob.ALL_FILES, "DummyOrigin-RevId");
assertThat(status.getBaseline()).isEqualTo("baseline");
assertThat(status.getPendingChanges()).isEmpty();
writeFile(this.workdir, "test.txt", "some content");
writer.write(TransformResults.of(this.workdir, new DummyRevision("one")), Glob.ALL_FILES, console);
// New writer since after changes it keeps state internally for ITERATIVE mode
status = d.newWriter(writerContext).getDestinationStatus(Glob.ALL_FILES, "DummyOrigin-RevId");
assertThat(status.getBaseline()).isEqualTo("baseline");
// Not supported for now as we rewrite the whole branch history.
assertThat(status.getPendingChanges()).isEmpty();
}
Aggregations