Search in sources :

Example 1 with PrefixConsole

use of com.google.copybara.util.console.PrefixConsole in project copybara by google.

the class WorkflowRunHelper method maybeValidateRepoInLastRevState.

void maybeValidateRepoInLastRevState(@Nullable Metadata metadata) throws RepoException, ValidationException, IOException {
    if (!workflow.isCheckLastRevState() || isForce()) {
        return;
    }
    workflow.getGeneralOptions().ioRepoTask("validate_last_rev", () -> {
        O lastRev = workflow.getGeneralOptions().repoTask("get_last_rev", this::maybeGetLastRev);
        if (lastRev == null) {
            // Not the job of this function to check for lastrev status.
            return null;
        }
        Change<O> change = originReader.change(lastRev);
        Changes changes = new Changes(ImmutableList.of(change), ImmutableList.of());
        // Create a new writer so that state is not shared with the regular writer.
        // The current writer might have state from previous migrations, etc.
        ChangeMigrator<O, D> migrator = getMigratorForChangeAndWriter(change, workflow.createDryRunWriter(resolvedRef));
        try {
            workflow.getGeneralOptions().ioRepoTask("migrate", () -> migrator.doMigrate(lastRev, lastRev, new PrefixConsole("Validating last migration: ", workflow.getConsole()), metadata == null ? new Metadata(change.getMessage(), change.getAuthor(), ImmutableSetMultimap.of()) : metadata, changes, /*destinationBaseline=*/
            null, lastRev));
            throw new ValidationException("Migration of last-rev '" + lastRev.asString() + "' didn't" + " result in an empty change. This means that the result change of that" + " migration was modified ouside of Copybara or that new changes happened" + " later in the destination without using Copybara. Use --force if you" + " really want to do the migration.");
        } catch (EmptyChangeException ignored) {
        // EmptyChangeException ignored
        }
        return null;
    });
}
Also used : Changes(com.google.copybara.revision.Changes) ValidationException(com.google.copybara.exception.ValidationException) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) PrefixConsole(com.google.copybara.util.console.PrefixConsole)

Aggregations

EmptyChangeException (com.google.copybara.exception.EmptyChangeException)1 ValidationException (com.google.copybara.exception.ValidationException)1 Changes (com.google.copybara.revision.Changes)1 PrefixConsole (com.google.copybara.util.console.PrefixConsole)1