add new MergeStrategies

This commit is contained in:
Eduard Heimbuch
2019-11-06 07:47:23 +01:00
parent db46441adf
commit bc5948f823
4 changed files with 23 additions and 2 deletions

View File

@@ -6,6 +6,8 @@ import sonia.scm.repository.spi.MergeCommand;
import sonia.scm.repository.spi.MergeCommandRequest;
import sonia.scm.repository.util.AuthorUtil;
import java.util.Set;
/**
* Use this {@link MergeCommandBuilder} to merge two branches of a repository ({@link #executeMerge()}) or to check if
* the branches could be merged without conflicts ({@link #dryRun()}). To do so, you have to specify the name of
@@ -64,6 +66,10 @@ public class MergeCommandBuilder {
return mergeCommand.isSupported(strategy);
}
public Set<MergeStrategy> getSupportedMergeStrategies() {
return mergeCommand.getSupportedMergeStrategies();
}
/**
* Use this to set the branch that should be merged into the target branch.
*

View File

@@ -1,5 +1,7 @@
package sonia.scm.repository.api;
public enum MergeStrategy {
SQUASH
SQUASH,
MERGE_COMMIT,
FAST_FORWARD_IF_POSSIBLE
}

View File

@@ -4,10 +4,14 @@ import sonia.scm.repository.api.MergeCommandResult;
import sonia.scm.repository.api.MergeDryRunCommandResult;
import sonia.scm.repository.api.MergeStrategy;
import java.util.Set;
public interface MergeCommand {
MergeCommandResult merge(MergeCommandRequest request);
MergeDryRunCommandResult dryRun(MergeCommandRequest request);
boolean isSupported(MergeStrategy strategy);
Set<MergeStrategy> getSupportedMergeStrategies();
}

View File

@@ -33,7 +33,11 @@ public class GitMergeCommand extends AbstractGitCommand implements MergeCommand
private final GitWorkdirFactory workdirFactory;
private static final Set<MergeStrategy> STRATEGIES = ImmutableSet.of(MergeStrategy.SQUASH);
private static final Set<MergeStrategy> STRATEGIES = ImmutableSet.of(
MergeStrategy.SQUASH,
MergeStrategy.MERGE_COMMIT,
MergeStrategy.FAST_FORWARD_IF_POSSIBLE
);
GitMergeCommand(GitContext context, sonia.scm.repository.Repository repository, GitWorkdirFactory workdirFactory) {
super(context, repository);
@@ -64,6 +68,11 @@ public class GitMergeCommand extends AbstractGitCommand implements MergeCommand
return STRATEGIES.contains(strategy);
}
@Override
public Set<MergeStrategy> getSupportedMergeStrategies() {
return STRATEGIES;
}
private class MergeWorker extends GitCloneWorker<MergeCommandResult> {
private final String target;