use of com.google.copybara.exception.CannotResolveRevisionException in project copybara by google.
the class GitRepository method commit.
// TODO(malcon): Create a CommitCmd object builder
public void commit(@Nullable String author, boolean amend, @Nullable ZonedDateTime timestamp, String message) throws RepoException, ValidationException {
if (isEmptyStaging() && !amend) {
String baseline = "unknown";
try {
baseline = parseRef("HEAD");
} catch (CannotResolveRevisionException | RepoException e) {
logger.atWarning().withCause(e).log("Cannot find baseline.");
}
throw new EmptyChangeException(String.format("Migration of the revision resulted in an empty change from baseline '%s'.\n" + "Is the change already migrated?", baseline));
}
ImmutableList.Builder<String> params = ImmutableList.<String>builder().add("commit");
if (author != null) {
params.add("--author", author);
}
if (timestamp != null) {
params.add("--date", timestamp.format(ISO_OFFSET_DATE_TIME_NO_SUBSECONDS));
}
if (amend) {
params.add("--amend");
}
if (noVerify) {
params.add("--no-verify");
}
Path descriptionFile = null;
try {
if (message.getBytes(StandardCharsets.UTF_8).length > ARBITRARY_MAX_ARG_SIZE) {
descriptionFile = getCwd().resolve(UUID.randomUUID().toString() + ".desc");
Files.write(descriptionFile, message.getBytes(StandardCharsets.UTF_8));
params.add("-F", descriptionFile.toAbsolutePath().toString());
} else {
params.add("-m", message);
}
git(getCwd(), addGitDirAndWorkTreeParams(params.build()));
} catch (IOException e) {
throw new RepoException("Could not commit change: Failed to write file " + descriptionFile, e);
} finally {
try {
if (descriptionFile != null) {
Files.deleteIfExists(descriptionFile);
}
} catch (IOException e) {
logger.atWarning().log("Could not delete description file: %s", descriptionFile);
}
}
}
use of com.google.copybara.exception.CannotResolveRevisionException in project copybara by google.
the class GitRepository method parseRef.
/**
* Resolves a git reference to the SHA-1 reference
*/
public String parseRef(String ref) throws RepoException, CannotResolveRevisionException {
// Runs rev-list on the reference and remove the extra newline from the output.
CommandOutputWithStatus result = gitAllowNonZeroExit(NO_INPUT, ImmutableList.of("rev-list", "-1", ref, "--"), DEFAULT_TIMEOUT);
if (!result.getTerminationStatus().success()) {
throw new CannotResolveRevisionException("Cannot find reference '" + ref + "'");
}
String sha1 = result.getStdout().trim();
Verify.verify(SHA1_PATTERN.matcher(sha1).matches(), "Should be resolved to a SHA-1: %s", sha1);
return sha1;
}
use of com.google.copybara.exception.CannotResolveRevisionException in project copybara by google.
the class WorkflowTest method invalidLastRevFlagGivesClearError.
@Test
public void invalidLastRevFlagGivesClearError() throws Exception {
origin.addSimpleChange(/*timestamp*/
42);
Workflow<?, ?> workflow = iterativeWorkflow("deadbeef");
CannotResolveRevisionException thrown = assertThrows(CannotResolveRevisionException.class, () -> workflow.run(workdir, ImmutableList.of(HEAD)));
assertThat(thrown).hasMessageThat().contains("Could not resolve --last-rev flag. Please make sure it exists in the origin:" + " deadbeef");
}
use of com.google.copybara.exception.CannotResolveRevisionException in project copybara by google.
the class GerritOriginTest method testReferencePatchSetNotFound.
@Test
public void testReferencePatchSetNotFound() throws RepoException, ValidationException {
CannotResolveRevisionException thrown = assertThrows(CannotResolveRevisionException.class, () -> origin.resolve("http://foo.com/#/c/12345/42"));
assertThat(thrown).hasMessageThat().contains("Cannot find patch set 42");
}
use of com.google.copybara.exception.CannotResolveRevisionException in project copybara by google.
the class GerritOriginTest method testReferenceNotFound.
@Test
public void testReferenceNotFound() throws RepoException, ValidationException {
CannotResolveRevisionException thrown = assertThrows(CannotResolveRevisionException.class, () -> origin.resolve("54321"));
assertThat(thrown).hasMessageThat().contains("Cannot find change number 54321");
}
Aggregations