Fix error handling on git push

Failing git push does not lead to an GitAPIException. Instead we have to
check the dedicated push update results.

By the way this adds a message for the internal repository exception.
This commit is contained in:
Rene Pfeuffer
2020-01-15 08:49:14 +01:00
parent c7a6252e12
commit c5520e6b07
4 changed files with 38 additions and 10 deletions

View File

@@ -7,6 +7,8 @@ import java.util.List;
public class InternalRepositoryException extends ExceptionWithContext {
public static final String CODE = "8LRncum0S1";
public InternalRepositoryException(ContextEntry.ContextBuilder context, String message) {
this(context, message, null);
}
@@ -29,6 +31,6 @@ public class InternalRepositoryException extends ExceptionWithContext {
@Override
public String getCode() {
return null;
return CODE;
}
}

View File

@@ -45,6 +45,8 @@ import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.PushResult;
import org.eclipse.jgit.transport.RemoteRefUpdate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.repository.GitUtil;
@@ -55,6 +57,8 @@ import sonia.scm.repository.util.WorkingCopy;
import sonia.scm.user.User;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
@@ -255,10 +259,24 @@ class AbstractGitCommand
void push() {
try {
clone.push().call();
Iterable<PushResult> pushResult = clone.push().call();
Iterator<PushResult> pushResultIterator = pushResult.iterator();
if (!pushResultIterator.hasNext()) {
throw new InternalRepositoryException(repository, "got no result from push");
}
Collection<RemoteRefUpdate> remoteUpdates = pushResultIterator.next().getRemoteUpdates();
if (remoteUpdates.isEmpty()) {
throw new InternalRepositoryException(repository, "push created no update");
}
remoteUpdates
.stream()
.filter(remoteRefUpdate -> remoteRefUpdate.getStatus() != RemoteRefUpdate.Status.OK)
.findAny()
.ifPresent(remoteRefUpdate -> {
throw new IntegrateChangesFromWorkdirException(repository, "could not push changes into central repository: " + remoteRefUpdate.getStatus());
});
} catch (GitAPIException e) {
throw new IntegrateChangesFromWorkdirException(repository,
"could not push changes into central repository", e);
throw new InternalRepositoryException(repository, "could not push changes into central repository", e);
}
logger.debug("pushed changes");
}

View File

@@ -165,8 +165,8 @@
"description": "Die eingegebenen Daten konnten nicht validiert werden. Bitte korrigieren Sie die Eingaben und senden Sie sie erneut."
},
"CHRM7IQzo1": {
"displayName": "Änderung fehlgeschlagen",
"description": "Die Änderung ist fehlgeschlagen. Bitte wenden Sie sich an ihren Administrator für weitere Hinweise."
"displayName": "Änderung des Repositories nicht möglich",
"description": "Die gewünschte Änderung am Repository konnte nicht durchgeführt werden. Höchst wahrscheinlich liegt dieses an installierten Plugins mit Hooks oder nativen Hooks."
},
"thbsUFokjk": {
"displayName": "Unerlaubte Änderung eines Schlüsselwerts",
@@ -195,6 +195,10 @@
"1yRiASshD1": {
"displayName": "Fehler beim Löschen des anonymen Nutzers",
"description": "Der anonyme Nutzer kann nicht gelöscht werden, solange der anonyme Zugriff in den Einstellungen aktiviert ist."
},
"8LRncum0S1": {
"displayName": "Interner Fehler im Repository",
"description": "Bei der Bearbeitung des internen Repositories ist ein Fehler oder ein unerwarteter Zustand aufgetreten. Bitte prüfen Sie die Logs für weitere Informationen."
}
},
"namespaceStrategies": {

View File

@@ -165,8 +165,8 @@
"description": "The values could not be validated. Please correct your input and try again."
},
"CHRM7IQzo1": {
"displayName": "Change failed",
"description": "The change failed. Please contact your administrator for further assistance."
"displayName": "Could not modify repository",
"description": "The requested modification to the repository was rejected. Most probably this was due to plugins with repository hooks or native hooks."
},
"thbsUFokjk": {
"displayName": "Illegal change of an identifier",
@@ -195,6 +195,10 @@
"1yRiASshD1": {
"displayName": "Error deleting the anonymous user",
"description": "The anonymous user cannot be deleted since the anonymous access is still enabled in the configuration."
},
"8LRncum0S1": {
"displayName": "Internal repository error",
"description": "There was an error or an unexpected condition while handling the native repository. Please consult the logs for further information."
}
},
"namespaceStrategies": {