mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-06 20:30:52 +01:00
Merge branch 'develop' into feature/import_git_from_url
This commit is contained in:
@@ -35,60 +35,28 @@ import sonia.scm.repository.Repository;
|
||||
public class AbstractCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
* @param context
|
||||
*
|
||||
*/
|
||||
protected final HgCommandContext context;
|
||||
protected final Repository repository;
|
||||
|
||||
public AbstractCommand(HgCommandContext context)
|
||||
{
|
||||
this.context = context;
|
||||
this.repository = context.getScmRepository();
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public com.aragost.javahg.Repository open()
|
||||
{
|
||||
return context.open();
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public HgCommandContext getContext()
|
||||
{
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Repository getRepository()
|
||||
{
|
||||
return repository;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private HgCommandContext context;
|
||||
|
||||
/** Field description */
|
||||
private Repository repository;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import com.aragost.javahg.Changeset;
|
||||
import com.aragost.javahg.Repository;
|
||||
import com.aragost.javahg.commands.ExecutionException;
|
||||
import com.aragost.javahg.commands.PullCommand;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.work.WorkingCopy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class AbstractWorkingCopyCommand extends AbstractCommand {
|
||||
static final Pattern HG_MESSAGE_PATTERN = Pattern.compile(".*\\[SCM\\](?: Error:)? (.*)");
|
||||
|
||||
protected final HgWorkingCopyFactory workingCopyFactory;
|
||||
|
||||
public AbstractWorkingCopyCommand(HgCommandContext context, HgWorkingCopyFactory workingCopyFactory)
|
||||
{
|
||||
super(context);
|
||||
this.workingCopyFactory = workingCopyFactory;
|
||||
}
|
||||
|
||||
protected List<Changeset> pullChangesIntoCentralRepository(WorkingCopy<Repository, Repository> workingCopy, String branch) {
|
||||
try {
|
||||
com.aragost.javahg.commands.PullCommand pullCommand = PullCommand.on(workingCopy.getCentralRepository());
|
||||
workingCopyFactory.configure(pullCommand);
|
||||
return pullCommand.execute(workingCopy.getDirectory().getAbsolutePath());
|
||||
} catch (ExecutionException e) {
|
||||
throw IntegrateChangesFromWorkdirException
|
||||
.withPattern(HG_MESSAGE_PATTERN)
|
||||
.forMessage(context.getScmRepository(), e.getMessage());
|
||||
} catch (IOException e) {
|
||||
throw new InternalRepositoryException(getRepository(),
|
||||
String.format("Could not pull changes '%s' into central repository", branch),
|
||||
e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,6 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import com.aragost.javahg.Changeset;
|
||||
import com.aragost.javahg.commands.CommitCommand;
|
||||
import com.aragost.javahg.commands.PullCommand;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -37,21 +36,16 @@ import sonia.scm.repository.api.BranchRequest;
|
||||
import sonia.scm.repository.work.WorkingCopy;
|
||||
import sonia.scm.user.User;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Mercurial implementation of the {@link BranchCommand}.
|
||||
* Note that this creates an empty commit to "persist" the new branch.
|
||||
*/
|
||||
public class HgBranchCommand extends AbstractCommand implements BranchCommand {
|
||||
public class HgBranchCommand extends AbstractWorkingCopyCommand implements BranchCommand {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(HgBranchCommand.class);
|
||||
|
||||
private final HgWorkingCopyFactory workingCopyFactory;
|
||||
|
||||
HgBranchCommand(HgCommandContext context, HgWorkingCopyFactory workingCopyFactory) {
|
||||
super(context);
|
||||
this.workingCopyFactory = workingCopyFactory;
|
||||
super(context, workingCopyFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,15 +97,4 @@ public class HgBranchCommand extends AbstractCommand implements BranchCommand {
|
||||
.execute();
|
||||
}
|
||||
|
||||
private void pullChangesIntoCentralRepository(WorkingCopy<com.aragost.javahg.Repository, com.aragost.javahg.Repository> workingCopy, String branch) {
|
||||
try {
|
||||
PullCommand pullCommand = PullCommand.on(workingCopy.getCentralRepository());
|
||||
workingCopyFactory.configure(pullCommand);
|
||||
pullCommand.execute(workingCopy.getDirectory().getAbsolutePath());
|
||||
} catch (IOException e) {
|
||||
throw new InternalRepositoryException(getRepository(),
|
||||
String.format("Could not pull changes '%s' into central repository", branch),
|
||||
e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import com.aragost.javahg.Changeset;
|
||||
import com.aragost.javahg.Repository;
|
||||
import com.aragost.javahg.commands.CommitCommand;
|
||||
import com.aragost.javahg.commands.ExecutionException;
|
||||
import com.aragost.javahg.commands.PullCommand;
|
||||
import com.aragost.javahg.commands.RemoveCommand;
|
||||
import com.aragost.javahg.commands.StatusCommand;
|
||||
import org.slf4j.Logger;
|
||||
@@ -41,20 +40,17 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static sonia.scm.repository.spi.UserFormatter.getUserStringFor;
|
||||
|
||||
@SuppressWarnings("java:S3252") // it is ok for javahg classes to access static method of subtype
|
||||
public class HgModifyCommand implements ModifyCommand {
|
||||
public class HgModifyCommand extends AbstractWorkingCopyCommand implements ModifyCommand {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(HgModifyCommand.class);
|
||||
static final Pattern HG_MESSAGE_PATTERN = Pattern.compile(".*\\[SCM\\](?: Error:)? (.*)");
|
||||
|
||||
private final HgCommandContext context;
|
||||
private final HgWorkingCopyFactory workingCopyFactory;
|
||||
|
||||
public HgModifyCommand(HgCommandContext context, HgWorkingCopyFactory workingCopyFactory) {
|
||||
this.context = context;
|
||||
this.workingCopyFactory = workingCopyFactory;
|
||||
super(context, workingCopyFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,10 +106,10 @@ public class HgModifyCommand implements ModifyCommand {
|
||||
|
||||
LOG.trace("commit changes in working copy");
|
||||
CommitCommand.on(workingRepository)
|
||||
.user(String.format("%s <%s>", request.getAuthor().getName(), request.getAuthor().getMail()))
|
||||
.user(getUserStringFor(request.getAuthor()))
|
||||
.message(request.getCommitMessage()).execute();
|
||||
|
||||
List<Changeset> execute = pullModifyChangesToCentralRepository(request, workingCopy);
|
||||
List<Changeset> execute = pullChangesIntoCentralRepository(workingCopy, request.getBranch());
|
||||
|
||||
String node = execute.get(0).getNode();
|
||||
LOG.debug("successfully pulled changes from working copy, new node {}", node);
|
||||
@@ -124,24 +120,7 @@ public class HgModifyCommand implements ModifyCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private List<Changeset> pullModifyChangesToCentralRepository(ModifyCommandRequest request, WorkingCopy<com.aragost.javahg.Repository, com.aragost.javahg.Repository> workingCopy) {
|
||||
LOG.trace("pull changes from working copy");
|
||||
try {
|
||||
com.aragost.javahg.commands.PullCommand pullCommand = PullCommand.on(workingCopy.getCentralRepository());
|
||||
workingCopyFactory.configure(pullCommand);
|
||||
return pullCommand.execute(workingCopy.getDirectory().getAbsolutePath());
|
||||
} catch (ExecutionException e) {
|
||||
throw IntegrateChangesFromWorkdirException
|
||||
.withPattern(HG_MESSAGE_PATTERN)
|
||||
.forMessage(context.getScmRepository(), e.getMessage());
|
||||
} catch (IOException e) {
|
||||
throw new InternalRepositoryException(context.getScmRepository(),
|
||||
String.format("Could not pull modify changes from working copy to central repository for branch %s", request.getBranch()),
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
private String throwInternalRepositoryException(String message, Exception e) {
|
||||
private void throwInternalRepositoryException(String message, Exception e) {
|
||||
throw new InternalRepositoryException(context.getScmRepository(), message, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ public class HgRepositoryServiceProvider extends RepositoryServiceProvider {
|
||||
Command.DIFF,
|
||||
Command.LOG,
|
||||
Command.TAGS,
|
||||
Command.TAG,
|
||||
Command.BRANCH,
|
||||
Command.BRANCHES,
|
||||
Command.INCOMING,
|
||||
@@ -261,4 +262,9 @@ public class HgRepositoryServiceProvider extends RepositoryServiceProvider {
|
||||
return new HgTagsCommand(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagCommand getTagCommand() {
|
||||
return new HgTagCommand(context, handler.getWorkingCopyFactory());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import com.aragost.javahg.Repository;
|
||||
import com.google.common.base.Strings;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import sonia.scm.repository.Tag;
|
||||
import sonia.scm.repository.api.TagCreateRequest;
|
||||
import sonia.scm.repository.api.TagDeleteRequest;
|
||||
import sonia.scm.repository.work.WorkingCopy;
|
||||
import sonia.scm.user.User;
|
||||
|
||||
import static sonia.scm.repository.spi.UserFormatter.getUserStringFor;
|
||||
|
||||
public class HgTagCommand extends AbstractWorkingCopyCommand implements TagCommand {
|
||||
|
||||
public static final String DEFAULT_BRANCH_NAME = "default";
|
||||
|
||||
public HgTagCommand(HgCommandContext context, HgWorkingCopyFactory workingCopyFactory) {
|
||||
super(context, workingCopyFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag create(TagCreateRequest request) {
|
||||
try (WorkingCopy<Repository, Repository> workingCopy = workingCopyFactory.createWorkingCopy(getContext(), DEFAULT_BRANCH_NAME)) {
|
||||
Repository repository = getContext().open();
|
||||
String rev = request.getRevision();
|
||||
if (Strings.isNullOrEmpty(rev)) {
|
||||
rev = repository.tip().getNode();
|
||||
}
|
||||
com.aragost.javahg.commands.TagCommand.on(workingCopy.getWorkingRepository())
|
||||
.rev(rev)
|
||||
.user(getUserStringFor(SecurityUtils.getSubject().getPrincipals().oneByType(User.class)))
|
||||
.execute(request.getName());
|
||||
pullChangesIntoCentralRepository(workingCopy, DEFAULT_BRANCH_NAME);
|
||||
return new Tag(request.getName(), rev);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(TagDeleteRequest request) {
|
||||
try (WorkingCopy<Repository, Repository> workingCopy = workingCopyFactory.createWorkingCopy(getContext(), DEFAULT_BRANCH_NAME)) {
|
||||
com.aragost.javahg.commands.TagCommand.on(workingCopy.getWorkingRepository())
|
||||
.user(getUserStringFor(SecurityUtils.getSubject().getPrincipals().oneByType(User.class)))
|
||||
.remove()
|
||||
.execute(request.getName());
|
||||
|
||||
pullChangesIntoCentralRepository(workingCopy, DEFAULT_BRANCH_NAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,8 @@ import java.util.List;
|
||||
*/
|
||||
public class HgTagsCommand extends AbstractCommand implements TagsCommand {
|
||||
|
||||
public static final String DEFAULT_TAG_NAME = "tip";
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
@@ -99,7 +101,7 @@ public class HgTagsCommand extends AbstractCommand implements TagsCommand {
|
||||
|
||||
if ((f != null) && !Strings.isNullOrEmpty(f.getName())
|
||||
&& (f.getChangeset() != null)) {
|
||||
t = new Tag(f.getName(), f.getChangeset().getNode(), f.getChangeset().getTimestamp().getDate().getTime());
|
||||
t = new Tag(f.getName(), f.getChangeset().getNode(), f.getChangeset().getTimestamp().getDate().getTime(), !f.getName().equals(DEFAULT_TAG_NAME));
|
||||
}
|
||||
|
||||
return t;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import sonia.scm.repository.Person;
|
||||
import sonia.scm.user.User;
|
||||
|
||||
final class UserFormatter {
|
||||
private UserFormatter() {
|
||||
}
|
||||
|
||||
static String getUserStringFor(User user) {
|
||||
return getUserStringFor(new Person(user.getName(), user.getMail()));
|
||||
}
|
||||
|
||||
static String getUserStringFor(Person person) {
|
||||
return String.format("%s <%s>", person.getName(), person.getMail());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user