mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 22:45:45 +01:00
Git diff request correctly throws NotFoundException if target revision is non-existent (#2141)
Sometimes it happens that a git diff command request is performed with a non-existent target branch. This is usually fine but the underlying system might have already garbage-collected the revisions associated with that branch. In this case, the revision for that deleted branch might turn up null which currently causes a 500 error. We catch this specific corner-case and throw the correct NotFoundException instead.
This commit is contained in:
committed by
GitHub
parent
8a0686459d
commit
96ce4cb8e6
@@ -37,14 +37,15 @@ import org.eclipse.jgit.treewalk.AbstractTreeIterator;
|
||||
import org.eclipse.jgit.treewalk.EmptyTreeIterator;
|
||||
import org.eclipse.jgit.treewalk.TreeWalk;
|
||||
import org.eclipse.jgit.treewalk.filter.PathFilter;
|
||||
import sonia.scm.ContextEntry;
|
||||
import sonia.scm.NotFoundException;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
||||
import static sonia.scm.NotFoundException.notFound;
|
||||
|
||||
final class Differ implements AutoCloseable {
|
||||
|
||||
private final RevWalk walk;
|
||||
@@ -70,13 +71,13 @@ final class Differ implements AutoCloseable {
|
||||
|
||||
ObjectId revision = repository.resolve(request.getRevision());
|
||||
if (revision == null) {
|
||||
throw NotFoundException.notFound(ContextEntry.ContextBuilder.entity("revision not found", request.getRevision()));
|
||||
throw notFound(entity("Revision", request.getRevision()));
|
||||
}
|
||||
RevCommit commit;
|
||||
try {
|
||||
commit = walk.parseCommit(revision);
|
||||
} catch (MissingObjectException ex) {
|
||||
throw NotFoundException.notFound(ContextEntry.ContextBuilder.entity("revision not found", request.getRevision()));
|
||||
throw notFound(entity("Revision", request.getRevision()));
|
||||
}
|
||||
|
||||
walk.markStart(commit);
|
||||
@@ -92,6 +93,9 @@ final class Differ implements AutoCloseable {
|
||||
|
||||
if (!Strings.isNullOrEmpty(request.getAncestorChangeset())) {
|
||||
ObjectId otherRevision = repository.resolve(request.getAncestorChangeset());
|
||||
if (otherRevision == null) {
|
||||
throw notFound(entity("Revision", request.getAncestorChangeset()));
|
||||
}
|
||||
ObjectId ancestorId = GitUtil.computeCommonAncestor(repository, revision, otherRevision);
|
||||
RevTree tree = walk.parseCommit(ancestorId).getTree();
|
||||
treeWalk.addTree(tree);
|
||||
|
||||
Reference in New Issue
Block a user