Merge branch 'stable-6.0'
* stable-6.0: Stop initCause throwing in readAdvertisedRefs Change-Id: I2266814c613fd81e9dfc722532ac3daa30ca66b5
This commit is contained in:
commit
94a4d30b95
|
@ -15,11 +15,15 @@
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
|
import static org.junit.Assert.assertThrows;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.EOFException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.eclipse.jgit.errors.NoRemoteRepositoryException;
|
||||||
import org.eclipse.jgit.lib.Constants;
|
import org.eclipse.jgit.lib.Constants;
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
import org.eclipse.jgit.lib.ObjectIdRef;
|
import org.eclipse.jgit.lib.ObjectIdRef;
|
||||||
|
@ -29,6 +33,16 @@
|
||||||
|
|
||||||
public class BasePackConnectionTest {
|
public class BasePackConnectionTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReadAdvertisedRefsShouldThrowExceptionWithOriginalCause() {
|
||||||
|
try (FailingBasePackConnection basePackConnection =
|
||||||
|
new FailingBasePackConnection()) {
|
||||||
|
Exception result = assertThrows(NoRemoteRepositoryException.class,
|
||||||
|
basePackConnection::readAdvertisedRefs);
|
||||||
|
assertEquals(EOFException.class, result.getCause().getClass());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateWithSymRefsAdds() {
|
public void testUpdateWithSymRefsAdds() {
|
||||||
final Ref mainRef = new ObjectIdRef.Unpeeled(Ref.Storage.LOOSE,
|
final Ref mainRef = new ObjectIdRef.Unpeeled(Ref.Storage.LOOSE,
|
||||||
|
@ -244,4 +258,12 @@ public void testUpdateWithSymRefsFillInHead() {
|
||||||
assertEquals(oidName, headRef.getObjectId().name());
|
assertEquals(oidName, headRef.getObjectId().name());
|
||||||
assertEquals(oidName, mainRef.getObjectId().name());
|
assertEquals(oidName, mainRef.getObjectId().name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private static class FailingBasePackConnection extends BasePackConnection {
|
||||||
|
FailingBasePackConnection() {
|
||||||
|
super(new TransportLocal(new URIish(),
|
||||||
|
new java.io.File("")));
|
||||||
|
pckIn = new PacketLineIn(new ByteArrayInputStream(new byte[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,96 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Darius Jokilehto <darius.jokilehto+os@gmail.com>
|
||||||
|
* Copyright (c) 2022 Antonio Barone <syntonyze@gmail.com>
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials are made available under the
|
||||||
|
* terms of the Eclipse Distribution License v. 1.0 which is available at
|
||||||
|
* https://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.eclipse.jgit.transport;
|
||||||
|
|
||||||
|
import org.eclipse.jgit.errors.NoRemoteRepositoryException;
|
||||||
|
import org.eclipse.jgit.errors.TransportException;
|
||||||
|
import org.eclipse.jgit.internal.JGitText;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.EOFException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.hamcrest.Matchers.endsWith;
|
||||||
|
import static org.hamcrest.Matchers.hasItem;
|
||||||
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertThrows;
|
||||||
|
|
||||||
|
public class BasePackPushConnectionTest {
|
||||||
|
@Test
|
||||||
|
public void testNoRemoteRepository() {
|
||||||
|
NoRemoteRepositoryException openFetchException =
|
||||||
|
new NoRemoteRepositoryException( new URIish(), "not found");
|
||||||
|
IOException ioException = new IOException("not read");
|
||||||
|
|
||||||
|
try (FailingBasePackPushConnection fbppc =
|
||||||
|
new FailingBasePackPushConnection(openFetchException)) {
|
||||||
|
TransportException result = fbppc.noRepository(ioException);
|
||||||
|
|
||||||
|
assertEquals(openFetchException, result);
|
||||||
|
assertThat(Arrays.asList(result.getSuppressed()),
|
||||||
|
hasItem(ioException));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPushNotPermitted() {
|
||||||
|
URIish uri = new URIish();
|
||||||
|
TransportException openFetchException = new TransportException(uri,
|
||||||
|
"a transport exception");
|
||||||
|
IOException ioException = new IOException("not read");
|
||||||
|
|
||||||
|
try (FailingBasePackPushConnection fbppc =
|
||||||
|
new FailingBasePackPushConnection(openFetchException)) {
|
||||||
|
TransportException result = fbppc.noRepository(ioException);
|
||||||
|
|
||||||
|
assertEquals(TransportException.class, result.getClass());
|
||||||
|
assertThat(result.getMessage(),
|
||||||
|
endsWith(JGitText.get().pushNotPermitted));
|
||||||
|
assertEquals(openFetchException, result.getCause());
|
||||||
|
assertThat(Arrays.asList(result.getSuppressed()),
|
||||||
|
hasItem(ioException));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReadAdvertisedRefPropagatesCauseAndSuppressedExceptions() {
|
||||||
|
IOException ioException = new IOException("not read");
|
||||||
|
try (FailingBasePackPushConnection basePackConnection =
|
||||||
|
new FailingBasePackPushConnection(
|
||||||
|
new NoRemoteRepositoryException(
|
||||||
|
new URIish(), "not found", ioException))) {
|
||||||
|
Exception result = assertThrows(NoRemoteRepositoryException.class,
|
||||||
|
basePackConnection::readAdvertisedRefs);
|
||||||
|
assertEquals(ioException, result.getCause());
|
||||||
|
assertThat(Arrays.asList(result.getSuppressed()),
|
||||||
|
hasItem(instanceOf(EOFException.class)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class FailingBasePackPushConnection
|
||||||
|
extends BasePackPushConnection {
|
||||||
|
FailingBasePackPushConnection(TransportException openFetchException) {
|
||||||
|
super(new TransportLocal(new URIish(),
|
||||||
|
new java.io.File("")) {
|
||||||
|
@Override public FetchConnection openFetch()
|
||||||
|
throws TransportException {
|
||||||
|
throw openFetchException;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
pckIn = new PacketLineIn(new ByteArrayInputStream(new byte[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<component id="org.eclipse.jgit" version="2">
|
||||||
|
<resource path="src/org/eclipse/jgit/errors/NoRemoteRepositoryException.java" type="org.eclipse.jgit.errors.NoRemoteRepositoryException">
|
||||||
|
<filter id="1141899266">
|
||||||
|
<message_arguments>
|
||||||
|
<message_argument value="5.13"/>
|
||||||
|
<message_argument value="6.1"/>
|
||||||
|
<message_argument value="NoRemoteRepositoryException(URIish, String, Throwable)"/>
|
||||||
|
</message_arguments>
|
||||||
|
</filter>
|
||||||
|
</resource>
|
||||||
|
<resource path="src/org/eclipse/jgit/transport/BasePackPushConnection.java" type="org.eclipse.jgit.transport.BasePackPushConnection">
|
||||||
|
<filter id="338792546">
|
||||||
|
<message_arguments>
|
||||||
|
<message_argument value="org.eclipse.jgit.transport.BasePackPushConnection"/>
|
||||||
|
<message_argument value="noRepository()"/>
|
||||||
|
</message_arguments>
|
||||||
|
</filter>
|
||||||
|
</resource>
|
||||||
|
</component>
|
|
@ -29,4 +29,19 @@ public class NoRemoteRepositoryException extends TransportException {
|
||||||
public NoRemoteRepositoryException(URIish uri, String s) {
|
public NoRemoteRepositoryException(URIish uri, String s) {
|
||||||
super(uri, s);
|
super(uri, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an exception indicating a repository does not exist.
|
||||||
|
*
|
||||||
|
* @param uri
|
||||||
|
* URI used for transport
|
||||||
|
* @param s
|
||||||
|
* message
|
||||||
|
* @param cause
|
||||||
|
* root cause exception
|
||||||
|
* @since 5.13
|
||||||
|
*/
|
||||||
|
public NoRemoteRepositoryException(URIish uri, String s, Throwable cause) {
|
||||||
|
super(uri, s, cause);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,9 +210,7 @@ private boolean readAdvertisedRefsImpl() throws IOException {
|
||||||
try {
|
try {
|
||||||
line = readLine();
|
line = readLine();
|
||||||
} catch (EOFException e) {
|
} catch (EOFException e) {
|
||||||
TransportException noRepo = noRepository();
|
throw noRepository(e);
|
||||||
noRepo.initCause(e);
|
|
||||||
throw noRepo;
|
|
||||||
}
|
}
|
||||||
if (line != null && VERSION_1.equals(line)) {
|
if (line != null && VERSION_1.equals(line)) {
|
||||||
// Same as V0, except for this extra line. We shouldn't get
|
// Same as V0, except for this extra line. We shouldn't get
|
||||||
|
@ -567,11 +565,14 @@ static void updateWithSymRefs(Map<String, Ref> refMap, Map<String, String> symRe
|
||||||
*
|
*
|
||||||
* Subclasses may override this method to provide better diagnostics.
|
* Subclasses may override this method to provide better diagnostics.
|
||||||
*
|
*
|
||||||
|
* @param cause
|
||||||
|
* root cause exception
|
||||||
* @return a TransportException saying a repository cannot be found and
|
* @return a TransportException saying a repository cannot be found and
|
||||||
* possibly why.
|
* possibly why.
|
||||||
*/
|
*/
|
||||||
protected TransportException noRepository() {
|
protected TransportException noRepository(Throwable cause) {
|
||||||
return new NoRemoteRepositoryException(uri, JGitText.get().notFound);
|
return new NoRemoteRepositoryException(uri, JGitText.get().notFound,
|
||||||
|
cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -139,7 +139,7 @@ public void push(final ProgressMonitor monitor,
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
protected TransportException noRepository() {
|
protected TransportException noRepository(Throwable cause) {
|
||||||
// Sadly we cannot tell the "invalid URI" case from "push not allowed".
|
// Sadly we cannot tell the "invalid URI" case from "push not allowed".
|
||||||
// Opening a fetch connection can help us tell the difference, as any
|
// Opening a fetch connection can help us tell the difference, as any
|
||||||
// useful repository is going to support fetch if it also would allow
|
// useful repository is going to support fetch if it also would allow
|
||||||
|
@ -147,18 +147,18 @@ protected TransportException noRepository() {
|
||||||
// URI is wrong. Otherwise we can correctly state push isn't allowed
|
// URI is wrong. Otherwise we can correctly state push isn't allowed
|
||||||
// as the fetch connection opened successfully.
|
// as the fetch connection opened successfully.
|
||||||
//
|
//
|
||||||
|
TransportException te;
|
||||||
try {
|
try {
|
||||||
transport.openFetch().close();
|
transport.openFetch().close();
|
||||||
} catch (NotSupportedException e) {
|
te = new TransportException(uri, JGitText.get().pushNotPermitted);
|
||||||
// Fall through.
|
|
||||||
} catch (NoRemoteRepositoryException e) {
|
} catch (NoRemoteRepositoryException e) {
|
||||||
// Fetch concluded the repository doesn't exist.
|
// Fetch concluded the repository doesn't exist.
|
||||||
//
|
te = e;
|
||||||
return e;
|
} catch (NotSupportedException | TransportException e) {
|
||||||
} catch (TransportException e) {
|
te = new TransportException(uri, JGitText.get().pushNotPermitted, e);
|
||||||
// Fall through.
|
|
||||||
}
|
}
|
||||||
return new TransportException(uri, JGitText.get().pushNotPermitted);
|
te.addSuppressed(cause);
|
||||||
|
return te;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue