mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
fix exception with empty git repositories
This commit is contained in:
@@ -43,6 +43,7 @@ import org.eclipse.jgit.dircache.DirCache;
|
|||||||
import org.eclipse.jgit.dircache.DirCacheCheckout;
|
import org.eclipse.jgit.dircache.DirCacheCheckout;
|
||||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||||
import org.eclipse.jgit.errors.MissingObjectException;
|
import org.eclipse.jgit.errors.MissingObjectException;
|
||||||
|
import org.eclipse.jgit.errors.NoRemoteRepositoryException;
|
||||||
import org.eclipse.jgit.errors.NotSupportedException;
|
import org.eclipse.jgit.errors.NotSupportedException;
|
||||||
import org.eclipse.jgit.errors.TransportException;
|
import org.eclipse.jgit.errors.TransportException;
|
||||||
import org.eclipse.jgit.lib.Constants;
|
import org.eclipse.jgit.lib.Constants;
|
||||||
@@ -155,10 +156,14 @@ public class GitRepositoryClient implements RepositoryClient
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
final FetchResult r = runFetch();
|
final FetchResult r = runFetch();
|
||||||
|
|
||||||
|
if (r != null)
|
||||||
|
{
|
||||||
final Ref branch = guessHEAD(r);
|
final Ref branch = guessHEAD(r);
|
||||||
|
|
||||||
doCheckout(branch);
|
doCheckout(branch);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
throw new RepositoryClientException(ex);
|
throw new RepositoryClientException(ex);
|
||||||
@@ -383,11 +388,17 @@ public class GitRepositoryClient implements RepositoryClient
|
|||||||
* @return
|
* @return
|
||||||
*
|
*
|
||||||
* @throws NotSupportedException
|
* @throws NotSupportedException
|
||||||
|
* @throws RepositoryClientException
|
||||||
* @throws TransportException
|
* @throws TransportException
|
||||||
* @throws URISyntaxException
|
* @throws URISyntaxException
|
||||||
*/
|
*/
|
||||||
private FetchResult runFetch()
|
private FetchResult runFetch()
|
||||||
throws NotSupportedException, URISyntaxException, TransportException
|
throws NotSupportedException, URISyntaxException, TransportException,
|
||||||
|
RepositoryClientException
|
||||||
|
{
|
||||||
|
FetchResult r = null;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Transport tn = Transport.open(repository, Constants.HEAD);
|
Transport tn = Transport.open(repository, Constants.HEAD);
|
||||||
|
|
||||||
@@ -396,8 +407,6 @@ public class GitRepositoryClient implements RepositoryClient
|
|||||||
tn.setCredentialsProvider(credentialsProvider);
|
tn.setCredentialsProvider(credentialsProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
FetchResult r;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
r = tn.fetch(new TextProgressMonitor(), null);
|
r = tn.fetch(new TextProgressMonitor(), null);
|
||||||
@@ -406,6 +415,13 @@ public class GitRepositoryClient implements RepositoryClient
|
|||||||
{
|
{
|
||||||
tn.close();
|
tn.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (NoRemoteRepositoryException ex)
|
||||||
|
{
|
||||||
|
|
||||||
|
// empty repository, call init
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user