LFS protocol support

Expose LFS batch protocol [1] from the standard LFS URL:

  http://gerrit/path/to/project/info/lfs/*

as this is the default URL where the git-lfs client [2] expects the LFS
protocol. Therefore, no additional configuration of the git-lfs client
is required.

LFS protocol requests are forwarded to the configured lfs.plugin.
If no lfs.plugin is defined, Gerrit responds with "501 Not Implemented"
to all LFS protocol requests.

User authentication is the same as for git-over-http protocol. An
additional advantage of using the standard LFS URL is that the git-lfs
client will reuse the authentication credentials used for the
git-over-http because the schema and the host name are the same.

NOTE: Currently the standard git-lfs client only supports basic
authentication. This means that Gerrit must be configured to support
basic authentication.

[1] https://github.com/github/git-lfs/blob/master/docs/api/http-v1-batch.md
[2] https://git-lfs.github.com/

Change-Id: I1e3f29789d73af52c60d3788ee4fd2e7024b1c0c
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Saša Živkov
2015-12-01 14:25:10 +01:00
parent 6233c1a239
commit ca7a67eb07
5 changed files with 290 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.httpd.plugins;
import static com.google.common.truth.Truth.assertThat;
import org.junit.Test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class LfsPluginServletTest {
@Test
public void noLfsEndPoint_noMatch() {
Pattern p = Pattern.compile(LfsPluginServlet.URL_REGEX);
doesNotMatch(p, "/foo");
doesNotMatch(p, "/a/foo");
doesNotMatch(p, "/p/foo");
doesNotMatch(p, "/a/p/foo");
doesNotMatch(p, "/info/lfs/objects/batch");
doesNotMatch(p, "/info/lfs/objects/batch/foo");
}
@Test
public void matchingLfsEndpoint_projectNameCaptured() {
Pattern p = Pattern.compile(LfsPluginServlet.URL_REGEX);
matches(p, "/foo/bar/info/lfs/objects/batch", "foo/bar");
matches(p, "/a/foo/bar/info/lfs/objects/batch", "foo/bar");
matches(p, "/p/foo/bar/info/lfs/objects/batch", "foo/bar");
matches(p, "/a/p/foo/bar/info/lfs/objects/batch", "foo/bar");
}
private void doesNotMatch(Pattern p, String input) {
Matcher m = p.matcher(input);
assertThat(m.matches()).isFalse();
}
private void matches(Pattern p, String input, String expectedProjectName) {
Matcher m = p.matcher(input);
assertThat(m.matches()).isTrue();
assertThat(m.group(1)).isEqualTo(expectedProjectName);
}
}