aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.lfs.test/tst/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.test/tst/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.test/tst/org/eclipse')
-rw-r--r--org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/internal/LfsConnectionFactoryTest.java132
1 files changed, 132 insertions, 0 deletions
diff --git a/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/internal/LfsConnectionFactoryTest.java b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/internal/LfsConnectionFactoryTest.java
new file mode 100644
index 0000000000..c7bd48e12c
--- /dev/null
+++ b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/internal/LfsConnectionFactoryTest.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2022 Nail Samatov <sanail@yandex.ru> 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
+ * https://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+package org.eclipse.jgit.lfs.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+
+import java.util.TreeMap;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.RemoteAddCommand;
+import org.eclipse.jgit.attributes.FilterCommandRegistry;
+import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.lfs.CleanFilter;
+import org.eclipse.jgit.lfs.Protocol;
+import org.eclipse.jgit.lfs.SmudgeFilter;
+import org.eclipse.jgit.lfs.errors.LfsConfigInvalidException;
+import org.eclipse.jgit.lfs.lib.Constants;
+import org.eclipse.jgit.lib.ConfigConstants;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.StoredConfig;
+import org.eclipse.jgit.transport.URIish;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class LfsConnectionFactoryTest extends RepositoryTestCase {
+
+ private static final String SMUDGE_NAME = org.eclipse.jgit.lib.Constants.BUILTIN_FILTER_PREFIX
+ + Constants.ATTR_FILTER_DRIVER_PREFIX
+ + org.eclipse.jgit.lib.Constants.ATTR_FILTER_TYPE_SMUDGE;
+
+ private static final String CLEAN_NAME = org.eclipse.jgit.lib.Constants.BUILTIN_FILTER_PREFIX
+ + Constants.ATTR_FILTER_DRIVER_PREFIX
+ + org.eclipse.jgit.lib.Constants.ATTR_FILTER_TYPE_CLEAN;
+
+ private Git git;
+
+ @BeforeClass
+ public static void installLfs() {
+ FilterCommandRegistry.register(SMUDGE_NAME, SmudgeFilter.FACTORY);
+ FilterCommandRegistry.register(CLEAN_NAME, CleanFilter.FACTORY);
+ }
+
+ @AfterClass
+ public static void removeLfs() {
+ FilterCommandRegistry.unregister(SMUDGE_NAME);
+ FilterCommandRegistry.unregister(CLEAN_NAME);
+ }
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ git = new Git(db);
+ }
+
+ @Test
+ public void lfsUrlFromRemoteUrlWithDotGit() throws Exception {
+ addRemoteUrl("https://localhost/repo.git");
+
+ String lfsUrl = LfsConnectionFactory.getLfsUrl(db,
+ Protocol.OPERATION_DOWNLOAD,
+ new TreeMap<>());
+ assertEquals("https://localhost/repo.git/info/lfs", lfsUrl);
+ }
+
+ @Test
+ public void lfsUrlFromRemoteUrlWithoutDotGit() throws Exception {
+ addRemoteUrl("https://localhost/repo");
+
+ String lfsUrl = LfsConnectionFactory.getLfsUrl(db,
+ Protocol.OPERATION_DOWNLOAD,
+ new TreeMap<>());
+ assertEquals("https://localhost/repo.git/info/lfs", lfsUrl);
+ }
+
+ @Test
+ public void lfsUrlFromLocalConfig() throws Exception {
+ addRemoteUrl("https://localhost/repo");
+
+ StoredConfig cfg = ((Repository) db).getConfig();
+ cfg.setString(ConfigConstants.CONFIG_SECTION_LFS,
+ null,
+ ConfigConstants.CONFIG_KEY_URL,
+ "https://localhost/repo/lfs");
+ cfg.save();
+
+ String lfsUrl = LfsConnectionFactory.getLfsUrl(db,
+ Protocol.OPERATION_DOWNLOAD,
+ new TreeMap<>());
+ assertEquals("https://localhost/repo/lfs", lfsUrl);
+ }
+
+ @Test
+ public void lfsUrlFromOriginConfig() throws Exception {
+ addRemoteUrl("https://localhost/repo");
+
+ StoredConfig cfg = ((Repository) db).getConfig();
+ cfg.setString(ConfigConstants.CONFIG_SECTION_LFS,
+ org.eclipse.jgit.lib.Constants.DEFAULT_REMOTE_NAME,
+ ConfigConstants.CONFIG_KEY_URL,
+ "https://localhost/repo/lfs");
+ cfg.save();
+
+ String lfsUrl = LfsConnectionFactory.getLfsUrl(db,
+ Protocol.OPERATION_DOWNLOAD,
+ new TreeMap<>());
+ assertEquals("https://localhost/repo/lfs", lfsUrl);
+ }
+
+ @Test
+ public void lfsUrlNotConfigured() throws Exception {
+ assertThrows(LfsConfigInvalidException.class, () -> LfsConnectionFactory
+ .getLfsUrl(db, Protocol.OPERATION_DOWNLOAD, new TreeMap<>()));
+ }
+
+ private void addRemoteUrl(String remotUrl) throws Exception {
+ RemoteAddCommand add = git.remoteAdd();
+ add.setUri(new URIish(remotUrl));
+ add.setName(org.eclipse.jgit.lib.Constants.DEFAULT_REMOTE_NAME);
+ add.call();
+ }
+}