mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[git] IDEA-95974 IDEA-95984 Fix GitHttpAdapter for invalid proxy case and other error cases.
* PushCommand: update the code copy-pasted from JGit lib to reflect the recent changes in JGit 2.0: additional TransportException. * Cleanup after all exception cases. * Additionally protect against NPE. Reviewed by irengrig
This commit is contained in:
@@ -341,43 +341,45 @@ public final class GitHttpAdapter {
|
||||
// don't "eat" one password entering attempt
|
||||
//noinspection AssignmentToForLoopParameter
|
||||
i--;
|
||||
command.cleanup();
|
||||
}
|
||||
command.cleanup();
|
||||
}
|
||||
catch (JGitInternalException e) {
|
||||
if (authError(e)) {
|
||||
if (provider.wasCancelled()) { // if user cancels the dialog, just return
|
||||
return GeneralResult.CANCELLED;
|
||||
try {
|
||||
if (authError(e)) {
|
||||
if (provider.wasCancelled()) { // if user cancels the dialog, just return
|
||||
return GeneralResult.CANCELLED;
|
||||
}
|
||||
// otherwise give more tries to enter password
|
||||
}
|
||||
// otherwise give more tries to enter password
|
||||
else if (!httpTransportErrorFixTried && isTransportExceptionForHttp(e, url)) {
|
||||
url = url.replaceFirst("http", "https");
|
||||
command.setUrl(url);
|
||||
provider.setUrl(url);
|
||||
httpTransportErrorFixTried = true;
|
||||
// don't "eat" one password entering attempt
|
||||
//noinspection AssignmentToForLoopParameter
|
||||
i--;
|
||||
}
|
||||
else if (!noRemoteWithoutGitErrorFixTried && isNoRemoteWithoutDotGitError(e, url)) {
|
||||
url = addDotGitToUrl(url);
|
||||
command.setUrl(url);
|
||||
provider.setUrl(url);
|
||||
noRemoteWithoutGitErrorFixTried = true;
|
||||
// don't "eat" one password entering attempt
|
||||
//noinspection AssignmentToForLoopParameter
|
||||
i--;
|
||||
}
|
||||
else if (smartHttpPushNotSupported(e)) {
|
||||
throw new SmartPushNotSupportedException(e.getCause().getMessage());
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
command.cleanup();
|
||||
}
|
||||
else if (!httpTransportErrorFixTried && isTransportExceptionForHttp(e, url)) {
|
||||
url = url.replaceFirst("http", "https");
|
||||
command.setUrl(url);
|
||||
provider.setUrl(url);
|
||||
httpTransportErrorFixTried = true;
|
||||
// don't "eat" one password entering attempt
|
||||
//noinspection AssignmentToForLoopParameter
|
||||
i--;
|
||||
command.cleanup();
|
||||
}
|
||||
else if (!noRemoteWithoutGitErrorFixTried && isNoRemoteWithoutDotGitError(e, url)) {
|
||||
url = addDotGitToUrl(url);
|
||||
command.setUrl(url);
|
||||
provider.setUrl(url);
|
||||
noRemoteWithoutGitErrorFixTried = true;
|
||||
// don't "eat" one password entering attempt
|
||||
//noinspection AssignmentToForLoopParameter
|
||||
i--;
|
||||
command.cleanup();
|
||||
}
|
||||
else if (smartHttpPushNotSupported(e)) {
|
||||
throw new SmartPushNotSupportedException(e.getCause().getMessage());
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return GeneralResult.NOT_AUTHORIZED;
|
||||
@@ -415,7 +417,7 @@ public final class GitHttpAdapter {
|
||||
|
||||
private static boolean isNoRemoteWithoutDotGitError(Throwable e, String url) {
|
||||
Throwable cause = e.getCause();
|
||||
if (!(cause instanceof NoRemoteRepositoryException) && !(cause.getCause() instanceof NoRemoteRepositoryException)) {
|
||||
if (cause == null || (!(cause instanceof NoRemoteRepositoryException) && !(cause.getCause() instanceof NoRemoteRepositoryException))) {
|
||||
return false;
|
||||
}
|
||||
return !url.toLowerCase().endsWith(GitUtil.DOT_GIT);
|
||||
|
||||
@@ -196,7 +196,7 @@ interface GitHttpRemoteCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() throws InvalidRemoteException, URISyntaxException {
|
||||
public void run() throws InvalidRemoteException, URISyntaxException, org.eclipse.jgit.api.errors.TransportException {
|
||||
PushCommand pushCommand = myGit.push();
|
||||
pushCommand.setRemote(myRemoteName);
|
||||
pushCommand.setRefSpecs(myPushSpecs);
|
||||
@@ -304,7 +304,9 @@ interface GitHttpRemoteCommand {
|
||||
Original code constructs the remoteConfig based on .git/config.
|
||||
*/
|
||||
@NotNull
|
||||
private Iterable<PushResult> call(PushCommand pushCommand, RemoteConfig remoteConfig) throws JGitInternalException, InvalidRemoteException {
|
||||
private Iterable<PushResult> call(PushCommand pushCommand, RemoteConfig remoteConfig)
|
||||
throws JGitInternalException, InvalidRemoteException, org.eclipse.jgit.api.errors.TransportException
|
||||
{
|
||||
ArrayList<PushResult> pushResults = new ArrayList<PushResult>(3);
|
||||
|
||||
List<RefSpec> refSpecs = pushCommand.getRefSpecs();
|
||||
@@ -359,9 +361,7 @@ interface GitHttpRemoteCommand {
|
||||
pushResults.add(result);
|
||||
}
|
||||
catch (TransportException e) {
|
||||
throw new JGitInternalException(
|
||||
JGitText.get().exceptionCaughtDuringExecutionOfPushCommand,
|
||||
e);
|
||||
throw new org.eclipse.jgit.api.errors.TransportException(e.getMessage(), e);
|
||||
}
|
||||
finally {
|
||||
transport.close();
|
||||
@@ -371,6 +371,9 @@ interface GitHttpRemoteCommand {
|
||||
catch (URISyntaxException e) {
|
||||
throw new InvalidRemoteException(MessageFormat.format(
|
||||
JGitText.get().invalidRemote, remote));
|
||||
} catch (TransportException e) {
|
||||
throw new org.eclipse.jgit.api.errors.TransportException(
|
||||
e.getMessage(), e);
|
||||
}
|
||||
catch (NotSupportedException e) {
|
||||
throw new JGitInternalException(
|
||||
|
||||
Reference in New Issue
Block a user