mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-06-16 22:41:27 +02:00
return revision on merge
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
package sonia.scm.repository.api;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.unmodifiableCollection;
|
||||
|
||||
/**
|
||||
@@ -13,19 +11,15 @@ import static java.util.Collections.unmodifiableCollection;
|
||||
*/
|
||||
public class MergeCommandResult {
|
||||
private final Collection<String> filesWithConflict;
|
||||
private static String mergeCommitRevision;
|
||||
private String newHeadRevision;
|
||||
|
||||
public MergeCommandResult(Collection<String> filesWithConflict, String mergeCommitRevision) {
|
||||
public MergeCommandResult(Collection<String> filesWithConflict) {
|
||||
this.filesWithConflict = filesWithConflict;
|
||||
this.mergeCommitRevision = mergeCommitRevision;
|
||||
}
|
||||
|
||||
public static MergeCommandResult success() {
|
||||
return new MergeCommandResult(emptyList(), mergeCommitRevision);
|
||||
}
|
||||
|
||||
public static MergeCommandResult failure(Collection<String> filesWithConflict) {
|
||||
return new MergeCommandResult(new HashSet<>(filesWithConflict), "");
|
||||
public MergeCommandResult(Collection<String> filesWithConflict, String newHeadRevision) {
|
||||
this.filesWithConflict = filesWithConflict;
|
||||
this.newHeadRevision = newHeadRevision;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,7 +27,7 @@ public class MergeCommandResult {
|
||||
* merge conflicts. In this case you can use {@link #getFilesWithConflict()} to check what files could not be merged.
|
||||
*/
|
||||
public boolean isSuccess() {
|
||||
return filesWithConflict.isEmpty();
|
||||
return filesWithConflict.isEmpty() && newHeadRevision != null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,7 +38,7 @@ public class MergeCommandResult {
|
||||
return unmodifiableCollection(filesWithConflict);
|
||||
}
|
||||
|
||||
public String getMergeCommitRevision() {
|
||||
return mergeCommitRevision;
|
||||
public String getNewHeadRevision() {
|
||||
return newHeadRevision;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class GitFastForwardIfPossible extends GitMergeStrategy {
|
||||
MergeResult fastForwardResult = mergeWithFastForwardOnlyMode();
|
||||
if (fastForwardResult.getMergeStatus().isSuccessful()) {
|
||||
push();
|
||||
return new MergeCommandResult(Collections.emptyList(), "");
|
||||
return new MergeCommandResult(Collections.emptyList(), fastForwardResult.getNewHead().toString());
|
||||
} else {
|
||||
return fallbackMerge.run();
|
||||
}
|
||||
|
||||
@@ -69,6 +69,6 @@ abstract class GitMergeStrategy extends AbstractGitCommand.GitCloneWorker<MergeC
|
||||
|
||||
MergeCommandResult analyseFailure(MergeResult result) {
|
||||
logger.info("could not merge branch {} into {} due to conflict in paths {}", toMerge, target, result.getConflicts().keySet());
|
||||
return MergeCommandResult.failure(result.getConflicts().keySet());
|
||||
return new MergeCommandResult(result.getConflicts().keySet());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.MergeCommand;
|
||||
import org.eclipse.jgit.api.MergeResult;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.api.MergeCommandResult;
|
||||
import org.eclipse.jgit.api.MergeCommand;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
@@ -21,7 +21,7 @@ class GitMergeWithSquash extends GitMergeStrategy {
|
||||
|
||||
@Override
|
||||
MergeCommandResult run() throws IOException {
|
||||
MergeCommand mergeCommand = getClone().merge();
|
||||
MergeCommand mergeCommand = getClone().merge();
|
||||
mergeCommand.setSquash(true);
|
||||
MergeResult result = doMergeInClone(mergeCommand);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import org.eclipse.jgit.api.MergeResult;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import sonia.scm.ContextEntry;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
@@ -12,6 +13,6 @@ public class GitMerger {
|
||||
if (revCommit.isPresent()) {
|
||||
return revCommit.get().toString().split(" ")[1];
|
||||
}
|
||||
throw new InternalRepositoryException(ContextEntry.ContextBuilder.entity(GitMergeCommit.class, "merge commit failed"), "could not create commit on merge");
|
||||
throw new InternalRepositoryException(ContextEntry.ContextBuilder.entity(GitMerger.class, "merge commit failed"), "could not create commit on merge");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user