throw new MojoExecutionException("Error creating tree: "
+ getExceptionMessage(e), e);
}
// Build commit
Commit commit = new Commit();
commit.setMessage(message);
commit.setTree(tree);
try {
UserService userService = new UserService(service.getClient());
User user = userService.getUser();
CommitUser author = new CommitUser();
author.setName(user.getName());
author.setEmail(user.getEmail());
author.setDate(new GregorianCalendar().getTime());
commit.setAuthor(author);
commit.setCommitter(author);
} catch (IOException e) {
throw new MojoExecutionException("Error retrieving user info: "
+ getExceptionMessage(e), e);
}
// Set parent commit SHA-1 if reference exists
if (ref != null)
commit.setParents(Collections.singletonList(new Commit().setSha(ref
.getObject().getSha())));
Commit created;
try {
if (!dryRun)
created = service.createCommit(repository, commit);
else
created = new Commit();
info(MessageFormat.format("Creating commit with SHA-1: {0}",
created.getSha()));
} catch (IOException e) {
throw new MojoExecutionException("Error creating commit: "
+ getExceptionMessage(e), e);
}
TypedResource object = new TypedResource();
object.setType(TYPE_COMMIT).setSha(created.getSha());
if (ref != null) {
// Update existing reference
ref.setObject(object);
try {
info(MessageFormat.format(
"Updating reference {0} from {1} to {2}", branch,
commit.getParents().get(0).getSha(), created.getSha()));
if (!dryRun)
service.editReference(repository, ref, force);
} catch (IOException e) {
throw new MojoExecutionException("Error editing reference: "
+ getExceptionMessage(e), e);
}
} else {
// Create new reference
ref = new Reference().setObject(object).setRef(branch);
try {
info(MessageFormat.format(
"Creating reference {0} starting at commit {1}",
branch, created.getSha()));
if (!dryRun)
service.createReference(repository, ref);
} catch (IOException e) {
throw new MojoExecutionException("Error creating reference: "
+ getExceptionMessage(e), e);