Use jgit client library for diff with conflict

This commit is contained in:
Rene Pfeuffer
2019-11-07 16:26:30 +01:00
parent df144e298c
commit 758e4ab750
3 changed files with 46 additions and 13 deletions

View File

@@ -12,7 +12,7 @@ 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" +
static final String DIFF_FILE_NO_CONFLICT = "--- a/Main.java\n" +
"+++ b/Main.java\n" +
"@@ -1,5 +1,5 @@\n" +
" class Main {\n" +
@@ -21,6 +21,22 @@ public class GitDiffCommand_Merge_Test extends AbstractGitCommandTestBase {
" System.out.println(\"Expect nothing more to happen.\");\n" +
" System.out.println(\"This is for demonstration, only.\");\n" +
" }\n";
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" +
" 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" +
"+=======\n" +
"+ System.out.println(\"Parameters:\");\n" +
"+ Arrays.stream(args).map(arg -> \"- \" + arg).forEach(System.out::println);\n" +
"+>>>>>>> feature/print_args\n" +
" }\n" +
" }\n";
@Rule
public BindTransportProtocolRule transportProtocolRule = new BindTransportProtocolRule();
@@ -30,12 +46,12 @@ public class GitDiffCommand_Merge_Test extends AbstractGitCommandTestBase {
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository, new SimpleGitWorkdirFactory(new WorkdirProvider()));
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
diffCommandRequest.setRevision("feature/rename_variable");
diffCommandRequest.setMergeChangeset("integration");
diffCommandRequest.setConflictBranch("integration");
ByteArrayOutputStream output = new ByteArrayOutputStream();
gitDiffCommand.getDiffResult(diffCommandRequest).accept(output);
assertThat(output.toString())
.contains(DIFF_HEADER)
.contains(DIFF_FILE_A_MULTIPLE_REVISIONS);
.contains(DIFF_FILE_NO_CONFLICT);
}
@Test
@@ -43,12 +59,12 @@ public class GitDiffCommand_Merge_Test extends AbstractGitCommandTestBase {
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository, new SimpleGitWorkdirFactory(new WorkdirProvider()));
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
diffCommandRequest.setRevision("feature/print_args");
diffCommandRequest.setMergeChangeset("integration");
diffCommandRequest.setConflictBranch("integration");
ByteArrayOutputStream output = new ByteArrayOutputStream();
gitDiffCommand.getDiffResult(diffCommandRequest).accept(output);
assertThat(output.toString())
.contains(DIFF_HEADER)
.contains(DIFF_FILE_A_MULTIPLE_REVISIONS);
.contains(DIFF_FILE_CONFLICT);
}
@Override