mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-03 03:55:51 +01:00
Fix merge direction
This commit is contained in:
@@ -49,7 +49,7 @@ public class GitMergeCommand extends AbstractGitCommand implements MergeCommand
|
||||
|
||||
@Override
|
||||
public MergeConflictResult computeConflicts(MergeCommandRequest request) {
|
||||
return inClone(git -> new ConflictWorker(git, request), workdirFactory, request.getTargetBranch());
|
||||
return inClone(git -> new ConflictWorker(git, request), workdirFactory, request.getBranchToMerge());
|
||||
}
|
||||
|
||||
private MergeCommandResult mergeWithStrategy(MergeCommandRequest request) {
|
||||
@@ -93,8 +93,8 @@ public class GitMergeCommand extends AbstractGitCommand implements MergeCommand
|
||||
}
|
||||
|
||||
private class ConflictWorker extends GitCloneWorker<MergeConflictResult> {
|
||||
private final String branchToMerge;
|
||||
private final String targetBranch;
|
||||
private final String theirs;
|
||||
private final String ours;
|
||||
private final CanonicalTreeParser treeParser;
|
||||
private final ObjectId treeId;
|
||||
private final ByteArrayOutputStream diffBuffer;
|
||||
@@ -104,15 +104,15 @@ public class GitMergeCommand extends AbstractGitCommand implements MergeCommand
|
||||
|
||||
private ConflictWorker(Git git, MergeCommandRequest request) {
|
||||
super(git, context, repository);
|
||||
branchToMerge = request.getBranchToMerge();
|
||||
targetBranch = request.getTargetBranch();
|
||||
theirs = request.getTargetBranch();
|
||||
ours = request.getBranchToMerge();
|
||||
|
||||
treeParser = new CanonicalTreeParser();
|
||||
diffBuffer = new ByteArrayOutputStream();
|
||||
try {
|
||||
treeId = git.getRepository().resolve(request.getTargetBranch() + "^{tree}");
|
||||
treeId = git.getRepository().resolve(ours + "^{tree}");
|
||||
} catch (IOException e) {
|
||||
throw notFound(entity("branch", request.getTargetBranch()).in(repository));
|
||||
throw notFound(entity("branch", ours).in(repository));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,15 +154,15 @@ public class GitMergeCommand extends AbstractGitCommand implements MergeCommand
|
||||
}
|
||||
|
||||
private MergeResult doTemporaryMerge() throws IOException {
|
||||
ObjectId sourceRevision = resolveRevision(branchToMerge);
|
||||
ObjectId sourceRevision = resolveRevision(theirs);
|
||||
try {
|
||||
return getClone().merge()
|
||||
.setFastForward(org.eclipse.jgit.api.MergeCommand.FastForwardMode.NO_FF)
|
||||
.setCommit(false)
|
||||
.include(branchToMerge, sourceRevision)
|
||||
.include(theirs, sourceRevision)
|
||||
.call();
|
||||
} catch (GitAPIException e) {
|
||||
throw new InternalRepositoryException(context.getRepository(), "could not merge branch " + branchToMerge + " into " + targetBranch, e);
|
||||
throw new InternalRepositoryException(context.getRepository(), "could not merge branch " + theirs + " into " + ours, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,20 +17,18 @@ public class GitMergeCommand_Conflict_Test extends AbstractGitCommandTestBase {
|
||||
static final String DIFF_HEADER = "diff --git a/Main.java b/Main.java";
|
||||
static final String DIFF_FILE_CONFLICT = "--- a/Main.java\n" +
|
||||
"+++ b/Main.java\n" +
|
||||
"@@ -1,6 +1,13 @@\n" +
|
||||
"+import java.util.Arrays;\n" +
|
||||
"+\n" +
|
||||
"@@ -3,7 +3,11 @@\n" +
|
||||
" class Main {\n" +
|
||||
" public static void main(String[] args) {\n" +
|
||||
" System.out.println(\"Expect nothing more to happen.\");\n" +
|
||||
"+<<<<<<< HEAD\n" +
|
||||
" System.out.println(\"This is for demonstration, only.\");\n" +
|
||||
" System.out.println(\"Parameters:\");\n" +
|
||||
" Arrays.stream(args).map(arg -> \"- \" + arg).forEach(System.out::println);\n" +
|
||||
"+=======\n" +
|
||||
"+ System.out.println(\"Parameters:\");\n" +
|
||||
"+ Arrays.stream(args).map(arg -> \"- \" + arg).forEach(System.out::println);\n" +
|
||||
"+>>>>>>> feature/print_args\n" +
|
||||
"+ System.out.println(\"This is for demonstration, only.\");\n" +
|
||||
"+>>>>>>> integration\n" +
|
||||
" }\n" +
|
||||
" }\n";
|
||||
" }";
|
||||
|
||||
@Rule
|
||||
public BindTransportProtocolRule transportProtocolRule = new BindTransportProtocolRule();
|
||||
@@ -51,18 +49,18 @@ public class GitMergeCommand_Conflict_Test extends AbstractGitCommandTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void diffBetweenTwoBranchesWithDeletedByThem() throws IOException {
|
||||
public void diffBetweenTwoBranchesWithDeletedByUs() throws IOException {
|
||||
MergeConflictResult result = computeMergeConflictResult("feature/remove_class", "integration");
|
||||
SingleMergeConflict conflict = result.getConflicts().get(0);
|
||||
assertThat(conflict.getType()).isEqualTo(DELETED_BY_THEM);
|
||||
assertThat(conflict.getType()).isEqualTo(DELETED_BY_US);
|
||||
assertThat(conflict.getPath()).isEqualTo("Main.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void diffBetweenTwoBranchesWithDeletedByUs() throws IOException {
|
||||
public void diffBetweenTwoBranchesWithDeletedByThem() throws IOException {
|
||||
MergeConflictResult result = computeMergeConflictResult("integration", "feature/remove_class");
|
||||
SingleMergeConflict conflict = result.getConflicts().get(0);
|
||||
assertThat(conflict.getType()).isEqualTo(DELETED_BY_US);
|
||||
assertThat(conflict.getType()).isEqualTo(DELETED_BY_THEM);
|
||||
assertThat(conflict.getPath()).isEqualTo("Main.java");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user