mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-06 21:45:43 +01:00
Merged 2.0.0-m3
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* <p>
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
@@ -24,96 +24,49 @@
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* <p>
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public final class GitSubModuleParser
|
||||
{
|
||||
public final class GitSubModuleParser {
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
private GitSubModuleParser() {}
|
||||
private GitSubModuleParser() {
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* //~--- methods --------------------------------------------------------------
|
||||
*
|
||||
*
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param content
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, SubRepository> parse(String content)
|
||||
{
|
||||
Map<String, SubRepository> subRepositories = new HashMap<String,
|
||||
SubRepository>();
|
||||
Scanner scanner = new Scanner(content);
|
||||
SubRepository repository = null;
|
||||
|
||||
while (scanner.hasNextLine())
|
||||
{
|
||||
String line = scanner.nextLine();
|
||||
|
||||
if (Util.isNotEmpty(line))
|
||||
{
|
||||
line = line.trim();
|
||||
|
||||
if (line.startsWith("[") && line.endsWith("]"))
|
||||
{
|
||||
repository = new SubRepository();
|
||||
}
|
||||
else if (line.startsWith("path"))
|
||||
{
|
||||
subRepositories.put(getValue(line), repository);
|
||||
}
|
||||
else if (line.startsWith("url"))
|
||||
{
|
||||
repository.setRepositoryUrl(getValue(line));
|
||||
public static Map<String, SubRepository> parse(String content) {
|
||||
Map<String, SubRepository> subRepositories = new HashMap<>();
|
||||
try (Scanner scanner = new Scanner(content)) {
|
||||
SubRepository repository = null;
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
if (Util.isNotEmpty(line)) {
|
||||
line = line.trim();
|
||||
if (line.startsWith("[") && line.endsWith("]")) {
|
||||
repository = new SubRepository();
|
||||
} else if (line.startsWith("path")) {
|
||||
subRepositories.put(getValue(line), repository);
|
||||
} else if (line.startsWith("url")) {
|
||||
repository.setRepositoryUrl(getValue(line));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return subRepositories;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param line
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static String getValue(String line)
|
||||
{
|
||||
private static String getValue(String line) {
|
||||
return line.split("=")[1].trim();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.eclipse.jgit.errors.MissingObjectException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
@@ -51,6 +52,7 @@ import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.GitChangesetConverter;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.RevisionNotFoundException;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -156,15 +158,11 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChangesetPagingResult getChangesets(LogCommandRequest request)
|
||||
throws IOException
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
public ChangesetPagingResult getChangesets(LogCommandRequest request) throws RevisionNotFoundException {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("fetch changesets for request: {}", request);
|
||||
}
|
||||
|
||||
@@ -172,17 +170,13 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
GitChangesetConverter converter = null;
|
||||
RevWalk revWalk = null;
|
||||
|
||||
try (org.eclipse.jgit.lib.Repository gr = open())
|
||||
{
|
||||
if (!gr.getAllRefs().isEmpty())
|
||||
{
|
||||
try (org.eclipse.jgit.lib.Repository gr = open()) {
|
||||
if (!gr.getAllRefs().isEmpty()) {
|
||||
int counter = 0;
|
||||
int start = request.getPagingStart();
|
||||
|
||||
if (start < 0)
|
||||
{
|
||||
if (logger.isErrorEnabled())
|
||||
{
|
||||
if (start < 0) {
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error("start parameter is negative, reset to 0");
|
||||
}
|
||||
|
||||
@@ -193,15 +187,13 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
int limit = request.getPagingLimit();
|
||||
ObjectId startId = null;
|
||||
|
||||
if (!Strings.isNullOrEmpty(request.getStartChangeset()))
|
||||
{
|
||||
if (!Strings.isNullOrEmpty(request.getStartChangeset())) {
|
||||
startId = gr.resolve(request.getStartChangeset());
|
||||
}
|
||||
|
||||
ObjectId endId = null;
|
||||
|
||||
if (!Strings.isNullOrEmpty(request.getEndChangeset()))
|
||||
{
|
||||
if (!Strings.isNullOrEmpty(request.getEndChangeset())) {
|
||||
endId = gr.resolve(request.getEndChangeset());
|
||||
}
|
||||
|
||||
@@ -209,57 +201,51 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
|
||||
converter = new GitChangesetConverter(gr, revWalk);
|
||||
|
||||
if (!Strings.isNullOrEmpty(request.getPath()))
|
||||
{
|
||||
if (!Strings.isNullOrEmpty(request.getPath())) {
|
||||
revWalk.setTreeFilter(
|
||||
AndTreeFilter.create(
|
||||
PathFilter.create(request.getPath()), TreeFilter.ANY_DIFF));
|
||||
}
|
||||
|
||||
|
||||
ObjectId head = getBranchOrDefault(gr, request.getBranch());
|
||||
|
||||
if (head != null)
|
||||
{
|
||||
if (startId != null)
|
||||
{
|
||||
if (head != null) {
|
||||
if (startId != null) {
|
||||
revWalk.markStart(revWalk.lookupCommit(startId));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
revWalk.markStart(revWalk.lookupCommit(head));
|
||||
}
|
||||
|
||||
Iterator<RevCommit> iterator = revWalk.iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
while (iterator.hasNext()) {
|
||||
RevCommit commit = iterator.next();
|
||||
|
||||
if ((counter >= start)
|
||||
&& ((limit < 0) || (counter < start + limit)))
|
||||
{
|
||||
&& ((limit < 0) || (counter < start + limit))) {
|
||||
changesetList.add(converter.createChangeset(commit));
|
||||
}
|
||||
|
||||
counter++;
|
||||
|
||||
if ((endId != null) && commit.getId().equals(endId))
|
||||
{
|
||||
if ((endId != null) && commit.getId().equals(endId)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
changesets = new ChangesetPagingResult(counter, changesetList);
|
||||
}
|
||||
else if (logger.isWarnEnabled())
|
||||
{
|
||||
} else if (logger.isWarnEnabled()) {
|
||||
logger.warn("the repository {} seems to be empty",
|
||||
repository.getName());
|
||||
|
||||
changesets = new ChangesetPagingResult(0, Collections.EMPTY_LIST);
|
||||
}
|
||||
}
|
||||
catch (MissingObjectException e)
|
||||
{
|
||||
throw new RevisionNotFoundException(e.getObjectId().name());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InternalRepositoryException("could not create change log", ex);
|
||||
|
||||
@@ -37,12 +37,12 @@ package sonia.scm.repository.client.spi;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.transport.CredentialsProvider;
|
||||
|
||||
import sonia.scm.repository.client.api.RepositoryClientException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -73,11 +73,20 @@ public class GitPushCommand implements PushCommand
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void push() throws IOException
|
||||
public void push() throws IOException {
|
||||
push(() -> git.push().setPushAll());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushTags() throws IOException {
|
||||
push(() -> git.push().setPushTags());
|
||||
}
|
||||
|
||||
private void push(Supplier<org.eclipse.jgit.api.PushCommand> commandSupplier) throws RepositoryClientException
|
||||
{
|
||||
try
|
||||
{
|
||||
org.eclipse.jgit.api.PushCommand cmd = git.push().setPushAll();
|
||||
org.eclipse.jgit.api.PushCommand cmd = commandSupplier.get();
|
||||
|
||||
if (credentialsProvider != null)
|
||||
{
|
||||
|
||||
@@ -35,22 +35,20 @@ package sonia.scm.repository.client.spi;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.revwalk.RevObject;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.repository.Tag;
|
||||
import sonia.scm.repository.client.api.RepositoryClientException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -119,7 +117,11 @@ public class GitTagCommand implements TagCommand
|
||||
ref = git.tag().setObjectId(revObject).call();
|
||||
}
|
||||
|
||||
tag = new Tag(request.getName(), ref.getPeeledObjectId().toString());
|
||||
if (ref.isPeeled()) {
|
||||
tag = new Tag(request.getName(), ref.getPeeledObjectId().toString());
|
||||
} else {
|
||||
tag = new Tag(request.getName(), ref.getObjectId().toString());
|
||||
}
|
||||
|
||||
}
|
||||
catch (GitAPIException ex)
|
||||
|
||||
@@ -35,15 +35,12 @@ package sonia.scm.repository.spi;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.junit.Test;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.GitConstants;
|
||||
import sonia.scm.repository.Modifications;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -55,7 +52,7 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link GitLogCommand}.
|
||||
*
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
@@ -63,13 +60,9 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
|
||||
/**
|
||||
* Tests log command with the usage of a default branch.
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws GitAPIException
|
||||
* @
|
||||
*/
|
||||
@Test
|
||||
public void testGetDefaultBranch() throws IOException, GitAPIException {
|
||||
public void testGetDefaultBranch() throws Exception {
|
||||
// without default branch, the repository head should be used
|
||||
ChangesetPagingResult result = createCommand().getChangesets(new LogCommandRequest());
|
||||
|
||||
@@ -79,10 +72,10 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
assertEquals("86a6645eceefe8b9a247db5eb16e3d89a7e6e6d1", result.getChangesets().get(1).getId());
|
||||
assertEquals("592d797cd36432e591416e8b2b98154f4f163411", result.getChangesets().get(2).getId());
|
||||
assertEquals("435df2f061add3589cb326cc64be9b9c3897ceca", result.getChangesets().get(3).getId());
|
||||
|
||||
|
||||
// set default branch and fetch again
|
||||
repository.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "test-branch");
|
||||
|
||||
|
||||
result = createCommand().getChangesets(new LogCommandRequest());
|
||||
|
||||
assertNotNull(result);
|
||||
@@ -91,16 +84,9 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
assertEquals("592d797cd36432e591416e8b2b98154f4f163411", result.getChangesets().get(1).getId());
|
||||
assertEquals("435df2f061add3589cb326cc64be9b9c3897ceca", result.getChangesets().get(2).getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testGetAll() throws IOException
|
||||
public void testGetAll() throws Exception
|
||||
{
|
||||
ChangesetPagingResult result =
|
||||
createCommand().getChangesets(new LogCommandRequest());
|
||||
@@ -110,15 +96,8 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
assertEquals(4, result.getChangesets().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test
|
||||
public void testGetAllByPath() throws IOException
|
||||
public void testGetAllByPath() throws Exception
|
||||
{
|
||||
LogCommandRequest request = new LogCommandRequest();
|
||||
|
||||
@@ -133,15 +112,8 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
assertEquals("435df2f061add3589cb326cc64be9b9c3897ceca", result.getChangesets().get(1).getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test
|
||||
public void testGetAllWithLimit() throws IOException
|
||||
public void testGetAllWithLimit() throws Exception
|
||||
{
|
||||
LogCommandRequest request = new LogCommandRequest();
|
||||
|
||||
@@ -164,15 +136,8 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
assertEquals("86a6645eceefe8b9a247db5eb16e3d89a7e6e6d1", c2.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test
|
||||
public void testGetAllWithPaging() throws IOException
|
||||
public void testGetAllWithPaging() throws Exception
|
||||
{
|
||||
LogCommandRequest request = new LogCommandRequest();
|
||||
|
||||
@@ -196,10 +161,6 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
assertEquals("592d797cd36432e591416e8b2b98154f4f163411", c2.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testGetCommit()
|
||||
{
|
||||
@@ -224,15 +185,8 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
assertThat(mods.getAdded(), contains("a.txt", "b.txt"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test
|
||||
public void testGetRange() throws IOException
|
||||
public void testGetRange() throws Exception
|
||||
{
|
||||
LogCommandRequest request = new LogCommandRequest();
|
||||
|
||||
@@ -254,12 +208,6 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
assertEquals("435df2f061add3589cb326cc64be9b9c3897ceca", c2.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private GitLogCommand createCommand()
|
||||
{
|
||||
return new GitLogCommand(createContext(), repository);
|
||||
|
||||
Reference in New Issue
Block a user