mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-12-24 01:09:48 +01:00
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:
@@ -7,6 +7,8 @@ import java.util.List;
|
|||||||
|
|
||||||
public class InternalRepositoryException extends ExceptionWithContext {
|
public class InternalRepositoryException extends ExceptionWithContext {
|
||||||
|
|
||||||
|
public static final String CODE = "8LRncum0S1";
|
||||||
|
|
||||||
public InternalRepositoryException(ContextEntry.ContextBuilder context, String message) {
|
public InternalRepositoryException(ContextEntry.ContextBuilder context, String message) {
|
||||||
this(context, message, null);
|
this(context, message, null);
|
||||||
}
|
}
|
||||||
@@ -29,6 +31,6 @@ public class InternalRepositoryException extends ExceptionWithContext {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCode() {
|
public String getCode() {
|
||||||
return null;
|
return CODE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ import org.eclipse.jgit.lib.ObjectId;
|
|||||||
import org.eclipse.jgit.lib.Ref;
|
import org.eclipse.jgit.lib.Ref;
|
||||||
import org.eclipse.jgit.lib.Repository;
|
import org.eclipse.jgit.lib.Repository;
|
||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import sonia.scm.repository.GitUtil;
|
import sonia.scm.repository.GitUtil;
|
||||||
@@ -55,6 +57,8 @@ import sonia.scm.repository.util.WorkingCopy;
|
|||||||
import sonia.scm.user.User;
|
import sonia.scm.user.User;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
@@ -255,10 +259,24 @@ class AbstractGitCommand
|
|||||||
|
|
||||||
void push() {
|
void push() {
|
||||||
try {
|
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) {
|
} catch (GitAPIException e) {
|
||||||
throw new IntegrateChangesFromWorkdirException(repository,
|
throw new InternalRepositoryException(repository, "could not push changes into central repository", e);
|
||||||
"could not push changes into central repository", e);
|
|
||||||
}
|
}
|
||||||
logger.debug("pushed changes");
|
logger.debug("pushed changes");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,8 +165,8 @@
|
|||||||
"description": "Die eingegebenen Daten konnten nicht validiert werden. Bitte korrigieren Sie die Eingaben und senden Sie sie erneut."
|
"description": "Die eingegebenen Daten konnten nicht validiert werden. Bitte korrigieren Sie die Eingaben und senden Sie sie erneut."
|
||||||
},
|
},
|
||||||
"CHRM7IQzo1": {
|
"CHRM7IQzo1": {
|
||||||
"displayName": "Änderung fehlgeschlagen",
|
"displayName": "Änderung des Repositories nicht möglich",
|
||||||
"description": "Die Änderung ist fehlgeschlagen. Bitte wenden Sie sich an ihren Administrator für weitere Hinweise."
|
"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": {
|
"thbsUFokjk": {
|
||||||
"displayName": "Unerlaubte Änderung eines Schlüsselwerts",
|
"displayName": "Unerlaubte Änderung eines Schlüsselwerts",
|
||||||
@@ -195,6 +195,10 @@
|
|||||||
"1yRiASshD1": {
|
"1yRiASshD1": {
|
||||||
"displayName": "Fehler beim Löschen des anonymen Nutzers",
|
"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."
|
"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": {
|
"namespaceStrategies": {
|
||||||
|
|||||||
@@ -165,8 +165,8 @@
|
|||||||
"description": "The values could not be validated. Please correct your input and try again."
|
"description": "The values could not be validated. Please correct your input and try again."
|
||||||
},
|
},
|
||||||
"CHRM7IQzo1": {
|
"CHRM7IQzo1": {
|
||||||
"displayName": "Change failed",
|
"displayName": "Could not modify repository",
|
||||||
"description": "The change failed. Please contact your administrator for further assistance."
|
"description": "The requested modification to the repository was rejected. Most probably this was due to plugins with repository hooks or native hooks."
|
||||||
},
|
},
|
||||||
"thbsUFokjk": {
|
"thbsUFokjk": {
|
||||||
"displayName": "Illegal change of an identifier",
|
"displayName": "Illegal change of an identifier",
|
||||||
@@ -195,6 +195,10 @@
|
|||||||
"1yRiASshD1": {
|
"1yRiASshD1": {
|
||||||
"displayName": "Error deleting the anonymous user",
|
"displayName": "Error deleting the anonymous user",
|
||||||
"description": "The anonymous user cannot be deleted since the anonymous access is still enabled in the configuration."
|
"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": {
|
"namespaceStrategies": {
|
||||||
|
|||||||
Reference in New Issue
Block a user