return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST,
"Remote URI must be provided", null));
}
try {
URIish uri = new URIish(remoteURI);
if (GitUtils.isForbiddenGitUri(uri)) {
statusHandler.handleRequest(
request,
response,
new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, NLS.bind(
"Remote URI {0} does not appear to be a git repository", remoteURI), null)); //$NON-NLS-1$
return false;
}
} catch (URISyntaxException e) {
statusHandler.handleRequest(request, response,
new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, NLS.bind("Invalid remote URI: {0}", remoteURI), e)); //$NON-NLS-1$
return false;
}
String fetchRefSpec = toPut.optString(GitConstants.KEY_REMOTE_FETCH_REF, null);
String remotePushURI = toPut.optString(GitConstants.KEY_REMOTE_PUSH_URI, null);
String pushRefSpec = toPut.optString(GitConstants.KEY_REMOTE_PUSH_REF, null);
File gitDir = GitUtils.getGitDir(p);
URI cloneLocation = BaseToCloneConverter.getCloneLocation(getURI(request), BaseToCloneConverter.REMOTE_LIST);
Repository db = null;
try {
db = FileRepositoryBuilder.create(gitDir);
StoredConfig config = db.getConfig();
RemoteConfig rc = new RemoteConfig(config, remoteName);
rc.addURI(new URIish(remoteURI));
// FetchRefSpec is required, but default version can be generated
// if it isn't provided
if (fetchRefSpec == null || fetchRefSpec.isEmpty()) {
fetchRefSpec = String.format("+refs/heads/*:refs/remotes/%s/*", remoteName); //$NON-NLS-1$
}
rc.addFetchRefSpec(new RefSpec(fetchRefSpec));
// pushURI is optional
if (remotePushURI != null && !remotePushURI.isEmpty())
rc.addPushURI(new URIish(remotePushURI));
// PushRefSpec is optional
if (pushRefSpec != null && !pushRefSpec.isEmpty())
rc.addPushRefSpec(new RefSpec(pushRefSpec));
rc.update(config);