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:
Rene Pfeuffer
2019-11-06 17:30:02 +01:00
parent c51118f575
commit df144e298c
8 changed files with 172 additions and 32 deletions

View File

@@ -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);
}
}

View File

@@ -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";
}
}