mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-06 13:35:44 +01:00
Create error response for already existing entities
This commit is contained in:
@@ -307,7 +307,7 @@ public class GitBrowseCommand extends AbstractGitCommand
|
||||
return Strings.isNullOrEmpty(request.getPath()) || "/".equals(request.getPath());
|
||||
}
|
||||
|
||||
private FileObject findChildren(FileObject parent, org.eclipse.jgit.lib.Repository repo, BrowseCommandRequest request, ObjectId revId, TreeWalk treeWalk) throws IOException, NotFoundException {
|
||||
private FileObject findChildren(FileObject parent, org.eclipse.jgit.lib.Repository repo, BrowseCommandRequest request, ObjectId revId, TreeWalk treeWalk) throws IOException {
|
||||
List<FileObject> files = Lists.newArrayList();
|
||||
while (treeWalk.next())
|
||||
{
|
||||
@@ -335,7 +335,7 @@ public class GitBrowseCommand extends AbstractGitCommand
|
||||
}
|
||||
|
||||
private FileObject findFirstMatch(org.eclipse.jgit.lib.Repository repo,
|
||||
BrowseCommandRequest request, ObjectId revId, TreeWalk treeWalk) throws IOException, NotFoundException {
|
||||
BrowseCommandRequest request, ObjectId revId, TreeWalk treeWalk) throws IOException {
|
||||
String[] pathElements = request.getPath().split("/");
|
||||
int currentDepth = 0;
|
||||
int limit = pathElements.length;
|
||||
|
||||
@@ -44,7 +44,6 @@ import org.eclipse.jgit.treewalk.TreeWalk;
|
||||
import org.eclipse.jgit.treewalk.filter.PathFilter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.NotFoundException;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
@@ -54,6 +53,9 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
||||
import static sonia.scm.NotFoundException.notFound;
|
||||
|
||||
|
||||
public class GitCatCommand extends AbstractGitCommand implements CatCommand {
|
||||
|
||||
@@ -101,7 +103,7 @@ public class GitCatCommand extends AbstractGitCommand implements CatCommand {
|
||||
try {
|
||||
entry = revWalk.parseCommit(revId);
|
||||
} catch (MissingObjectException e) {
|
||||
throw NotFoundException.notFound("Revision", revId.getName()).in(repository).build();
|
||||
throw notFound(entity("Revision", revId.getName()).in(repository));
|
||||
}
|
||||
RevTree revTree = entry.getTree();
|
||||
|
||||
@@ -119,7 +121,7 @@ public class GitCatCommand extends AbstractGitCommand implements CatCommand {
|
||||
|
||||
return new ClosableObjectLoaderContainer(loader, treeWalk, revWalk);
|
||||
} else {
|
||||
throw NotFoundException.notFound("Path", path).in("Revision", revId.getName()).in(repository).build();
|
||||
throw notFound(entity("Path", path).in("Revision", revId.getName()).in(repository));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,6 @@ import org.eclipse.jgit.treewalk.filter.PathFilter;
|
||||
import org.eclipse.jgit.treewalk.filter.TreeFilter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.NotFoundException;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.GitChangesetConverter;
|
||||
@@ -61,6 +60,9 @@ import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
||||
import static sonia.scm.NotFoundException.notFound;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -248,7 +250,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
}
|
||||
catch (MissingObjectException e)
|
||||
{
|
||||
throw NotFoundException.notFound("Revision", e.getObjectId().getName()).in(repository).build();
|
||||
throw notFound(entity("Revision", e.getObjectId().getName()).in(repository));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import org.junit.Test;
|
||||
import sonia.scm.NotFoundException;
|
||||
import sonia.scm.repository.BrowserResult;
|
||||
import sonia.scm.repository.FileObject;
|
||||
import sonia.scm.repository.GitConstants;
|
||||
@@ -63,7 +62,7 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultDefaultBranch() throws IOException, NotFoundException {
|
||||
public void testDefaultDefaultBranch() throws IOException {
|
||||
// without default branch, the repository head should be used
|
||||
FileObject root = createCommand().getBrowserResult(new BrowseCommandRequest()).getFile();
|
||||
assertNotNull(root);
|
||||
@@ -78,7 +77,7 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExplicitDefaultBranch() throws IOException, NotFoundException {
|
||||
public void testExplicitDefaultBranch() throws IOException {
|
||||
repository.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "test-branch");
|
||||
|
||||
FileObject root = createCommand().getBrowserResult(new BrowseCommandRequest()).getFile();
|
||||
|
||||
Reference in New Issue
Block a user