use of com.google.copybara.exception.CannotResolveRevisionException in project copybara by google.
the class GitVisitorUtil method visitChanges.
/**
* Visits
*/
static void visitChanges(GitRevision start, ChangesVisitor visitor, ChangeReader.Builder queryChanges, GeneralOptions generalOptions, String type, int visitChangePageSize) throws RepoException, ValidationException {
Preconditions.checkNotNull(start);
int skip = 0;
boolean finished = false;
try (ProfilerTask ignore = generalOptions.profiler().start(type + "/visit_changes")) {
while (!finished) {
ImmutableList<Change<GitRevision>> result;
try (ProfilerTask ignore2 = generalOptions.profiler().start("git_log_" + skip + "_" + visitChangePageSize)) {
result = queryChanges.setSkip(skip).setLimit(visitChangePageSize).build().run(start.getSha1()).reverse();
}
if (result.isEmpty()) {
break;
}
skip += result.size();
for (Change<GitRevision> current : result) {
if (visitor.visit(current) == VisitResult.TERMINATE) {
finished = true;
break;
}
}
}
}
if (skip == 0) {
throw new CannotResolveRevisionException("Cannot resolve reference " + start.getSha1());
}
}
use of com.google.copybara.exception.CannotResolveRevisionException in project copybara by google.
the class HgRepository method identify.
/**
* Returns a revision object given a reference.
*
* <p> A reference can be any of the following:
* <ul>
* <li> A global identifier for a revision. Example: f4e0e692208520203de05557244e573e981f6c72
* <li> A local identifier for a revision in the repository. Example: 1
* <li> A bookmark in the repository.
* <li> A branch in the repository, which returns the tip of that branch. Example: default
* <li> A tag in the repository. Example: tip
* </ul>
*/
public HgRevision identify(String reference) throws RepoException, CannotResolveRevisionException {
try {
CommandOutput commandOutput = hg(hgDir, "identify", "--template", "{node}\n", "--id", "--rev", reference);
String globalId = commandOutput.getStdout().trim();
return new HgRevision(globalId, reference);
} catch (RepoException e) {
if (UNKNOWN_REVISION.matcher(e.getMessage()).find()) {
throw new CannotResolveRevisionException(String.format("Unknown revision: %s", e.getMessage()));
}
throw e;
}
}
use of com.google.copybara.exception.CannotResolveRevisionException in project copybara by google.
the class WorkflowTest method iterativeWorkflowNoPreviousRef.
@Test
public void iterativeWorkflowNoPreviousRef() throws Exception {
origin.addSimpleChange(/*timestamp*/
1);
Workflow<?, ?> workflow = iterativeWorkflow(/*previousRef=*/
null);
CannotResolveRevisionException thrown = assertThrows(CannotResolveRevisionException.class, () -> workflow.run(workdir, ImmutableList.of("0")));
assertThat(thrown).hasMessageThat().contains("Previous revision label DummyOrigin-RevId could not be found");
}
use of com.google.copybara.exception.CannotResolveRevisionException in project copybara by google.
the class GitHubPrOriginTest method testCheckout_noMergeRef.
@Test
public void testCheckout_noMergeRef() throws Exception {
GitRepository remote = gitUtil.mockRemoteRepo("github.com/google/example");
addFiles(remote, "base", ImmutableMap.<String, String>builder().put("test.txt", "a").buildOrThrow());
String prHeadSha1 = remote.parseRef("HEAD");
remote.simpleCommand("update-ref", GitHubUtil.asHeadRef(123), prHeadSha1);
MockPullRequest.create(gitUtil).setState("open").setPrNumber(123).mock();
// Now try with merge ref
GitHubPrOrigin origin = githubPrOrigin("url = 'https://github.com/google/example'", "use_merge = True");
CannotResolveRevisionException thrown = assertThrows(CannotResolveRevisionException.class, () -> origin.newReader(Glob.ALL_FILES, authoring).checkout(origin.resolve("123"), workdir));
assertThat(thrown).hasMessageThat().contains("Cannot find a merge reference for Pull Request 123");
}
use of com.google.copybara.exception.CannotResolveRevisionException in project copybara by google.
the class GitHubPrOriginTest method testCheckout_nullMergeable_mergeCommitDoesntExist.
@Test
public void testCheckout_nullMergeable_mergeCommitDoesntExist() throws Exception {
GitRepository remote = withTmpWorktree(gitUtil.mockRemoteRepo("github.com/google/example"));
String baseRef = addFiles(remote, "base", ImmutableMap.of("test.txt", "a"));
remote.simpleCommand("branch", "feature");
String featureRef = addFiles(remote, "commit to feature branch", ImmutableMap.of("test.txt", "c"));
remote.forceCheckout(baseRef);
String mainRef = addFiles(remote, "commit to main branch", ImmutableMap.of("test.txt", "b"));
remote.forceCheckout(mainRef);
remote.simpleCommand("update-ref", GitHubUtil.asHeadRef(123), featureRef);
MockPullRequest.create(gitUtil).setState("open").setPrimaryBranch("main").setPrNumber(123).setMergeable(null).mock();
GitHubPrOrigin origin = githubPrOrigin("url = 'https://github.com/google/example'", "use_merge = True");
CannotResolveRevisionException thrown = assertThrows(CannotResolveRevisionException.class, () -> origin.resolve("123"));
assertThat(thrown).hasMessageThat().contains("Cannot find a merge reference for Pull Request 123");
}
Aggregations