Merged in bugfix/show_error_on_missing_branch (pull request #213)

fix there is no error on missing revision
This commit is contained in:
René Pfeuffer
2019-03-12 15:37:33 +00:00
14 changed files with 40 additions and 32 deletions

View File

@@ -77,7 +77,7 @@ public final class HookEventFacade
Repository repository = repositoryManagerProvider.get().get(id);
if (repository == null)
{
throw notFound(entity("repository", id));
throw notFound(entity("Repository", id));
}
return handle(repository);
}

View File

@@ -205,7 +205,7 @@ public final class GitUtil
}
catch (GitAPIException ex)
{
throw new InternalRepositoryException(ContextEntry.ContextBuilder.entity("remote", directory.toString()).in(remoteRepository), "could not fetch", ex);
throw new InternalRepositoryException(ContextEntry.ContextBuilder.entity("Remote", directory.toString()).in(remoteRepository), "could not fetch", ex);
}
}

View File

@@ -110,7 +110,7 @@ public class GitBlameCommand extends AbstractGitCommand implements BlameCommand
if (gitBlameResult == null)
{
throw new InternalRepositoryException(entity("path", request.getPath()).in(repository),
throw new InternalRepositoryException(entity("Path", request.getPath()).in(repository),
"could not create blame result for path");
}

View File

@@ -65,6 +65,9 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import static sonia.scm.ContextEntry.ContextBuilder.entity;
import static sonia.scm.NotFoundException.notFound;
//~--- JDK imports ------------------------------------------------------------
/**
@@ -128,10 +131,11 @@ public class GitBrowseCommand extends AbstractGitCommand
if (Util.isNotEmpty(request.getRevision()))
{
logger.error("could not find revision {}", request.getRevision());
throw notFound(entity("Revision", request.getRevision()).in(this.repository));
}
else if (logger.isWarnEnabled())
{
logger.warn("coul not find head of repository, empty?");
logger.warn("could not find head of repository, empty?");
}
result = new BrowserResult(Constants.HEAD, createEmtpyRoot());
@@ -354,7 +358,7 @@ public class GitBrowseCommand extends AbstractGitCommand
}
}
throw new NotFoundException("file", request.getPath());
throw notFound(entity("File", request.getPath()).in("Revision", revId.getName()).in(this.repository));
}
@SuppressWarnings("unchecked")

View File

@@ -43,7 +43,6 @@ import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.revwalk.filter.RevFilter;
import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
import org.eclipse.jgit.treewalk.filter.PathFilter;
import org.eclipse.jgit.treewalk.filter.TreeFilter;
@@ -79,6 +78,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
*/
private static final Logger logger =
LoggerFactory.getLogger(GitLogCommand.class);
public static final String REVISION = "Revision";
//~--- constructors ---------------------------------------------------------
@@ -143,6 +143,10 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
{
logger.error("could not open repository", ex);
}
catch (NullPointerException e)
{
throw notFound(entity(REVISION, revision).in(this.repository));
}
finally
{
IOUtil.close(converter);
@@ -208,7 +212,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
if (!Strings.isNullOrEmpty(request.getAncestorChangeset())) {
ancestorId = repository.resolve(request.getAncestorChangeset());
if (ancestorId == null) {
throw notFound(entity("Revision", request.getAncestorChangeset()).in(this.repository));
throw notFound(entity(REVISION, request.getAncestorChangeset()).in(this.repository));
}
}
@@ -250,7 +254,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
}
}
} else if (ancestorId != null) {
throw notFound(entity("Revision", request.getBranch()).in(this.repository));
throw notFound(entity(REVISION, request.getBranch()).in(this.repository));
}
if (branch != null) {
@@ -267,7 +271,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
}
catch (MissingObjectException e)
{
throw notFound(entity("Revision", e.getObjectId().getName()).in(repository));
throw notFound(entity(REVISION, e.getObjectId().getName()).in(repository));
}
catch (NotFoundException e)
{
@@ -285,17 +289,4 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
return changesets;
}
private ObjectId computeCommonAncestor(LogCommandRequest request, Repository repository, ObjectId startId, Ref branch) throws IOException {
try (RevWalk mergeBaseWalk = new RevWalk(repository)) {
mergeBaseWalk.setRevFilter(RevFilter.MERGE_BASE);
if (startId != null) {
mergeBaseWalk.markStart(mergeBaseWalk.lookupCommit(startId));
} else {
mergeBaseWalk.markStart(mergeBaseWalk.lookupCommit(branch.getObjectId()));
}
mergeBaseWalk.markStart(mergeBaseWalk.parseCommit(repository.resolve(request.getAncestorChangeset())));
return mergeBaseWalk.next().getId();
}
}
}

View File

@@ -74,7 +74,7 @@ public class GitMergeCommand extends AbstractGitCommand implements MergeCommand
private ObjectId resolveRevisionOrThrowNotFound(Repository repository, String revision) throws IOException {
ObjectId resolved = repository.resolve(revision);
if (resolved == null) {
throw notFound(entity("revision", revision).in(context.getRepository()));
throw notFound(entity("Revision", revision).in(context.getRepository()));
} else {
return resolved;
}
@@ -125,7 +125,7 @@ public class GitMergeCommand extends AbstractGitCommand implements MergeCommand
clone.checkout().setStartPoint(targetRevision.getName()).setName(target).setCreateBranch(true).call();
} catch (RefNotFoundException e) {
logger.debug("could not checkout target branch {} for merge as local branch", target, e);
throw notFound(entity("revision", target).in(context.getRepository()));
throw notFound(entity("Revision", target).in(context.getRepository()));
} catch (GitAPIException e) {
throw new InternalRepositoryException(context.getRepository(), "could not checkout target branch for merge as local branch: " + target, e);
}

