mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
Not unique revisions on compare (#1974)
* Throw more specific exception if compared revisions are ambiguous. * Add changelog entry * Move changelog entry in intended folder * Small typo Co-authored-by: Florian Scholdei <florian.scholdei@cloudogu.com>
This commit is contained in:
2
gradle/changelog/not_unique_compare.yaml
Normal file
2
gradle/changelog/not_unique_compare.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
- type: fixed
|
||||
description: Throw more specific exception if compared revisions are ambiguous ([#1974](https://github.com/scm-manager/scm-manager/pull/1974))
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
public class NotUniqueRevisionException extends ExceptionWithContext {
|
||||
|
||||
private static final long serialVersionUID = 1710455380886499111L;
|
||||
|
||||
private static final String CODE = "9tSzgRvIu1";
|
||||
|
||||
public NotUniqueRevisionException(Class<?> type, String id) {
|
||||
this(Collections.singletonList(new ContextEntry(type, id)));
|
||||
}
|
||||
|
||||
public NotUniqueRevisionException(String type, String id) {
|
||||
this(Collections.singletonList(new ContextEntry(type, id)));
|
||||
}
|
||||
|
||||
public static NotUniqueRevisionException notUniqueIdentifier(ContextEntry.ContextBuilder contextBuilder) {
|
||||
return new NotUniqueRevisionException(contextBuilder.build());
|
||||
}
|
||||
|
||||
private NotUniqueRevisionException(List<ContextEntry> context) {
|
||||
super(context, createMessage(context));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return CODE;
|
||||
}
|
||||
|
||||
private static String createMessage(List<ContextEntry> context) {
|
||||
return context.stream()
|
||||
.map(c -> c.getType().toLowerCase() + " with id " + c.getId())
|
||||
.collect(joining(" in ", "Not unique identifier ", ""));
|
||||
}
|
||||
}
|
||||
@@ -26,8 +26,11 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import org.eclipse.jgit.diff.DiffEntry;
|
||||
import org.eclipse.jgit.diff.DiffFormatter;
|
||||
import org.eclipse.jgit.errors.AmbiguousObjectException;
|
||||
import sonia.scm.NotUniqueRevisionException;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.api.DiffFile;
|
||||
import sonia.scm.repository.api.DiffResult;
|
||||
import sonia.scm.repository.api.Hunk;
|
||||
@@ -58,7 +61,11 @@ public class GitDiffResultCommand extends AbstractGitCommand implements DiffResu
|
||||
public DiffResult getDiffResult(DiffResultCommandRequest request) throws IOException {
|
||||
org.eclipse.jgit.lib.Repository repository = open();
|
||||
int offset = request.getOffset() == null ? 0 : request.getOffset();
|
||||
return new GitDiffResult(repository, Differ.diff(repository, request), offset, request.getLimit());
|
||||
try {
|
||||
return new GitDiffResult(repository, Differ.diff(repository, request), offset, request.getLimit());
|
||||
} catch (AmbiguousObjectException ex) {
|
||||
throw new NotUniqueRevisionException(Repository.class, context.getRepository().getId());
|
||||
}
|
||||
}
|
||||
|
||||
private class GitDiffResult implements DiffResult {
|
||||
|
||||
@@ -195,6 +195,10 @@
|
||||
"displayName": "Nicht gefunden",
|
||||
"description": "Der gewünschte Datensatz konnte nicht gefunden werden. Möglicherweise wurde er in einer weiteren Session gelöscht."
|
||||
},
|
||||
"9tSzgRvIu1": {
|
||||
"displayName": "Revision nicht einzigartig",
|
||||
"description": "Es gab mehrere Treffer zu dieser Revision. Bitte nutzen Sie eine eindeutige Id."
|
||||
},
|
||||
"FtR7UznKU1": {
|
||||
"displayName": "Existiert bereits",
|
||||
"description": "Ein Datensatz mit den gegebenen Schlüsselwerten existiert bereits."
|
||||
@@ -209,7 +213,7 @@
|
||||
},
|
||||
"2wR7UzpPG1": {
|
||||
"displayName": "Konkurrierende Änderungen",
|
||||
"description": "Der Datensatz wurde konkurrierend von einem anderen Benutzer oder einem anderen Prozess modifiziert. Bitte laden sie die Daten erneut."
|
||||
"description": "Der Datensatz wurde konkurrierend von einem anderen Benutzer oder einem anderen Prozess modifiziert. Bitte laden Sie die Daten erneut."
|
||||
},
|
||||
"9SR8G0kmU1": {
|
||||
"displayName": "Feature nicht unterstützt",
|
||||
|
||||
@@ -195,6 +195,10 @@
|
||||
"displayName": "Not found",
|
||||
"description": "The requested entity could not be found. It may have been deleted in another session."
|
||||
},
|
||||
"9tSzgRvIu1": {
|
||||
"displayName": "Not unique revision",
|
||||
"description": "This revision is ambiguous. Please use an unique identifier."
|
||||
},
|
||||
"FtR7UznKU1": {
|
||||
"displayName": "Already exists",
|
||||
"description": "There is already an entity with the same key values."
|
||||
|
||||
Reference in New Issue
Block a user