Enable LFS support for the CLI by registering the according filters. Errors during filter creation must be propagated up the call stack, as a failure to create a filter should be treated as fatal if the filter is required. Change-Id: I3833757839bdda97cd01b6c21c1613d199e2692d Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com>tags/v4.11.0.201803080745-r
org.eclipse.jetty.util.security;version="[9.4.5,10.0.0)", | org.eclipse.jetty.util.security;version="[9.4.5,10.0.0)", | ||||
org.eclipse.jetty.util.thread;version="[9.4.5,10.0.0)", | org.eclipse.jetty.util.thread;version="[9.4.5,10.0.0)", | ||||
org.eclipse.jgit.api;version="[4.11.0,4.12.0)", | org.eclipse.jgit.api;version="[4.11.0,4.12.0)", | ||||
org.eclipse.jgit.api.errors;version="[4.11.0,4.12.0)", | |||||
org.eclipse.jgit.internal.storage.file;version="[4.11.0,4.12.0)", | org.eclipse.jgit.internal.storage.file;version="[4.11.0,4.12.0)", | ||||
org.eclipse.jgit.junit;version="[4.11.0,4.12.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.junit.http;version="[4.11.0,4.12.0)", |
import java.nio.file.Path; | import java.nio.file.Path; | ||||
import org.eclipse.jgit.api.Git; | import org.eclipse.jgit.api.Git; | ||||
import org.eclipse.jgit.api.errors.JGitInternalException; | |||||
import org.eclipse.jgit.junit.JGitTestUtil; | import org.eclipse.jgit.junit.JGitTestUtil; | ||||
import org.eclipse.jgit.junit.TestRepository; | import org.eclipse.jgit.junit.TestRepository; | ||||
import org.eclipse.jgit.lfs.BuiltinLFS; | import org.eclipse.jgit.lfs.BuiltinLFS; | ||||
import org.eclipse.jgit.lfs.lib.Constants; | |||||
import org.eclipse.jgit.lfs.lib.LongObjectId; | import org.eclipse.jgit.lfs.lib.LongObjectId; | ||||
import org.eclipse.jgit.lib.ConfigConstants; | |||||
import org.eclipse.jgit.lib.Repository; | import org.eclipse.jgit.lib.Repository; | ||||
import org.eclipse.jgit.lib.StoredConfig; | import org.eclipse.jgit.lib.StoredConfig; | ||||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; | import org.eclipse.jgit.storage.file.FileRepositoryBuilder; | ||||
.create(tmp.resolve(".git").toFile()); | .create(tmp.resolve(".git").toFile()); | ||||
db.create(); | db.create(); | ||||
StoredConfig cfg = db.getConfig(); | StoredConfig cfg = db.getConfig(); | ||||
cfg.setString("filter", "lfs", "usejgitbuiltin", "true"); | |||||
cfg.setString("lfs", null, "url", server.getURI().toString() + "/lfs"); | |||||
cfg.setBoolean(ConfigConstants.CONFIG_FILTER_SECTION, Constants.LFS, | |||||
ConfigConstants.CONFIG_KEY_USEJGITBUILTIN, true); | |||||
cfg.setBoolean(ConfigConstants.CONFIG_FILTER_SECTION, Constants.LFS, | |||||
ConfigConstants.CONFIG_KEY_REQUIRED, false); | |||||
cfg.setString(Constants.LFS, null, "url", | |||||
server.getURI().toString() + "/lfs"); | |||||
cfg.save(); | cfg.save(); | ||||
tdb = new TestRepository<>(db); | tdb = new TestRepository<>(db); | ||||
server.getRequests().toString()); | server.getRequests().toString()); | ||||
} | } | ||||
@Test(expected = JGitInternalException.class) | |||||
public void testUnknownContentRequired() throws Exception { | |||||
StoredConfig cfg = tdb.getRepository().getConfig(); | |||||
cfg.setBoolean(ConfigConstants.CONFIG_FILTER_SECTION, Constants.LFS, | |||||
ConfigConstants.CONFIG_KEY_REQUIRED, true); | |||||
cfg.save(); | |||||
// must throw | |||||
git.checkout().setName("test").call(); | |||||
} | |||||
@Test | @Test | ||||
public void testKnownContent() throws Exception { | public void testKnownContent() throws Exception { | ||||
putContent( | putContent( |
invalidLongId=Invalid id: {0} | invalidLongId=Invalid id: {0} | ||||
invalidLongIdLength=Invalid id length {0}; should be {1} | invalidLongIdLength=Invalid id length {0}; should be {1} | ||||
lfsUnavailable=LFS is not available for repository {0} | lfsUnavailable=LFS is not available for repository {0} | ||||
protocolError=LFS Protocol Error {0}: {1} | |||||
requiredHashFunctionNotAvailable=Required hash function {0} not available. | requiredHashFunctionNotAvailable=Required hash function {0} not available. | ||||
repositoryNotFound=Repository {0} not found | repositoryNotFound=Repository {0} not found | ||||
repositoryReadOnly=Repository {0} is read-only | repositoryReadOnly=Repository {0} is read-only |
Protocol.Response resp = gson.fromJson(reader, | Protocol.Response resp = gson.fromJson(reader, | ||||
Protocol.Response.class); | Protocol.Response.class); | ||||
for (Protocol.ObjectInfo o : resp.objects) { | for (Protocol.ObjectInfo o : resp.objects) { | ||||
if (o.error != null) { | |||||
throw new IOException( | |||||
MessageFormat.format(LfsText.get().protocolError, | |||||
o.error.code, o.error.message)); | |||||
} | |||||
if (o.actions == null) { | if (o.actions == null) { | ||||
continue; | continue; | ||||
} | } |
/***/ public String invalidLongId; | /***/ public String invalidLongId; | ||||
/***/ public String invalidLongIdLength; | /***/ public String invalidLongIdLength; | ||||
/***/ public String lfsUnavailable; | /***/ public String lfsUnavailable; | ||||
/***/ public String protocolError; | |||||
/***/ public String requiredHashFunctionNotAvailable; | /***/ public String requiredHashFunctionNotAvailable; | ||||
/***/ public String repositoryNotFound; | /***/ public String repositoryNotFound; | ||||
/***/ public String repositoryReadOnly; | /***/ public String repositoryReadOnly; |
* @throws java.lang.Exception | * @throws java.lang.Exception | ||||
*/ | */ | ||||
public static void main(final String[] argv) throws Exception { | public static void main(final String[] argv) throws Exception { | ||||
// make sure built-in filters are registered | |||||
BuiltinLFS.register(); | |||||
new Main().run(argv); | new Main().run(argv); | ||||
} | } | ||||
import org.eclipse.jgit.errors.MissingObjectException; | import org.eclipse.jgit.errors.MissingObjectException; | ||||
import org.eclipse.jgit.events.WorkingTreeModifiedEvent; | import org.eclipse.jgit.events.WorkingTreeModifiedEvent; | ||||
import org.eclipse.jgit.internal.JGitText; | import org.eclipse.jgit.internal.JGitText; | ||||
import org.eclipse.jgit.lib.ConfigConstants; | |||||
import org.eclipse.jgit.lib.Constants; | import org.eclipse.jgit.lib.Constants; | ||||
import org.eclipse.jgit.lib.CoreConfig.AutoCRLF; | import org.eclipse.jgit.lib.CoreConfig.AutoCRLF; | ||||
import org.eclipse.jgit.lib.CoreConfig.EolStreamType; | import org.eclipse.jgit.lib.CoreConfig.EolStreamType; | ||||
private static void runBuiltinFilterCommand(Repository repo, | private static void runBuiltinFilterCommand(Repository repo, | ||||
CheckoutMetadata checkoutMetadata, ObjectLoader ol, | CheckoutMetadata checkoutMetadata, ObjectLoader ol, | ||||
OutputStream channel) throws MissingObjectException, IOException { | OutputStream channel) throws MissingObjectException, IOException { | ||||
boolean isMandatory = repo.getConfig().getBoolean( | |||||
ConfigConstants.CONFIG_FILTER_SECTION, "lfs", | |||||
ConfigConstants.CONFIG_KEY_REQUIRED, false); | |||||
FilterCommand command = null; | FilterCommand command = null; | ||||
try { | try { | ||||
command = FilterCommandRegistry.createFilterCommand( | command = FilterCommandRegistry.createFilterCommand( | ||||
channel); | channel); | ||||
} catch (IOException e) { | } catch (IOException e) { | ||||
LOG.error(JGitText.get().failedToDetermineFilterDefinition, e); | LOG.error(JGitText.get().failedToDetermineFilterDefinition, e); | ||||
// In case an IOException occurred during creating of the command | |||||
// then proceed as if there would not have been a builtin filter. | |||||
ol.copyTo(channel); | |||||
if (!isMandatory) { | |||||
// In case an IOException occurred during creating of the | |||||
// command then proceed as if there would not have been a | |||||
// builtin filter (only if the filter is not mandatory). | |||||
ol.copyTo(channel); | |||||
} else { | |||||
throw e; | |||||
} | |||||
} | } | ||||
if (command != null) { | if (command != null) { | ||||
while (command.run() != -1) { | while (command.run() != -1) { |