use of com.gitblit.utils.JGitUtils.MergeResult in project gitblit by gitblit.
the class PatchsetReceivePack method merge.
/**
* Merge the specified patchset to the integration branch.
*
* @param ticket
* @param patchset
* @return true, if successful
*/
public MergeStatus merge(TicketModel ticket) {
PersonIdent committer = new PersonIdent(user.getDisplayName(), StringUtils.isEmpty(user.emailAddress) ? (user.username + "@gitblit") : user.emailAddress);
Patchset patchset = ticket.getCurrentPatchset();
String message = MessageFormat.format("Merged #{0,number,0} \"{1}\"", ticket.number, ticket.title);
Ref oldRef = null;
try {
oldRef = getRepository().getRef(ticket.mergeTo);
} catch (IOException e) {
LOGGER.error("failed to get ref for " + ticket.mergeTo, e);
}
MergeResult mergeResult = JGitUtils.merge(getRepository(), patchset.tip, ticket.mergeTo, getRepositoryModel().mergeType, committer, message);
if (StringUtils.isEmpty(mergeResult.sha)) {
LOGGER.error("FAILED to merge {} to {} ({})", new Object[] { patchset, ticket.mergeTo, mergeResult.status.name() });
return mergeResult.status;
}
Change change = new Change(user.username);
change.setField(Field.status, Status.Merged);
change.setField(Field.mergeSha, mergeResult.sha);
change.setField(Field.mergeTo, ticket.mergeTo);
if (StringUtils.isEmpty(ticket.responsible)) {
// unassigned tickets are assigned to the closer
change.setField(Field.responsible, user.username);
}
long ticketId = ticket.number;
ticket = ticketService.updateTicket(repository, ticket.number, change);
if (ticket != null) {
ticketNotifier.queueMailing(ticket);
if (oldRef != null) {
ReceiveCommand cmd = new ReceiveCommand(oldRef.getObjectId(), ObjectId.fromString(mergeResult.sha), oldRef.getName());
cmd.setResult(Result.OK);
List<ReceiveCommand> commands = Arrays.asList(cmd);
logRefChange(commands);
updateIncrementalPushTags(commands);
updateGitblitRefLog(commands);
}
// call patchset hooks
for (PatchsetHook hook : gitblit.getExtensions(PatchsetHook.class)) {
try {
hook.onMergePatchset(ticket);
} catch (Exception e) {
LOGGER.error("Failed to execute extension", e);
}
}
return mergeResult.status;
} else {
LOGGER.error("FAILED to resolve ticket {} by merge from web ui", ticketId);
}
return mergeResult.status;
}
Aggregations