mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
Add POC for diff against temporary merge result
This fails for files with merge conflicts, because results for these files are not added to git and therefore there is no blob the diff formatter can use to render. This has somehow to be fixed by making jgit use the version from the file system. Taking a look at the implementation of Git.clone() might help here.
This commit is contained in:
@@ -40,7 +40,7 @@ public class GitDiffCommandTest extends AbstractGitCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void diffForOneRevisionShouldCreateDiff() throws IOException {
|
||||
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository);
|
||||
GitDiffCommand gitDiffCommand = createDiffCommand();
|
||||
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
|
||||
diffCommandRequest.setRevision("3f76a12f08a6ba0dc988c68b7f0b2cd190efc3c4");
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
@@ -50,7 +50,7 @@ public class GitDiffCommandTest extends AbstractGitCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void diffForOneBranchShouldCreateDiff() throws IOException {
|
||||
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository);
|
||||
GitDiffCommand gitDiffCommand = createDiffCommand();
|
||||
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
|
||||
diffCommandRequest.setRevision("test-branch");
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
@@ -60,7 +60,7 @@ public class GitDiffCommandTest extends AbstractGitCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void diffForPathShouldCreateLimitedDiff() throws IOException {
|
||||
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository);
|
||||
GitDiffCommand gitDiffCommand = createDiffCommand();
|
||||
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
|
||||
diffCommandRequest.setRevision("test-branch");
|
||||
diffCommandRequest.setPath("a.txt");
|
||||
@@ -71,7 +71,7 @@ public class GitDiffCommandTest extends AbstractGitCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void diffBetweenTwoBranchesShouldCreateDiff() throws IOException {
|
||||
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository);
|
||||
GitDiffCommand gitDiffCommand = createDiffCommand();
|
||||
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
|
||||
diffCommandRequest.setRevision("master");
|
||||
diffCommandRequest.setAncestorChangeset("test-branch");
|
||||
@@ -82,7 +82,7 @@ public class GitDiffCommandTest extends AbstractGitCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void diffBetweenTwoBranchesForPathShouldCreateLimitedDiff() throws IOException {
|
||||
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository);
|
||||
GitDiffCommand gitDiffCommand = createDiffCommand();
|
||||
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
|
||||
diffCommandRequest.setRevision("master");
|
||||
diffCommandRequest.setAncestorChangeset("test-branch");
|
||||
@@ -91,4 +91,8 @@ public class GitDiffCommandTest extends AbstractGitCommandTestBase {
|
||||
gitDiffCommand.getDiffResult(diffCommandRequest).accept(output);
|
||||
assertEquals(DIFF_FILE_A_MULTIPLE_REVISIONS, output.toString());
|
||||
}
|
||||
|
||||
private GitDiffCommand createDiffCommand() {
|
||||
return new GitDiffCommand(createContext(), repository, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import sonia.scm.repository.util.WorkdirProvider;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class GitDiffCommand_Merge_Test extends AbstractGitCommandTestBase {
|
||||
|
||||
static final String DIFF_HEADER = "diff --git a/Main.java b/Main.java";
|
||||
static final String DIFF_FILE_A_MULTIPLE_REVISIONS = "--- a/Main.java\n" +
|
||||
"+++ b/Main.java\n" +
|
||||
"@@ -1,5 +1,5 @@\n" +
|
||||
" class Main {\n" +
|
||||
"- public static void main(String[] args) {\n" +
|
||||
"+ public static void main(String[] arguments) {\n" +
|
||||
" System.out.println(\"Expect nothing more to happen.\");\n" +
|
||||
" System.out.println(\"This is for demonstration, only.\");\n" +
|
||||
" }\n";
|
||||
|
||||
@Rule
|
||||
public BindTransportProtocolRule transportProtocolRule = new BindTransportProtocolRule();
|
||||
|
||||
@Test
|
||||
public void diffBetweenTwoBranchesWithoutConflict() throws IOException {
|
||||
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository, new SimpleGitWorkdirFactory(new WorkdirProvider()));
|
||||
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
|
||||
diffCommandRequest.setRevision("feature/rename_variable");
|
||||
diffCommandRequest.setMergeChangeset("integration");
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
gitDiffCommand.getDiffResult(diffCommandRequest).accept(output);
|
||||
assertThat(output.toString())
|
||||
.contains(DIFF_HEADER)
|
||||
.contains(DIFF_FILE_A_MULTIPLE_REVISIONS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void diffBetweenTwoBranchesWithSimpleConflict() throws IOException {
|
||||
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository, new SimpleGitWorkdirFactory(new WorkdirProvider()));
|
||||
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
|
||||
diffCommandRequest.setRevision("feature/print_args");
|
||||
diffCommandRequest.setMergeChangeset("integration");
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
gitDiffCommand.getDiffResult(diffCommandRequest).accept(output);
|
||||
assertThat(output.toString())
|
||||
.contains(DIFF_HEADER)
|
||||
.contains(DIFF_FILE_A_MULTIPLE_REVISIONS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getZippedRepositoryResource() {
|
||||
return "sonia/scm/repository/spi/scm-git-spi-merge-diff-test.zip";
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user