From 973e955ead1a9bf41efb3168baf5b68527e78023 Mon Sep 17 00:00:00 2001 From: Andre Bossert Date: Sun, 19 Jan 2020 20:56:28 +0100 Subject: Add availability check of pre-defined tools see: https://git-scm.com/docs/git-difftool see: https://git-scm.com/docs/git-mergetool * now all available tools are printed with "--tool-help" * if no diff.tool or merge.tool is defined the first available pre-defined tool is used TODO: - add mergetools to difftools --> extra change or merge to this - return the exit-code of the tool to jgit / java runtime Bug: 356832 Change-Id: I20fb04e71ced981f5625020f461bbac24e6cec70 Signed-off-by: Andre Bossert --- .../tst/org/eclipse/jgit/pgm/DiffToolTest.java | 30 ++++++++++++++++++---- .../tst/org/eclipse/jgit/pgm/MergeToolTest.java | 30 ++++++++++++++++++---- 2 files changed, 50 insertions(+), 10 deletions(-) (limited to 'org.eclipse.jgit.pgm.test/tst/org') 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 8daaa6ad9e..a258821f0c 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 @@ -20,8 +20,10 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; -import org.eclipse.jgit.internal.diffmergetool.CommandLineDiffTool; +import org.eclipse.jgit.internal.diffmergetool.DiffTools; +import org.eclipse.jgit.internal.diffmergetool.ExternalDiffTool; import org.eclipse.jgit.lib.StoredConfig; import org.junit.Before; import org.junit.Test; @@ -149,20 +151,38 @@ public class DiffToolTest extends ToolTestCase { @Test public void testToolHelp() throws Exception { - CommandLineDiffTool[] defaultTools = CommandLineDiffTool.values(); List expectedOutput = new ArrayList<>(); + + DiffTools diffTools = new DiffTools(db); + Map predefinedTools = diffTools + .getPredefinedTools(true); + List availableTools = new ArrayList<>(); + List notAvailableTools = new ArrayList<>(); + for (ExternalDiffTool tool : predefinedTools.values()) { + if (tool.isAvailable()) { + availableTools.add(tool); + } else { + notAvailableTools.add(tool); + } + } + expectedOutput.add( "'git difftool --tool=' may be set to one of the following:"); - for (CommandLineDiffTool defaultTool : defaultTools) { - String toolName = defaultTool.name(); + for (ExternalDiffTool tool : availableTools) { + String toolName = tool.getName(); expectedOutput.add(toolName); } String customToolHelpLine = TOOL_NAME + "." + CONFIG_KEY_CMD + " " + getEchoCommand(); expectedOutput.add("user-defined:"); expectedOutput.add(customToolHelpLine); + expectedOutput.add( + "The following tools are valid, but not currently available:"); + for (ExternalDiffTool tool : notAvailableTools) { + String toolName = tool.getName(); + expectedOutput.add(toolName); + } 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.", }; 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 2e50f09081..e9d559e70e 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 @@ -19,8 +19,10 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; -import org.eclipse.jgit.internal.diffmergetool.CommandLineMergeTool; +import org.eclipse.jgit.internal.diffmergetool.ExternalMergeTool; +import org.eclipse.jgit.internal.diffmergetool.MergeTools; import org.eclipse.jgit.lib.StoredConfig; import org.junit.Before; import org.junit.Test; @@ -157,20 +159,38 @@ public class MergeToolTest extends ToolTestCase { @Test public void testToolHelp() throws Exception { - CommandLineMergeTool[] defaultTools = CommandLineMergeTool.values(); List expectedOutput = new ArrayList<>(); + + MergeTools diffTools = new MergeTools(db); + Map predefinedTools = diffTools + .getPredefinedTools(true); + List availableTools = new ArrayList<>(); + List notAvailableTools = new ArrayList<>(); + for (ExternalMergeTool tool : predefinedTools.values()) { + if (tool.isAvailable()) { + availableTools.add(tool); + } else { + notAvailableTools.add(tool); + } + } + expectedOutput.add( "'git mergetool --tool=' may be set to one of the following:"); - for (CommandLineMergeTool defaultTool : defaultTools) { - String toolName = defaultTool.name(); + for (ExternalMergeTool tool : availableTools) { + String toolName = tool.getName(); expectedOutput.add(toolName); } String customToolHelpLine = TOOL_NAME + "." + CONFIG_KEY_CMD + " " + getEchoCommand(); expectedOutput.add("user-defined:"); expectedOutput.add(customToolHelpLine); + expectedOutput.add( + "The following tools are valid, but not currently available:"); + for (ExternalMergeTool tool : notAvailableTools) { + String toolName = tool.getName(); + expectedOutput.add(toolName); + } 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.", }; expectedOutput.addAll(Arrays.asList(userDefinedToolsHelp)); -- cgit v1.2.3