aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeToolTest.java
diff options
context:
space:
mode:
authorAndre Bossert <andre.bossert@siemens.com>2020-01-19 20:57:23 +0100
committerAndrey Loskutov <loskutov@gmx.de>2022-06-02 10:36:31 +0200
commitff77d412a9f1a956b8d76b139489038ee3b0870c (patch)
tree2e636007062bba558a674208d4a508f79fed2271 /org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeToolTest.java
parent973e955ead1a9bf41efb3168baf5b68527e78023 (diff)
downloadjgit-ff77d412a9f1a956b8d76b139489038ee3b0870c.tar.gz
jgit-ff77d412a9f1a956b8d76b139489038ee3b0870c.zip
Adapt diff- and merge tool code for PGM and EGit usage
see: https://git-scm.com/docs/git-mergetool * DiffTools and MergeTools * store FS, gitDir and workTree for usage without git repository (for EGit preferences) * add getUserDefinedToolNames() and getPredefinedToolNames() * replace getToolNames() with getAllToolNames() that combines the two lists and put default tool name (diff.tool or merge.tool) as first element (for EGit preferences) * FileElement: refactoring of getFile() and friends to have midName (LOCAL, REMOTE etc.) always added to the temp file name (also for EGit) * FileElement: added directory attribute that is used in getFile() to return path with workDir as parent * DiffTool and MergeTool * added errw.flush(), because sometimes stderr is not printed in case of die() * print e.getMessage() always to stderr * Moved toolname and prompt logic into managers * Exported internal packages required for egit.ui Bug: 356832 Change-Id: I71e7f4dc362169a7612ca4f6546a021bc4b2b5f4 Signed-off-by: Andre Bossert <andre.bossert@siemens.com> Signed-off-by: Tim Neumann <Tim.Neumann@advantest.com>
Diffstat (limited to 'org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeToolTest.java')
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeToolTest.java77
1 files changed, 71 insertions, 6 deletions
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 e9d559e70e..1236dd30d3 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
@@ -14,8 +14,10 @@ import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PROMPT;
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 static org.junit.Assert.fail;
import java.io.InputStream;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -42,6 +44,58 @@ public class MergeToolTest extends ToolTestCase {
}
@Test
+ public void testUndefinedTool() throws Exception {
+ String toolName = "undefined";
+ String[] conflictingFilenames = createMergeConflict();
+
+ List<String> expectedErrors = new ArrayList<>();
+ for (String conflictingFilename : conflictingFilenames) {
+ expectedErrors.add("External merge tool is not defined: " + toolName);
+ expectedErrors.add("merge of " + conflictingFilename + " failed");
+ }
+
+ runAndCaptureUsingInitRaw(expectedErrors, MERGE_TOOL,
+ "--no-prompt", "--tool", toolName);
+ }
+
+ @Test(expected = Die.class)
+ public void testUserToolWithCommandNotFoundError() throws Exception {
+ String toolName = "customTool";
+
+ int errorReturnCode = 127; // command not found
+ String command = "exit " + errorReturnCode;
+
+ StoredConfig config = db.getConfig();
+ config.setString(CONFIG_MERGETOOL_SECTION, toolName, CONFIG_KEY_CMD,
+ command);
+
+ createMergeConflict();
+ runAndCaptureUsingInitRaw(MERGE_TOOL, "--no-prompt", "--tool",
+ toolName);
+
+ fail("Expected exception to be thrown due to external tool exiting with error code: "
+ + errorReturnCode);
+ }
+
+ @Test
+ public void testEmptyToolName() throws Exception {
+ String emptyToolName = "";
+
+ StoredConfig config = db.getConfig();
+ // the default merge tool is configured without a subsection
+ String subsection = null;
+ config.setString(CONFIG_MERGE_SECTION, subsection, CONFIG_KEY_TOOL,
+ emptyToolName);
+
+ createMergeConflict();
+
+ String araxisErrorLine = "compare: unrecognized option `-wait' @ error/compare.c/CompareImageCommand/1123.";
+ String[] expectedErrorOutput = { araxisErrorLine, araxisErrorLine, };
+ runAndCaptureUsingInitRaw(Arrays.asList(expectedErrorOutput),
+ MERGE_TOOL, "--no-prompt");
+ }
+
+ @Test
public void testAbortMerge() throws Exception {
String[] inputLines = {
"y", // start tool for merge resolution
@@ -220,7 +274,7 @@ public class MergeToolTest extends ToolTestCase {
String.valueOf(false));
}
- private static String[] getExpectedMergeConflictOutputNoPrompt(
+ private String[] getExpectedMergeConflictOutputNoPrompt(
String[] conflictFilenames) {
List<String> expected = new ArrayList<>();
expected.add("Merging:");
@@ -232,7 +286,8 @@ public class MergeToolTest extends ToolTestCase {
+ "':");
expected.add("{local}: modified file");
expected.add("{remote}: modified file");
- expected.add(conflictFilename);
+ Path filePath = getFullPath(conflictFilename);
+ expected.add(filePath.toString());
expected.add(conflictFilename + " seems unchanged.");
}
return expected.toArray(new String[0]);
@@ -257,7 +312,7 @@ public class MergeToolTest extends ToolTestCase {
return expected.toArray(new String[0]);
}
- private static String[] getExpectedAbortMergeOutput(
+ private String[] getExpectedAbortMergeOutput(
String[] conflictFilenames, int abortIndex) {
List<String> expected = new ArrayList<>();
expected.add("Merging:");
@@ -274,8 +329,9 @@ public class MergeToolTest extends ToolTestCase {
"Normal merge conflict for '" + conflictFilename + "':");
expected.add("{local}: modified file");
expected.add("{remote}: modified file");
+ Path fullPath = getFullPath(conflictFilename);
expected.add("Hit return to start merge resolution tool ("
- + TOOL_NAME + "): " + conflictFilename);
+ + TOOL_NAME + "): " + fullPath);
expected.add(conflictFilename + " seems unchanged.");
expected.add("Was the merge successful [y/n]?");
if (i < conflictFilenames.length - 1) {
@@ -286,7 +342,7 @@ public class MergeToolTest extends ToolTestCase {
return expected.toArray(new String[0]);
}
- private static String[] getExpectedMergeConflictOutput(
+ private String[] getExpectedMergeConflictOutput(
String[] conflictFilenames) {
List<String> expected = new ArrayList<>();
expected.add("Merging:");
@@ -299,8 +355,9 @@ public class MergeToolTest extends ToolTestCase {
+ "':");
expected.add("{local}: modified file");
expected.add("{remote}: modified file");
+ Path filePath = getFullPath(conflictFilename);
expected.add("Hit return to start merge resolution tool ("
- + TOOL_NAME + "): " + conflictFilename);
+ + TOOL_NAME + "): " + filePath);
expected.add(conflictFilename + " seems unchanged.");
expected.add("Was the merge successful [y/n]?");
if (i < conflictFilenames.length - 1) {
@@ -327,4 +384,12 @@ public class MergeToolTest extends ToolTestCase {
}
return expected.toArray(new String[0]);
}
+
+ private static String getEchoCommand() {
+ /*
+ * use 'MERGED' placeholder, as both 'LOCAL' and 'REMOTE' will be
+ * replaced with full paths to a temporary file during some of the tests
+ */
+ return "(echo \"$MERGED\")";
+ }
}