Create and handle RevisionNotFoundException

This commit is contained in:
René Pfeuffer
2018-08-16 10:24:47 +02:00
parent 70039ad540
commit 9babeecea6
4 changed files with 36 additions and 2 deletions

View File

@@ -32,6 +32,7 @@
package sonia.scm.repository.spi;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
@@ -46,6 +47,7 @@ import org.slf4j.LoggerFactory;
import sonia.scm.repository.GitUtil;
import sonia.scm.repository.PathNotFoundException;
import sonia.scm.repository.RepositoryException;
import sonia.scm.repository.RevisionNotFoundException;
import sonia.scm.util.Util;
import java.io.Closeable;
@@ -97,7 +99,12 @@ public class GitCatCommand extends AbstractGitCommand implements CatCommand {
RevWalk revWalk = new RevWalk(repo);
RevCommit entry = revWalk.parseCommit(revId);
RevCommit entry = null;
try {
entry = revWalk.parseCommit(revId);
} catch (MissingObjectException e) {
throw new RevisionNotFoundException(revId.getName());
}
RevTree revTree = entry.getTree();
if (revTree != null) {

View File

@@ -36,6 +36,7 @@ import org.junit.Test;
import sonia.scm.repository.GitConstants;
import sonia.scm.repository.PathNotFoundException;
import sonia.scm.repository.RepositoryException;
import sonia.scm.repository.RevisionNotFoundException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -90,6 +91,15 @@ public class GitCatCommandTest extends AbstractGitCommandTestBase {
execute(request);
}
@Test(expected = RevisionNotFoundException.class)
public void testUnknownRevision() throws IOException, RepositoryException {
CatCommandRequest request = new CatCommandRequest();
request.setRevision("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
request.setPath("a.txt");
execute(request);
}
@Test
public void testSimpleStream() throws IOException, RepositoryException {
CatCommandRequest request = new CatCommandRequest();