add import for hg repository via url with and without credentials

This commit is contained in:
Eduard Heimbuch
2020-12-02 14:20:40 +01:00
parent dffe466405
commit 28b485f11f
2 changed files with 17 additions and 38 deletions

View File

@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Unify and add description to key view across user settings ([#1440](https://github.com/scm-manager/scm-manager/pull/1440))
- Healthcheck for docker image ([#1428](https://github.com/scm-manager/scm-manager/issues/1428) and [#1454](https://github.com/scm-manager/scm-manager/issues/1454))
- Repository import via URL for git ([#1460](https://github.com/scm-manager/scm-manager/pull/1460))
- Repository import via URL for hg ([#1463](https://github.com/scm-manager/scm-manager/pull/1463))
### Changed
- Send mercurial hook callbacks over separate tcp socket instead of http ([#1416](https://github.com/scm-manager/scm-manager/pull/1416))

View File

@@ -24,67 +24,45 @@
package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
import com.aragost.javahg.Changeset;
import com.aragost.javahg.commands.ExecutionException;
import com.google.common.base.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.ContextEntry;
import sonia.scm.repository.HgRepositoryHandler;
import sonia.scm.repository.InternalRepositoryException;
import sonia.scm.repository.api.ImportFailedException;
import sonia.scm.repository.api.PullResponse;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
//~--- JDK imports ------------------------------------------------------------
public class HgPullCommand extends AbstractHgPushOrPullCommand implements PullCommand {
/**
*
* @author Sebastian Sdorra
*/
public class HgPullCommand extends AbstractHgPushOrPullCommand
implements PullCommand
{
private static final Logger logger = LoggerFactory.getLogger(HgPullCommand.class);
/** Field description */
private static final Logger logger =
LoggerFactory.getLogger(HgPullCommand.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
* @param handler
* @param context
*/
public HgPullCommand(HgRepositoryHandler handler, HgCommandContext context)
{
public HgPullCommand(HgRepositoryHandler handler, HgCommandContext context) {
super(handler, context);
}
//~--- methods --------------------------------------------------------------
@Override
@SuppressWarnings("unchecked")
public PullResponse pull(PullCommandRequest request)
throws IOException
{
throws IOException {
String url = getRemoteUrl(request);
logger.debug("pull changes from {} to {}", url, getRepository().getId());
logger.debug("pull changes from {} to {}", url, getContext().getScmRepository().getId());
List<Changeset> result = Collections.EMPTY_LIST;
List<Changeset> result;
try
{
result = com.aragost.javahg.commands.PullCommand.on(open()).execute(url);
if (!Strings.isNullOrEmpty(request.getUsername()) && !Strings.isNullOrEmpty(request.getPassword())) {
url = url.replace("://", String.format("://%s:%s@", request.getUsername(), request.getPassword()));
}
catch (ExecutionException ex)
{
throw new InternalRepositoryException(getRepository(), "could not execute push command", ex);
try {
result = com.aragost.javahg.commands.PullCommand.on(open()).execute(url);
} catch (ExecutionException ex) {
throw new ImportFailedException(ContextEntry.ContextBuilder.entity(getRepository()).build(), "could not execute pull command", ex);
}
return new PullResponse(result.size());