summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit
diff options
context:
space:
mode:
authorAndre Bossert <andre.bossert@siemens.com>2020-01-19 20:41:23 +0100
committerSimeon Andreev <simeon.danailov.andreev@gmail.com>2021-12-08 10:43:00 +0100
commit14a59bdc7b37c85591eed07bc60c3f4fdcde2a8a (patch)
treefea19991aa9b034079a8e0acf437aadb750fb076 /org.eclipse.jgit.test/tst/org/eclipse/jgit
parentcaea5a26f08c6cf969607a178bc54896120d0940 (diff)
downloadjgit-14a59bdc7b37c85591eed07bc60c3f4fdcde2a8a.tar.gz
jgit-14a59bdc7b37c85591eed07bc60c3f4fdcde2a8a.zip
Add config reader for user-defined difftools
see: http://git-scm.com/docs/git-difftool * add config reader for user-defined difftools * diff.tool * diff.guitool * difftool.prompt * difftool.trustExitCode * difftool.<tool>.path * difftool.<tool>.cmd * add pre-defined difftools * implemented "git difftool --tool-help" to verify config reader and pre-defined difftools Bug: 356832 Change-Id: Idde8fddbef61f3378ee565c6321570b3962d0e1d Signed-off-by: Andre Bossert <andre.bossert@siemens.com> Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/diffmergetool/ExternalDiffToolTest.java68
1 files changed, 56 insertions, 12 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/diffmergetool/ExternalDiffToolTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/diffmergetool/ExternalDiffToolTest.java
index f07d9d1afc..b141a86f76 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/diffmergetool/ExternalDiffToolTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/diffmergetool/ExternalDiffToolTest.java
@@ -9,9 +9,18 @@
*/
package org.eclipse.jgit.internal.diffmergetool;
+import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_DIFFTOOL_SECTION;
+import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_CMD;
+import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_GUITOOL;
+import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PATH;
+import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PROMPT;
+import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_TRUST_EXIT_CODE;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Map;
import java.util.Set;
import org.eclipse.jgit.lib.internal.BooleanTriState;
@@ -29,27 +38,64 @@ public class ExternalDiffToolTest extends ExternalToolTest {
Set<String> actualToolNames = manager.getToolNames();
Set<String> expectedToolNames = Collections.emptySet();
assertEquals("Incorrect set of external diff tool names",
- expectedToolNames,
- actualToolNames);
+ expectedToolNames, actualToolNames);
}
@Test
public void testAllTools() {
DiffTools manager = new DiffTools(db);
Set<String> actualToolNames = manager.getAvailableTools().keySet();
- Set<String> expectedToolNames = Collections.emptySet();
- assertEquals("Incorrect set of available external diff tools",
- expectedToolNames,
+ Set<String> expectedToolNames = new LinkedHashSet<>();
+ CommandLineDiffTool[] defaultTools = CommandLineDiffTool.values();
+ for (CommandLineDiffTool defaultTool : defaultTools) {
+ String toolName = defaultTool.name();
+ expectedToolNames.add(toolName);
+ }
+ assertEquals("Incorrect set of external diff tools", expectedToolNames,
actualToolNames);
}
@Test
+ public void testOverridePredefinedToolPath() {
+ String toolName = CommandLineDiffTool.guiffy.name();
+ String customToolPath = "/usr/bin/echo";
+
+ FileBasedConfig config = db.getConfig();
+ config.setString(CONFIG_DIFFTOOL_SECTION, toolName, CONFIG_KEY_CMD,
+ "echo");
+ config.setString(CONFIG_DIFFTOOL_SECTION, toolName, CONFIG_KEY_PATH,
+ customToolPath);
+
+ DiffTools manager = new DiffTools(db);
+ Map<String, ExternalDiffTool> tools = manager.getUserDefinedTools();
+ ExternalDiffTool diffTool = tools.get(toolName);
+ assertNotNull("Expected tool \"" + toolName + "\" to be user defined",
+ diffTool);
+
+ String toolPath = diffTool.getPath();
+ assertEquals("Expected external diff tool to have an overriden path",
+ customToolPath, toolPath);
+ }
+
+ @Test
public void testUserDefinedTools() {
+ FileBasedConfig config = db.getConfig();
+ String customToolname = "customTool";
+ config.setString(CONFIG_DIFFTOOL_SECTION, customToolname,
+ CONFIG_KEY_CMD, "echo");
+ config.setString(CONFIG_DIFFTOOL_SECTION, customToolname,
+ CONFIG_KEY_PATH, "/usr/bin/echo");
+ config.setString(CONFIG_DIFFTOOL_SECTION, customToolname,
+ CONFIG_KEY_PROMPT, "--no-prompt");
+ config.setString(CONFIG_DIFFTOOL_SECTION, customToolname,
+ CONFIG_KEY_GUITOOL, "--no-gui");
+ config.setString(CONFIG_DIFFTOOL_SECTION, customToolname,
+ CONFIG_KEY_TRUST_EXIT_CODE, "--no-trust-exit-code");
DiffTools manager = new DiffTools(db);
Set<String> actualToolNames = manager.getUserDefinedTools().keySet();
- Set<String> expectedToolNames = Collections.emptySet();
- assertEquals("Incorrect set of user defined external diff tools",
- expectedToolNames,
+ Set<String> expectedToolNames = new LinkedHashSet<>();
+ expectedToolNames.add(customToolname);
+ assertEquals("Incorrect set of external diff tools", expectedToolNames,
actualToolNames);
}
@@ -59,8 +105,7 @@ public class ExternalDiffToolTest extends ExternalToolTest {
Set<String> actualToolNames = manager.getNotAvailableTools().keySet();
Set<String> expectedToolNames = Collections.emptySet();
assertEquals("Incorrect set of not available external diff tools",
- expectedToolNames,
- actualToolNames);
+ expectedToolNames, actualToolNames);
}
@Test
@@ -80,8 +125,7 @@ public class ExternalDiffToolTest extends ExternalToolTest {
int compareResult = manager.compare(newPath, oldPath, newId, oldId,
toolName, prompt, gui, trustExitCode);
assertEquals("Incorrect compare result for external diff tool",
- expectedCompareResult,
- compareResult);
+ expectedCompareResult, compareResult);
}
@Test