View File

@@ -349,7 +349,7 @@ public class HgRepositoryHandler
try {
return new INIConfigurationReader().read(new File(directory, PATH_HGRC)).getSection(CONFIG_SECTION_SCMM).getParameter(CONFIG_KEY_REPOSITORY_ID);
} catch (IOException e) {
throw new InternalRepositoryException(ContextEntry.ContextBuilder.entity("directory", directory.toString()), "could not read scm configuration file", e);
throw new InternalRepositoryException(ContextEntry.ContextBuilder.entity("Directory", directory.toString()), "could not read scm configuration file", e);
}
}

View File

@@ -234,7 +234,7 @@ public class SvnRepositoryHandler
try {
return new INIConfigurationReader().read(new File(directory, CONFIG_FILE_NAME)).getSection(CONFIG_SECTION_SCMM).getParameter(CONFIG_KEY_REPOSITORY_ID);
} catch (IOException e) {
throw new InternalRepositoryException(ContextEntry.ContextBuilder.entity("directory", directory.toString()), "could not read scm configuration file", e);
throw new InternalRepositoryException(ContextEntry.ContextBuilder.entity("Directory", directory.toString()), "could not read scm configuration file", e);
}
}
}

View File

@@ -53,6 +53,10 @@ import sonia.scm.util.Util;
import java.util.Collection;
import static org.tmatesoft.svn.core.SVNErrorCode.FS_NO_SUCH_REVISION;
import static sonia.scm.ContextEntry.ContextBuilder.entity;
import static sonia.scm.NotFoundException.notFound;
//~--- JDK imports ------------------------------------------------------------
/**
@@ -107,6 +111,9 @@ public class SvnBrowseCommand extends AbstractSvnCommand
}
catch (SVNException ex)
{
if (FS_NO_SUCH_REVISION.equals(ex.getErrorMessage().getErrorCode())) {
throw notFound(entity("Revision", Long.toString(revisionNumber)).in(this.repository));
}
logger.error("could not open repository", ex);
}
@@ -153,6 +160,9 @@ public class SvnBrowseCommand extends AbstractSvnCommand
private FileObject createFileObject(BrowseCommandRequest request,
SVNRepository repository, long revision, SVNDirEntry entry, String path)
{
if (entry == null) {
throw notFound(entity("Path", path).in("Revision", Long.toString(revision)).in(this.repository));
}
FileObject fileObject = new FileObject();
fileObject.setName(entry.getName());

View File

@@ -85,7 +85,7 @@ public class FileHistoryRootResource {
} else {
String message = String.format("for the revision %s and the file %s there are no changesets", revision, path);
log.error(message);
throw notFound(entity("path", path).in("revision", revision).in(namespaceAndName));
throw notFound(entity("Path", path).in("revision", revision).in(namespaceAndName));
}
}
}

View File

@@ -258,7 +258,7 @@ public class RepositoryPermissionRootResource {
*/
private void checkPermissionAlreadyExists(RepositoryPermissionDto permission, Repository repository) {
if (isPermissionExist(permission, repository)) {
throw alreadyExists(entity("permission", permission.getName()).in(repository));
throw alreadyExists(entity("Permission", permission.getName()).in(repository));
}
}

View File

@@ -15,6 +15,9 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import java.io.IOException;
import static sonia.scm.ContextEntry.ContextBuilder.entity;
import static sonia.scm.NotFoundException.notFound;
public class SourceRootResource {
private final RepositoryServiceFactory serviceFactory;
@@ -62,7 +65,7 @@ public class SourceRootResource {
if (browserResult != null) {
return Response.ok(browserResultToFileObjectDtoMapper.map(browserResult, namespaceAndName)).build();
} else {
return Response.status(Response.Status.NOT_FOUND).build();
throw notFound(entity("Source", path).in("Revision", revision).in(namespaceAndName));
}
}
}

View File

@@ -77,7 +77,7 @@ public class PermissionAssigner {
private Predicate<PermissionDescriptor> permissionExists(Collection<PermissionDescriptor> availablePermissions, Collection<AssignedPermission> existingPermissions) {
return p -> {
if (!availablePermissions.contains(p) && existingPermissions.stream().map(AssignedPermission::getPermission).noneMatch(e -> e.equals(p))) {
throw NotFoundException.notFound(ContextEntry.ContextBuilder.entity("permission", p.getValue()));
throw NotFoundException.notFound(ContextEntry.ContextBuilder.entity("Permission", p.getValue()));
}
return true;
};

View File

@@ -403,7 +403,7 @@ public class DefaultUserManager extends AbstractUserManager
User user = get((String) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal());
if (!user.getPassword().equals(oldPassword)) {
throw new InvalidPasswordException(ContextEntry.ContextBuilder.entity("passwordChange", "-").in(User.class, user.getName()));
throw new InvalidPasswordException(ContextEntry.ContextBuilder.entity("PasswordChange", "-").in(User.class, user.getName()));
}
user.setPassword(newPassword);
@@ -422,7 +422,7 @@ public class DefaultUserManager extends AbstractUserManager
throw new NotFoundException(User.class, userId);
}
if (!isTypeDefault(user)) {
throw new ChangePasswordNotAllowedException(ContextEntry.ContextBuilder.entity("passwordChange", "-").in(User.class, user.getName()), user.getType());
throw new ChangePasswordNotAllowedException(ContextEntry.ContextBuilder.entity("PasswordChange", "-").in(User.class, user.getName()), user.getType());
}
user.setPassword(newPassword);
this.modify(user);