diff options
author | Andre Bossert <andre.bossert@siemens.com> | 2019-03-08 22:31:34 +0100 |
---|---|---|
committer | Andrey Loskutov <loskutov@gmx.de> | 2022-05-25 13:52:04 +0200 |
commit | eaf4d500b886a7e776f50bf53497fe463e714b25 (patch) | |
tree | 740ac70c01372243cdbc8c902113ff144c8f3c2b /org.eclipse.jgit.pgm.test/tst/org/eclipse | |
parent | 85734356351ec2df4067b2472a37f6d9bcbb7350 (diff) | |
download | jgit-eaf4d500b886a7e776f50bf53497fe463e714b25.tar.gz jgit-eaf4d500b886a7e776f50bf53497fe463e714b25.zip |
Add mergetool merge feature (execute external tool)
see: https://git-scm.com/docs/git-mergetool
* implement mergetool merge function (execute external tool)
* add ExecutionResult and commandExecutionError to ToolException
* handle "base not present" case (empty or null base file path)
* handle deleted (rm) and modified (add) conflicts
* handle settings
* keepBackup
* keepTemporaries
* writeToTemp
Bug: 356832
Change-Id: Id323c2fcb1c24d12ceb299801df8bac51a6d463f
Signed-off-by: Andre Bossert <andre.bossert@siemens.com>
Diffstat (limited to 'org.eclipse.jgit.pgm.test/tst/org/eclipse')
-rw-r--r-- | org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DiffToolTest.java | 88 | ||||
-rw-r--r-- | org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeToolTest.java | 242 | ||||
-rw-r--r-- | org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ToolTestCase.java (renamed from org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ExternalToolTestCase.java) | 85 |
3 files changed, 364 insertions, 51 deletions
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DiffToolTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DiffToolTest.java index 017a5d994f..dc34c0d67b 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DiffToolTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DiffToolTest.java @@ -16,6 +16,7 @@ import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PROMPT; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_TOOL; import static org.junit.Assert.fail; +import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -30,7 +31,7 @@ import org.junit.Test; /** * Testing the {@code difftool} command. */ -public class DiffToolTest extends ExternalToolTestCase { +public class DiffToolTest extends ToolTestCase { private static final String DIFF_TOOL = CONFIG_DIFFTOOL_SECTION; @@ -41,6 +42,46 @@ public class DiffToolTest extends ExternalToolTestCase { configureEchoTool(TOOL_NAME); } + @Test + public void testToolWithPrompt() throws Exception { + String[] inputLines = { + "y", // accept launching diff tool + "y", // accept launching diff tool + }; + + RevCommit commit = createUnstagedChanges(); + List<DiffEntry> changes = getRepositoryChanges(commit); + String[] expectedOutput = getExpectedCompareOutput(changes); + + String option = "--tool"; + + InputStream inputStream = createInputStream(inputLines); + assertArrayOfLinesEquals("Incorrect output for option: " + option, + expectedOutput, runAndCaptureUsingInitRaw(inputStream, + DIFF_TOOL, "--prompt", option, TOOL_NAME)); + } + + @Test + public void testToolAbortLaunch() throws Exception { + String[] inputLines = { + "y", // accept launching diff tool + "n", // don't launch diff tool + }; + + RevCommit commit = createUnstagedChanges(); + List<DiffEntry> changes = getRepositoryChanges(commit); + int abortIndex = 1; + String[] expectedOutput = getExpectedAbortOutput(changes, abortIndex); + + String option = "--tool"; + + InputStream inputStream = createInputStream(inputLines); + assertArrayOfLinesEquals("Incorrect output for option: " + option, + expectedOutput, + runAndCaptureUsingInitRaw(inputStream, DIFF_TOOL, "--prompt", option, + TOOL_NAME)); + } + @Test(expected = Die.class) public void testNotDefinedTool() throws Exception { createUnstagedChanges(); @@ -53,7 +94,7 @@ public class DiffToolTest extends ExternalToolTestCase { public void testTool() throws Exception { RevCommit commit = createUnstagedChanges(); List<DiffEntry> changes = getRepositoryChanges(commit); - String[] expectedOutput = getExpectedToolOutput(changes); + String[] expectedOutput = getExpectedToolOutputNoPrompt(changes); String[] options = { "--tool", @@ -72,7 +113,7 @@ public class DiffToolTest extends ExternalToolTestCase { public void testToolTrustExitCode() throws Exception { RevCommit commit = createUnstagedChanges(); List<DiffEntry> changes = getRepositoryChanges(commit); - String[] expectedOutput = getExpectedToolOutput(changes); + String[] expectedOutput = getExpectedToolOutputNoPrompt(changes); String[] options = { "--tool", "-t", }; @@ -87,7 +128,7 @@ public class DiffToolTest extends ExternalToolTestCase { public void testToolNoGuiNoPromptNoTrustExitcode() throws Exception { RevCommit commit = createUnstagedChanges(); List<DiffEntry> changes = getRepositoryChanges(commit); - String[] expectedOutput = getExpectedToolOutput(changes); + String[] expectedOutput = getExpectedToolOutputNoPrompt(changes); String[] options = { "--tool", "-t", }; @@ -103,7 +144,7 @@ public class DiffToolTest extends ExternalToolTestCase { public void testToolCached() throws Exception { RevCommit commit = createStagedChanges(); List<DiffEntry> changes = getRepositoryChanges(commit); - String[] expectedOutput = getExpectedToolOutput(changes); + String[] expectedOutput = getExpectedToolOutputNoPrompt(changes); String[] options = { "--cached", "--staged", }; @@ -118,7 +159,8 @@ public class DiffToolTest extends ExternalToolTestCase { public void testToolHelp() throws Exception { CommandLineDiffTool[] defaultTools = CommandLineDiffTool.values(); List<String> expectedOutput = new ArrayList<>(); - expectedOutput.add("git difftool --tool=<tool> may be set to one of the following:"); + expectedOutput.add( + "'git difftool --tool=<tool>' may be set to one of the following:"); for (CommandLineDiffTool defaultTool : defaultTools) { String toolName = defaultTool.name(); expectedOutput.add(toolName); @@ -159,7 +201,7 @@ public class DiffToolTest extends ExternalToolTestCase { String.valueOf(false)); } - private String[] getExpectedToolOutput(List<DiffEntry> changes) { + private static String[] getExpectedToolOutputNoPrompt(List<DiffEntry> changes) { String[] expectedToolOutput = new String[changes.size()]; for (int i = 0; i < changes.size(); ++i) { DiffEntry change = changes.get(i); @@ -169,4 +211,36 @@ public class DiffToolTest extends ExternalToolTestCase { } return expectedToolOutput; } + + private static String[] getExpectedCompareOutput(List<DiffEntry> changes) { + List<String> expected = new ArrayList<>(); + int n = changes.size(); + for (int i = 0; i < n; ++i) { + DiffEntry change = changes.get(i); + String newPath = change.getNewPath(); + expected.add( + "Viewing (" + (i + 1) + "/" + n + "): '" + newPath + "'"); + expected.add("Launch '" + TOOL_NAME + "' [Y/n]?"); + expected.add(newPath); + } + return expected.toArray(new String[0]); + } + + private static String[] getExpectedAbortOutput(List<DiffEntry> changes, + int abortIndex) { + List<String> expected = new ArrayList<>(); + int n = changes.size(); + for (int i = 0; i < n; ++i) { + DiffEntry change = changes.get(i); + String newPath = change.getNewPath(); + expected.add( + "Viewing (" + (i + 1) + "/" + n + "): '" + newPath + "'"); + expected.add("Launch '" + TOOL_NAME + "' [Y/n]?"); + if (i == abortIndex) { + break; + } + expected.add(newPath); + } + return expected.toArray(new String[0]); + } } diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeToolTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeToolTest.java index 32cd60415e..2e50f09081 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeToolTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeToolTest.java @@ -15,6 +15,7 @@ import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_TOOL; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_MERGETOOL_SECTION; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_MERGE_SECTION; +import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -27,7 +28,7 @@ import org.junit.Test; /** * Testing the {@code mergetool} command. */ -public class MergeToolTest extends ExternalToolTestCase { +public class MergeToolTest extends ToolTestCase { private static final String MERGE_TOOL = CONFIG_MERGETOOL_SECTION; @@ -39,38 +40,122 @@ public class MergeToolTest extends ExternalToolTestCase { } @Test - public void testTool() throws Exception { - createMergeConflict(); - String[] expectedOutput = getExpectedToolOutput(); + public void testAbortMerge() throws Exception { + String[] inputLines = { + "y", // start tool for merge resolution + "n", // don't accept merge tool result + "n", // don't continue resolution + }; + String[] conflictingFilenames = createMergeConflict(); + int abortIndex = 1; + String[] expectedOutput = getExpectedAbortMergeOutput( + conflictingFilenames, + abortIndex); + + String option = "--tool"; + + InputStream inputStream = createInputStream(inputLines); + assertArrayOfLinesEquals("Incorrect output for option: " + option, + expectedOutput, runAndCaptureUsingInitRaw(inputStream, + MERGE_TOOL, "--prompt", option, TOOL_NAME)); + } - String[] options = { - "--tool", - "-t", + @Test + public void testAbortLaunch() throws Exception { + String[] inputLines = { + "n", // abort merge tool launch }; + String[] conflictingFilenames = createMergeConflict(); + String[] expectedOutput = getExpectedAbortLaunchOutput( + conflictingFilenames); - for (String option : options) { - assertArrayOfLinesEquals("Incorrect output for option: " + option, - expectedOutput, - runAndCaptureUsingInitRaw(MERGE_TOOL, option, - TOOL_NAME)); - } + String option = "--tool"; + + InputStream inputStream = createInputStream(inputLines); + assertArrayOfLinesEquals("Incorrect output for option: " + option, + expectedOutput, runAndCaptureUsingInitRaw(inputStream, + MERGE_TOOL, "--prompt", option, TOOL_NAME)); } @Test - public void testToolNoGuiNoPrompt() throws Exception { - createMergeConflict(); - String[] expectedOutput = getExpectedToolOutput(); + public void testMergeConflict() throws Exception { + String[] inputLines = { + "y", // start tool for merge resolution + "y", // accept merge result as successful + "y", // start tool for merge resolution + "y", // accept merge result as successful + }; + String[] conflictingFilenames = createMergeConflict(); + String[] expectedOutput = getExpectedMergeConflictOutput( + conflictingFilenames); + + String option = "--tool"; + + InputStream inputStream = createInputStream(inputLines); + assertArrayOfLinesEquals("Incorrect output for option: " + option, + expectedOutput, runAndCaptureUsingInitRaw(inputStream, + MERGE_TOOL, "--prompt", option, TOOL_NAME)); + } + + @Test + public void testDeletedConflict() throws Exception { + String[] inputLines = { + "d", // choose delete option to resolve conflict + "m", // choose merge option to resolve conflict + }; + String[] conflictingFilenames = createDeletedConflict(); + String[] expectedOutput = getExpectedDeletedConflictOutput( + conflictingFilenames); + + String option = "--tool"; + + InputStream inputStream = createInputStream(inputLines); + assertArrayOfLinesEquals("Incorrect output for option: " + option, + expectedOutput, runAndCaptureUsingInitRaw(inputStream, + MERGE_TOOL, "--prompt", option, TOOL_NAME)); + } + + @Test + public void testNoConflict() throws Exception { + createStagedChanges(); + String[] expectedOutput = { "No files need merging" }; String[] options = { "--tool", "-t", }; for (String option : options) { assertArrayOfLinesEquals("Incorrect output for option: " + option, - expectedOutput, runAndCaptureUsingInitRaw(MERGE_TOOL, - "--no-gui", "--no-prompt", option, TOOL_NAME)); + expectedOutput, + runAndCaptureUsingInitRaw(MERGE_TOOL, option, TOOL_NAME)); } } @Test + public void testMergeConflictNoPrompt() throws Exception { + String[] conflictingFilenames = createMergeConflict(); + String[] expectedOutput = getExpectedMergeConflictOutputNoPrompt( + conflictingFilenames); + + String option = "--tool"; + + assertArrayOfLinesEquals("Incorrect output for option: " + option, + expectedOutput, + runAndCaptureUsingInitRaw(MERGE_TOOL, option, TOOL_NAME)); + } + + @Test + public void testMergeConflictNoGuiNoPrompt() throws Exception { + String[] conflictingFilenames = createMergeConflict(); + String[] expectedOutput = getExpectedMergeConflictOutputNoPrompt( + conflictingFilenames); + + String option = "--tool"; + + assertArrayOfLinesEquals("Incorrect output for option: " + option, + expectedOutput, runAndCaptureUsingInitRaw(MERGE_TOOL, + "--no-gui", "--no-prompt", option, TOOL_NAME)); + } + + @Test public void testToolHelp() throws Exception { CommandLineMergeTool[] defaultTools = CommandLineMergeTool.values(); List<String> expectedOutput = new ArrayList<>(); @@ -87,8 +172,7 @@ public class MergeToolTest extends ExternalToolTestCase { String[] userDefinedToolsHelp = { "The following tools are valid, but not currently available:", "Some of the tools listed above only work in a windowed", - "environment. If run in a terminal-only session, they will fail.", - }; + "environment. If run in a terminal-only session, they will fail.", }; expectedOutput.addAll(Arrays.asList(userDefinedToolsHelp)); String option = "--tool-help"; @@ -116,21 +200,111 @@ public class MergeToolTest extends ExternalToolTestCase { String.valueOf(false)); } - private String[] getExpectedToolOutput() { - String[] mergeConflictFilenames = { "a", "b", }; - List<String> expectedOutput = new ArrayList<>(); - expectedOutput.add("Merging:"); - for (String mergeConflictFilename : mergeConflictFilenames) { - expectedOutput.add(mergeConflictFilename); + private static String[] getExpectedMergeConflictOutputNoPrompt( + String[] conflictFilenames) { + List<String> expected = new ArrayList<>(); + expected.add("Merging:"); + for (String conflictFilename : conflictFilenames) { + expected.add(conflictFilename); + } + for (String conflictFilename : conflictFilenames) { + expected.add("Normal merge conflict for '" + conflictFilename + + "':"); + expected.add("{local}: modified file"); + expected.add("{remote}: modified file"); + expected.add(conflictFilename); + expected.add(conflictFilename + " seems unchanged."); + } + return expected.toArray(new String[0]); + } + + private static String[] getExpectedAbortLaunchOutput( + String[] conflictFilenames) { + List<String> expected = new ArrayList<>(); + expected.add("Merging:"); + for (String conflictFilename : conflictFilenames) { + expected.add(conflictFilename); + } + if (conflictFilenames.length > 1) { + String conflictFilename = conflictFilenames[0]; + expected.add( + "Normal merge conflict for '" + conflictFilename + "':"); + expected.add("{local}: modified file"); + expected.add("{remote}: modified file"); + expected.add("Hit return to start merge resolution tool (" + + TOOL_NAME + "):"); + } + return expected.toArray(new String[0]); + } + + private static String[] getExpectedAbortMergeOutput( + String[] conflictFilenames, int abortIndex) { + List<String> expected = new ArrayList<>(); + expected.add("Merging:"); + for (String conflictFilename : conflictFilenames) { + expected.add(conflictFilename); + } + for (int i = 0; i < conflictFilenames.length; ++i) { + if (i == abortIndex) { + break; + } + + String conflictFilename = conflictFilenames[i]; + expected.add( + "Normal merge conflict for '" + conflictFilename + "':"); + expected.add("{local}: modified file"); + expected.add("{remote}: modified file"); + expected.add("Hit return to start merge resolution tool (" + + TOOL_NAME + "): " + conflictFilename); + expected.add(conflictFilename + " seems unchanged."); + expected.add("Was the merge successful [y/n]?"); + if (i < conflictFilenames.length - 1) { + expected.add( + "\tContinue merging other unresolved paths [y/n]?"); + } + } + return expected.toArray(new String[0]); + } + + private static String[] getExpectedMergeConflictOutput( + String[] conflictFilenames) { + List<String> expected = new ArrayList<>(); + expected.add("Merging:"); + for (String conflictFilename : conflictFilenames) { + expected.add(conflictFilename); + } + for (int i = 0; i < conflictFilenames.length; ++i) { + String conflictFilename = conflictFilenames[i]; + expected.add("Normal merge conflict for '" + conflictFilename + + "':"); + expected.add("{local}: modified file"); + expected.add("{remote}: modified file"); + expected.add("Hit return to start merge resolution tool (" + + TOOL_NAME + "): " + conflictFilename); + expected.add(conflictFilename + " seems unchanged."); + expected.add("Was the merge successful [y/n]?"); + if (i < conflictFilenames.length - 1) { + // expected.add( + // "\tContinue merging other unresolved paths [y/n]?"); + } + } + return expected.toArray(new String[0]); + } + + private static String[] getExpectedDeletedConflictOutput( + String[] conflictFilenames) { + List<String> expected = new ArrayList<>(); + expected.add("Merging:"); + for (String mergeConflictFilename : conflictFilenames) { + expected.add(mergeConflictFilename); } - for (String mergeConflictFilename : mergeConflictFilenames) { - expectedOutput.add("Normal merge conflict for '" - + mergeConflictFilename + "':"); - expectedOutput.add("{local}: modified file"); - expectedOutput.add("{remote}: modified file"); - expectedOutput.add("TODO: Launch mergetool '" + TOOL_NAME - + "' for path '" + mergeConflictFilename + "'..."); + for (int i = 0; i < conflictFilenames.length; ++i) { + String conflictFilename = conflictFilenames[i]; + expected.add(conflictFilename + " seems unchanged."); + expected.add("{local}: deleted"); + expected.add("{remote}: modified file"); + expected.add("Use (m)odified or (d)eleted file, or (a)bort?"); } - return expectedOutput.toArray(new String[0]); + return expected.toArray(new String[0]); } } diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ExternalToolTestCase.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ToolTestCase.java index e10b13efb1..d13eeb7e4d 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ExternalToolTestCase.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ToolTestCase.java @@ -11,10 +11,14 @@ package org.eclipse.jgit.pgm; import static org.junit.Assert.assertEquals; +import java.io.ByteArrayInputStream; +import java.io.InputStream; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; -import org.eclipse.jgit.api.CherryPickResult; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.diff.DiffEntry; import org.eclipse.jgit.lib.CLIRepositoryTestCase; @@ -29,7 +33,7 @@ import org.kohsuke.args4j.Argument; /** * Base test case for the {@code difftool} and {@code mergetool} commands. */ -public abstract class ExternalToolTestCase extends CLIRepositoryTestCase { +public abstract class ToolTestCase extends CLIRepositoryTestCase { public static class GitCliJGitWrapperParser { @Argument(index = 0, metaVar = "metaVar_command", required = true, handler = SubcommandHandler.class) @@ -56,6 +60,12 @@ public abstract class ExternalToolTestCase extends CLIRepositoryTestCase { protected String[] runAndCaptureUsingInitRaw(String... args) throws Exception { + InputStream inputStream = null; // no input stream + return runAndCaptureUsingInitRaw(inputStream, args); + } + + protected String[] runAndCaptureUsingInitRaw(InputStream inputStream, + String... args) throws Exception { CLIGitCommand.Result result = new CLIGitCommand.Result(); GitCliJGitWrapperParser bean = new GitCliJGitWrapperParser(); @@ -63,7 +73,7 @@ public abstract class ExternalToolTestCase extends CLIRepositoryTestCase { clp.parseArgument(args); TextBuiltin cmd = bean.subcommand; - cmd.initRaw(db, null, null, result.out, result.err); + cmd.initRaw(db, null, inputStream, result.out, result.err); cmd.execute(bean.arguments.toArray(new String[bean.arguments.size()])); if (cmd.getOutputWriter() != null) { cmd.getOutputWriter().flush(); @@ -71,28 +81,73 @@ public abstract class ExternalToolTestCase extends CLIRepositoryTestCase { if (cmd.getErrorWriter() != null) { cmd.getErrorWriter().flush(); } + + List<String> errLines = result.errLines().stream() + .filter(l -> !l.isBlank()) // we care only about error messages + .collect(Collectors.toList()); + assertEquals("Expected no standard error output from tool", + Collections.EMPTY_LIST.toString(), errLines.toString()); + return result.outLines().toArray(new String[0]); } - protected CherryPickResult createMergeConflict() throws Exception { + protected String[] createMergeConflict() throws Exception { + // create files on initial branch + git.checkout().setName(TEST_BRANCH_NAME).call(); writeTrashFile("a", "Hello world a"); writeTrashFile("b", "Hello world b"); git.add().addFilepattern(".").call(); git.commit().setMessage("files a & b added").call(); + // create another branch and change files + git.branchCreate().setName("branch_1").call(); + git.checkout().setName("branch_1").call(); writeTrashFile("a", "Hello world a 1"); writeTrashFile("b", "Hello world b 1"); git.add().addFilepattern(".").call(); - RevCommit commit1 = git.commit().setMessage("files a & b commit 1") - .call(); - git.branchCreate().setName("branch_1").call(); + RevCommit commit1 = git.commit() + .setMessage("files a & b modified commit 1").call(); + // checkout initial branch git.checkout().setName(TEST_BRANCH_NAME).call(); + // create another branch and change files + git.branchCreate().setName("branch_2").call(); + git.checkout().setName("branch_2").call(); writeTrashFile("a", "Hello world a 2"); writeTrashFile("b", "Hello world b 2"); git.add().addFilepattern(".").call(); - git.commit().setMessage("files a & b commit 2").call(); + git.commit().setMessage("files a & b modified commit 2").call(); + // cherry-pick conflicting changes + git.cherryPick().include(commit1).call(); + String[] conflictingFilenames = { "a", "b" }; + return conflictingFilenames; + } + + protected String[] createDeletedConflict() throws Exception { + // create files on initial branch + git.checkout().setName(TEST_BRANCH_NAME).call(); + writeTrashFile("a", "Hello world a"); + writeTrashFile("b", "Hello world b"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("files a & b added").call(); + // create another branch and change files + git.branchCreate().setName("branch_1").call(); + git.checkout().setName("branch_1").call(); + writeTrashFile("a", "Hello world a 1"); + writeTrashFile("b", "Hello world b 1"); + git.add().addFilepattern(".").call(); + RevCommit commit1 = git.commit() + .setMessage("files a & b modified commit 1").call(); + // checkout initial branch + git.checkout().setName(TEST_BRANCH_NAME).call(); + // create another branch and change files git.branchCreate().setName("branch_2").call(); - CherryPickResult result = git.cherryPick().include(commit1).call(); - return result; + git.checkout().setName("branch_2").call(); + git.rm().addFilepattern("a").call(); + git.rm().addFilepattern("b").call(); + git.commit().setMessage("files a & b deleted commit 2").call(); + // cherry-pick conflicting changes + git.cherryPick().include(commit1).call(); + String[] conflictingFilenames = { "a", "b" }; + return conflictingFilenames; } protected RevCommit createUnstagedChanges() throws Exception { @@ -121,6 +176,16 @@ public abstract class ExternalToolTestCase extends CLIRepositoryTestCase { return changes; } + protected static InputStream createInputStream(String[] inputLines) { + return createInputStream(Arrays.asList(inputLines)); + } + + protected static InputStream createInputStream(List<String> inputLines) { + String input = String.join(System.lineSeparator(), inputLines); + InputStream inputStream = new ByteArrayInputStream(input.getBytes()); + return inputStream; + } + protected static void assertArrayOfLinesEquals(String failMessage, String[] expected, String[] actual) { assertEquals(failMessage, toString(expected), toString(actual)); |