aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.lfs.server.test
diff options
context:
space:
mode:
authorMarkus Duft <markus.duft@ssi-schaefer.com>2017-11-10 11:10:28 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2018-02-27 18:32:45 +0100
commitc0bb992845e6ba5df9f420739fe9075ed20e9ee2 (patch)
tree23e01159ba98b6d5040e4d47d4fbfdf0dc02e0c5 /org.eclipse.jgit.lfs.server.test
parent12a589fb577ebbd464cede7b06a7949c84a51350 (diff)
downloadjgit-c0bb992845e6ba5df9f420739fe9075ed20e9ee2.tar.gz
jgit-c0bb992845e6ba5df9f420739fe9075ed20e9ee2.zip
LFS: pre-push upload support
If JGit built in LFS support is enabled for the current repository (or user/system), any existing pre-push hook will cause an exception for the time beeing, as only a single pre-push hook is supported. Thus either native pre-push hooks OR JGit built-in LFS support may be enabled currently, but not both. Change-Id: Ie7d2b90e26e948d9cca3d05a7a19489488c75895 Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.lfs.server.test')
-rw-r--r--org.eclipse.jgit.lfs.server.test/META-INF/MANIFEST.MF6
-rw-r--r--org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/PushTest.java165
2 files changed, 170 insertions, 1 deletions
diff --git a/org.eclipse.jgit.lfs.server.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.lfs.server.test/META-INF/MANIFEST.MF
index af046aecc7..1589f42285 100644
--- a/org.eclipse.jgit.lfs.server.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.lfs.server.test/META-INF/MANIFEST.MF
@@ -33,13 +33,17 @@ Import-Package: javax.servlet;version="[3.1.0,4.0.0)",
org.eclipse.jgit.junit;version="[4.11.0,4.12.0)",
org.eclipse.jgit.junit.http;version="[4.11.0,4.12.0)",
org.eclipse.jgit.lfs;version="[4.11.0,4.12.0)",
- org.eclipse.jgit.lfs.lib;version="[4.11.0,4.12.0)",
org.eclipse.jgit.lfs.errors;version="[4.11.0,4.12.0)",
+ org.eclipse.jgit.lfs.lib;version="[4.11.0,4.12.0)",
org.eclipse.jgit.lfs.server;version="[4.11.0,4.12.0)",
org.eclipse.jgit.lfs.server.fs;version="[4.11.0,4.12.0)",
org.eclipse.jgit.lfs.test;version="[4.11.0,4.12.0)",
org.eclipse.jgit.lib;version="[4.11.0,4.12.0)",
+ org.eclipse.jgit.revwalk;version="[4.11.0,4.12.0)",
org.eclipse.jgit.storage.file;version="[4.11.0,4.12.0)",
+ org.eclipse.jgit.transport;version="[4.11.0,4.12.0)",
+ org.eclipse.jgit.treewalk;version="[4.11.0,4.12.0)",
+ org.eclipse.jgit.treewalk.filter;version="[4.11.0,4.12.0)",
org.eclipse.jgit.util;version="[4.11.0,4.12.0)",
org.hamcrest.core;version="[1.1.0,2.0.0)",
org.junit;version="[4.12,5.0.0)",
diff --git a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/PushTest.java b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/PushTest.java
new file mode 100644
index 0000000000..82566f351a
--- /dev/null
+++ b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/PushTest.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2018, Markus Duft <markus.duft@ssi-schaefer.com>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.lfs.server.fs;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.RemoteAddCommand;
+import org.eclipse.jgit.junit.JGitTestUtil;
+import org.eclipse.jgit.junit.TestRepository;
+import org.eclipse.jgit.lfs.CleanFilter;
+import org.eclipse.jgit.lfs.SmudgeFilter;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ObjectLoader;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.StoredConfig;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
+import org.eclipse.jgit.transport.URIish;
+import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.treewalk.filter.PathFilter;
+import org.eclipse.jgit.util.FileUtils;
+import org.eclipse.jgit.util.IO;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class PushTest extends LfsServerTest {
+
+ Git git;
+
+ private TestRepository localDb;
+
+ private Repository remoteDb;
+
+ @Override
+ @Before
+ public void setup() throws Exception {
+ super.setup();
+
+ SmudgeFilter.register();
+ CleanFilter.register();
+
+ Path rtmp = Files.createTempDirectory("jgit_test_");
+ remoteDb = FileRepositoryBuilder.create(rtmp.toFile());
+ remoteDb.create(true);
+
+ Path tmp = Files.createTempDirectory("jgit_test_");
+ Repository db = FileRepositoryBuilder
+ .create(tmp.resolve(".git").toFile());
+ db.create(false);
+ StoredConfig cfg = db.getConfig();
+ cfg.setString("filter", "lfs", "usejgitbuiltin", "true");
+ cfg.setString("lfs", null, "url", server.getURI().toString() + "/lfs");
+ cfg.save();
+
+ localDb = new TestRepository<>(db);
+ localDb.branch("master").commit().add(".gitattributes",
+ "*.bin filter=lfs diff=lfs merge=lfs -text ").create();
+ git = Git.wrap(db);
+
+ URIish uri = new URIish(
+ "file://" + remoteDb.getDirectory());
+ RemoteAddCommand radd = git.remoteAdd();
+ radd.setUri(uri);
+ radd.setName(Constants.DEFAULT_REMOTE_NAME);
+ radd.call();
+
+ git.checkout().setName("master").call();
+ git.push().call();
+ }
+
+ @After
+ public void cleanup() throws Exception {
+ remoteDb.close();
+ localDb.getRepository().close();
+ FileUtils.delete(localDb.getRepository().getWorkTree(),
+ FileUtils.RECURSIVE);
+ FileUtils.delete(remoteDb.getDirectory(), FileUtils.RECURSIVE);
+ }
+
+ @Test
+ public void testPushSimple() throws Exception {
+ JGitTestUtil.writeTrashFile(localDb.getRepository(), "a.bin",
+ "1234567");
+ git.add().addFilepattern("a.bin").call();
+ RevCommit commit = git.commit().setMessage("add lfs blob").call();
+ git.push().call();
+
+ // check object in remote db, should be LFS pointer
+ ObjectId id = commit.getId();
+ try (RevWalk walk = new RevWalk(remoteDb)) {
+ RevCommit rc = walk.parseCommit(id);
+ try (TreeWalk tw = new TreeWalk(walk.getObjectReader())) {
+ tw.addTree(rc.getTree());
+ tw.setFilter(PathFilter.create("a.bin"));
+ tw.next();
+
+ assertEquals(tw.getPathString(), "a.bin");
+ ObjectLoader ldr = walk.getObjectReader()
+ .open(tw.getObjectId(0), Constants.OBJ_BLOB);
+ try(InputStream is = ldr.openStream()) {
+ assertEquals(
+ "version https://git-lfs.github.com/spec/v1\noid sha256:8bb0cf6eb9b17d0f7d22b456f121257dc1254e1f01665370476383ea776df414\nsize 7\n",
+ new String(IO
+ .readWholeStream(is,
+ (int) ldr.getSize())
+ .array()));
+ }
+ }
+
+ }
+
+ assertEquals(
+ "[POST /lfs/objects/batch 200, PUT /lfs/objects/8bb0cf6eb9b17d0f7d22b456f121257dc1254e1f01665370476383ea776df414 200]",
+ server.getRequests().toString());
+ }
+
+}