aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.lfs/src/org/eclipse
diff options
context:
space:
mode:
authorNail Samatov <sanail@yandex.ru>2022-02-07 18:13:58 +0300
committerThomas Wolf <thomas.wolf@paranor.ch>2022-02-08 09:11:12 +0100
commita054f3ce76c2aaeada7fc9b84f23a3eceb2f7708 (patch)
tree0da5ac962419ed9a02d9b8a4d0eec72984a7d5d9 /org.eclipse.jgit.lfs/src/org/eclipse
parent7e752364a6000259b2ec3fc66e0314ba12e6c0d4 (diff)
downloadjgit-a054f3ce76c2aaeada7fc9b84f23a3eceb2f7708.tar.gz
jgit-a054f3ce76c2aaeada7fc9b84f23a3eceb2f7708.zip
Support LFS Server URL without .git suffix
According to Git LFS documentation, URLs with and without .git suffix should be supported. By default, Git LFS will append .git/info/lfs to the end of a Git remote URL. To build the LFS server URL it will use: Git Remote: https://git-server.com/foo/bar LFS Server: https://git-server.com/foo/bar.git/info/lfs Git Remote: https://git-server.com/foo/bar.git LFS Server: https://git-server.com/foo/bar.git/info/lfs Fix the LfsConnectionFactory accordingly. Move a utility method to add the ".git" suffix if not present yet from FileResolver to StringUtils and use it. Bug: 578621 Change-Id: I8d3645872d5f03bb8e82c9c73647adb3e81ce484 Signed-off-by: Nail Samatov <sanail@yandex.ru> Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.lfs/src/org/eclipse')
-rw-r--r--org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java29
1 files changed, 23 insertions, 6 deletions
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 e221913bea..5a17d411c7 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
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017, Markus Duft <markus.duft@ssi-schaefer.com> and others
+ * Copyright (C) 2017, 2022 Markus Duft <markus.duft@ssi-schaefer.com> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -39,6 +39,7 @@ 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.eclipse.jgit.util.StringUtils;
/**
* Provides means to get a valid LFS connection for a given repository.
@@ -64,7 +65,7 @@ public class LfsConnectionFactory {
* be used for
* @param purpose
* the action, e.g. Protocol.OPERATION_DOWNLOAD
- * @return the url for the lfs server. e.g.
+ * @return the connection for the lfs server. e.g.
* "https://github.com/github/git-lfs.git/info/lfs"
* @throws IOException
*/
@@ -92,7 +93,24 @@ public class LfsConnectionFactory {
return connection;
}
- private static String getLfsUrl(Repository db, String purpose,
+ /**
+ * Get LFS Server URL.
+ *
+ * @param db
+ * the repository to work with
+ * @param purpose
+ * the action, e.g. Protocol.OPERATION_DOWNLOAD
+ * @param additionalHeaders
+ * additional headers that can be used to connect to LFS server
+ * @return the URL for the LFS server. e.g.
+ * "https://github.com/github/git-lfs.git/info/lfs"
+ * @throws LfsConfigInvalidException
+ * if the LFS config is invalid
+ * @see <a href=
+ * "https://github.com/git-lfs/git-lfs/blob/main/docs/api/server-discovery.md">
+ * Server Discovery documentation</a>
+ */
+ static String getLfsUrl(Repository db, String purpose,
Map<String, String> additionalHeaders)
throws LfsConfigInvalidException {
StoredConfig config = db.getConfig();
@@ -125,8 +143,6 @@ public class LfsConnectionFactory {
| CommandFailedException e) {
ex = e;
}
- } else {
- lfsUrl = lfsUrl + Protocol.INFO_LFS_ENDPOINT;
}
}
if (lfsUrl == null) {
@@ -149,7 +165,8 @@ public class LfsConnectionFactory {
additionalHeaders.putAll(action.header);
return action.href;
}
- return remoteUrl + Protocol.INFO_LFS_ENDPOINT;
+ return StringUtils.nameWithDotGit(remoteUrl)
+ + Protocol.INFO_LFS_ENDPOINT;
}
private static Protocol.ExpiringAction getSshAuthentication(