mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-06 13:35:44 +01:00
merge with branch 1.x
This commit is contained in:
@@ -50,12 +50,14 @@ import sonia.scm.repository.spi.GitRepositoryServiceProvider;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.schedule.Scheduler;
|
||||
import sonia.scm.schedule.Task;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -195,21 +197,17 @@ public class GitRepositoryHandler
|
||||
protected void create(Repository repository, File directory)
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
org.eclipse.jgit.lib.Repository gitRepository = null;
|
||||
|
||||
try
|
||||
{
|
||||
gitRepository = new FileRepositoryBuilder().setGitDir(
|
||||
directory).readEnvironment().findGitDir().build();
|
||||
try (org.eclipse.jgit.lib.Repository gitRepository = build(directory)) {
|
||||
gitRepository.create(true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (gitRepository != null)
|
||||
{
|
||||
gitRepository.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private org.eclipse.jgit.lib.Repository build(File directory) throws IOException {
|
||||
return new FileRepositoryBuilder()
|
||||
.setGitDir(directory)
|
||||
.readEnvironment()
|
||||
.findGitDir()
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -271,7 +271,7 @@ public class GitBrowseCommand extends AbstractGitCommand
|
||||
walk.markStart(commit);
|
||||
result = Util.getFirst(walk);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.error("could not parse commit for file", ex);
|
||||
}
|
||||
@@ -417,12 +417,9 @@ public class GitBrowseCommand extends AbstractGitCommand
|
||||
revision);
|
||||
}
|
||||
|
||||
Map<String, SubRepository> subRepositories = null;
|
||||
ByteArrayOutputStream baos = null;
|
||||
|
||||
try
|
||||
Map<String, SubRepository> subRepositories;
|
||||
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() )
|
||||
{
|
||||
baos = new ByteArrayOutputStream();
|
||||
new GitCatCommand(context, repository).getContent(repo, revision,
|
||||
PATH_MODULES, baos);
|
||||
subRepositories = GitSubModuleParser.parse(baos.toString());
|
||||
@@ -431,8 +428,6 @@ public class GitBrowseCommand extends AbstractGitCommand
|
||||
{
|
||||
logger.trace("could not find .gitmodules", ex);
|
||||
subRepositories = Collections.EMPTY_MAP;
|
||||
} finally {
|
||||
IOUtil.close(baos);
|
||||
}
|
||||
|
||||
return subRepositories;
|
||||
@@ -461,8 +456,7 @@ public class GitBrowseCommand extends AbstractGitCommand
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private final Map<ObjectId, Map<String, SubRepository>> subrepositoryCache =
|
||||
Maps.newHashMap();
|
||||
|
||||
/** sub repository cache */
|
||||
private final Map<ObjectId, Map<String, SubRepository>> subrepositoryCache = Maps.newHashMap();
|
||||
}
|
||||
|
||||
@@ -35,8 +35,6 @@ package sonia.scm.repository.client.spi;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.io.Closeables;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
@@ -48,7 +46,6 @@ import sonia.scm.repository.client.api.RepositoryClientException;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -83,31 +80,17 @@ public class GitCommitCommand implements CommitCommand
|
||||
@Override
|
||||
public Changeset commit(CommitRequest request) throws IOException
|
||||
{
|
||||
Changeset changeset = null;
|
||||
GitChangesetConverter converter = null;
|
||||
|
||||
try
|
||||
try (GitChangesetConverter converter = new GitChangesetConverter(git.getRepository()))
|
||||
{
|
||||
RevCommit commit = git.commit().setAuthor(
|
||||
request.getAuthor().getName(),
|
||||
request.getAuthor().getMail()).setMessage(
|
||||
request.getMessage()).call();
|
||||
RevCommit commit = git.commit()
|
||||
.setAuthor(request.getAuthor().getName(), request.getAuthor().getMail())
|
||||
.setMessage(request.getMessage())
|
||||
.call();
|
||||
|
||||
converter = new GitChangesetConverter(git.getRepository());
|
||||
|
||||
changeset = converter.createChangeset(commit);
|
||||
return converter.createChangeset(commit);
|
||||
} catch (GitAPIException ex) {
|
||||
throw new RepositoryClientException("could not commit changes to repository", ex);
|
||||
}
|
||||
catch (GitAPIException ex)
|
||||
{
|
||||
throw new RepositoryClientException(
|
||||
"could not commit changes to repository", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(converter);
|
||||
}
|
||||
|
||||
return changeset;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
@@ -105,13 +105,18 @@ public class GitRepositoryClientFactoryProvider
|
||||
{
|
||||
Git git = null;
|
||||
|
||||
CredentialsProvider credentialsProvider =
|
||||
new UsernamePasswordCredentialsProvider(username, password);
|
||||
CredentialsProvider credentialsProvider = null;
|
||||
if ( username != null && password != null ) {
|
||||
credentialsProvider = new UsernamePasswordCredentialsProvider(username, password);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
git = Git.cloneRepository().setURI(url).setDirectory(
|
||||
workingCopy).setCredentialsProvider(credentialsProvider).call();
|
||||
git = Git.cloneRepository()
|
||||
.setURI(url)
|
||||
.setDirectory(workingCopy)
|
||||
.setCredentialsProvider(credentialsProvider)
|
||||
.call();
|
||||
}
|
||||
catch (GitAPIException ex)
|
||||
{
|
||||
|
||||
@@ -35,6 +35,7 @@ package sonia.scm.repository.client.spi;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.transport.CredentialsProvider;
|
||||
@@ -188,6 +189,11 @@ public class GitRepositoryClientProvider extends RepositoryClientProvider
|
||||
return new GitTagCommand(git);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getWorkingCopy() {
|
||||
return git.getRepository().getDirectory();
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
|
||||
Reference in New Issue
Block a user