in src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/DeleteRefCommand.java [65:127]
public void deleteRef(Project.NameKey name, String refName, String sourceLabel)
throws IOException, RestApiException {
try {
repLog.info("Delete ref from {} for project {}, ref name {}", sourceLabel, name, refName);
Optional<ProjectState> projectState = projectCache.get(name);
if (!projectState.isPresent()) {
throw new ResourceNotFoundException(String.format("Project %s was not found", name));
}
Source source =
sourcesCollection
.getByRemoteName(sourceLabel)
.orElseThrow(
() ->
new IllegalStateException(
String.format("Could not find URI for %s remote", sourceLabel)));
URIish sourceUri = source.getURI(name);
try {
Context.setLocalEvent(true);
deleteRef.deleteSingleRef(projectState.get(), refName);
eventDispatcher
.get()
.postEvent(
new FetchRefReplicatedEvent(
name.get(),
refName,
sourceUri,
ReplicationState.RefFetchResult.SUCCEEDED,
RefUpdate.Result.FORCED));
} catch (PermissionBackendException e) {
logger.atSevere().withCause(e).log(
"Unexpected error while trying to delete ref '%s' on project %s and notifying it",
refName, name);
throw RestApiException.wrap(e.getMessage(), e);
} catch (ResourceConflictException e) {
eventDispatcher
.get()
.postEvent(
new FetchRefReplicatedEvent(
name.get(),
refName,
sourceUri,
ReplicationState.RefFetchResult.FAILED,
RefUpdate.Result.LOCK_FAILURE));
String message =
String.format(
"RefUpdate lock failure for: sourceLabel=%s, project=%s, refName=%s",
sourceLabel, name, refName);
logger.atSevere().withCause(e).log(message);
fetchStateLog.error(message);
throw e;
} finally {
Context.unsetLocalEvent();
}
repLog.info(
"Delete ref from {} for project {}, ref name {} completed", sourceLabel, name, refName);
} catch (PermissionBackendException e) {
throw RestApiException.wrap(e.getMessage(), e);
}
}