aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.lfs/src/org
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2018-06-12 14:09:39 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2018-06-13 11:24:24 +0200
commitf7fbc7fcd72becb06795e32d1ea263cf6185a670 (patch)
tree836eec140c2cd3d0d84812b211195660798fceaf /org.eclipse.jgit.lfs/src/org
parent5429d1a0cff593bf28186c38fde7e41798a2c0b8 (diff)
downloadjgit-f7fbc7fcd72becb06795e32d1ea263cf6185a670.tar.gz
jgit-f7fbc7fcd72becb06795e32d1ea263cf6185a670.zip
Propagate failure of ssh command to caller of SshSupport
When SshSupport.runSshCommand fails since the executed external ssh command failed throw a CommandFailedException. If discovery of LFS server fails due to failure of the git-lfs-authenticate command chain the CommandFailureException to the LfsConfigInvalidException in order to allow root cause analysis in the application using that. Change-Id: I2f9ea2be11274549f6d845937164c248b3d840b2 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.lfs/src/org')
-rw-r--r--org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/LfsConfigInvalidException.java13
-rw-r--r--org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java47
-rw-r--r--org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsText.java1
3 files changed, 38 insertions, 23 deletions
diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/LfsConfigInvalidException.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/LfsConfigInvalidException.java
index 5320af0b78..f90a003b4b 100644
--- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/LfsConfigInvalidException.java
+++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/LfsConfigInvalidException.java
@@ -63,4 +63,17 @@ public class LfsConfigInvalidException extends IOException {
super(msg);
}
+ /**
+ * Constructor for LfsConfigInvalidException.
+ *
+ * @param msg
+ * the error description
+ * @param e
+ * cause of this exception
+ * @since 5.0
+ */
+ public LfsConfigInvalidException(String msg, Exception e) {
+ super(msg, e);
+ }
+
}
diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java
index bac980bb8d..955eca0c3f 100644
--- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java
+++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java
@@ -49,6 +49,7 @@ import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_TYPE;
import java.io.IOException;
import java.net.ProxySelector;
+import java.net.URISyntaxException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.LinkedList;
@@ -56,6 +57,7 @@ import java.util.Map;
import java.util.TreeMap;
import org.eclipse.jgit.annotations.NonNull;
+import org.eclipse.jgit.errors.CommandFailedException;
import org.eclipse.jgit.lfs.LfsPointer;
import org.eclipse.jgit.lfs.Protocol;
import org.eclipse.jgit.lfs.errors.LfsConfigInvalidException;
@@ -68,17 +70,12 @@ import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.transport.http.HttpConnection;
import org.eclipse.jgit.util.HttpSupport;
import org.eclipse.jgit.util.SshSupport;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Provides means to get a valid LFS connection for a given repository.
*/
public class LfsConnectionFactory {
- private static final Logger log = LoggerFactory
- .getLogger(LfsConnectionFactory.class);
-
private static final int SSH_AUTH_TIMEOUT_SECONDS = 30;
private static final String SCHEME_HTTPS = "https"; //$NON-NLS-1$
private static final String SCHEME_SSH = "ssh"; //$NON-NLS-1$
@@ -133,6 +130,7 @@ public class LfsConnectionFactory {
String lfsUrl = config.getString(ConfigConstants.CONFIG_SECTION_LFS,
null,
ConfigConstants.CONFIG_KEY_URL);
+ Exception ex = null;
if (lfsUrl == null) {
String remoteUrl = null;
for (String remote : db.getRemoteNames()) {
@@ -151,39 +149,44 @@ public class LfsConnectionFactory {
break;
}
if (lfsUrl == null && remoteUrl != null) {
- lfsUrl = discoverLfsUrl(db, purpose, additionalHeaders,
- remoteUrl);
+ try {
+ lfsUrl = discoverLfsUrl(db, purpose, additionalHeaders,
+ remoteUrl);
+ } catch (URISyntaxException | IOException
+ | CommandFailedException e) {
+ ex = e;
+ }
} else {
lfsUrl = lfsUrl + Protocol.INFO_LFS_ENDPOINT;
}
}
if (lfsUrl == null) {
+ if (ex != null) {
+ throw new LfsConfigInvalidException(
+ LfsText.get().lfsNoDownloadUrl, ex);
+ }
throw new LfsConfigInvalidException(LfsText.get().lfsNoDownloadUrl);
}
return lfsUrl;
}
private static String discoverLfsUrl(Repository db, String purpose,
- Map<String, String> additionalHeaders, String remoteUrl) {
- try {
- URIish u = new URIish(remoteUrl);
- if (u.getScheme() == null || SCHEME_SSH.equals(u.getScheme())) {
- Protocol.ExpiringAction action = getSshAuthentication(
- db, purpose, remoteUrl, u);
- additionalHeaders.putAll(action.header);
- return action.href;
- } else {
- return remoteUrl + Protocol.INFO_LFS_ENDPOINT;
- }
- } catch (Exception e) {
- log.error(LfsText.get().cannotDiscoverLfs, e);
- return null; // could not discover
+ Map<String, String> additionalHeaders, String remoteUrl)
+ throws URISyntaxException, IOException, CommandFailedException {
+ URIish u = new URIish(remoteUrl);
+ if (u.getScheme() == null || SCHEME_SSH.equals(u.getScheme())) {
+ Protocol.ExpiringAction action = getSshAuthentication(db, purpose,
+ remoteUrl, u);
+ additionalHeaders.putAll(action.header);
+ return action.href;
+ } else {
+ return remoteUrl + Protocol.INFO_LFS_ENDPOINT;
}
}
private static Protocol.ExpiringAction getSshAuthentication(
Repository db, String purpose, String remoteUrl, URIish u)
- throws IOException {
+ throws IOException, CommandFailedException {
AuthCache cached = sshAuthCache.get(remoteUrl);
Protocol.ExpiringAction action = null;
if (cached != null && cached.validUntil > System.currentTimeMillis()) {
diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsText.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsText.java
index d51203a740..d7d0fe186a 100644
--- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsText.java
+++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsText.java
@@ -60,7 +60,6 @@ public class LfsText extends TranslationBundle {
}
// @formatter:off
- /***/ public String cannotDiscoverLfs;
/***/ public String corruptLongObject;
/***/ public String inconsistentMediafileLength;
/***/ public String inconsistentContentLength;