@Override
protected Remote _call() {
if (name == null || name.isEmpty()) {
throw new RemoteException(StatusCode.MISSING_NAME);
}
ConfigDatabase config = configDatabase();
List<String> allRemotes = config.getAllSubsections("remote");
if (!allRemotes.contains(name)) {
throw new RemoteException(StatusCode.REMOTE_NOT_FOUND);
}
Remote remote = null;
String remoteSection = "remote." + name;
Optional<String> remoteFetchURL = config.get(remoteSection + ".url");
Optional<String> remoteFetch = config.get(remoteSection + ".fetch");
Optional<String> remotePushURL = Optional.absent();
Optional<String> remoteMapped = config.get(remoteSection + ".mapped");
Optional<String> remoteMappedBranch = config.get(remoteSection + ".mappedBranch");
Optional<String> remoteUserName = config.get(remoteSection + ".username");
Optional<String> remotePassword = config.get(remoteSection + ".password");
if (remoteFetchURL.isPresent() && remoteFetch.isPresent()) {
remotePushURL = config.get(remoteSection + ".pushurl");
}
remote = new Remote(name, remoteFetchURL.or(""), remotePushURL.or(remoteFetchURL.or("")),
remoteFetch.or(""), remoteMapped.or("false").equals("true"),
remoteMappedBranch.orNull(), remoteUserName.orNull(), remotePassword.orNull());
config.removeSection(remoteSection);
// Remove refs
final ImmutableSet<Ref> localRemoteRefs = command(LsRemote.class).retrieveLocalRefs(true)
.setRemote(Suppliers.ofInstance(Optional.of(remote))).call();