summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm.test
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.pgm.test')
-rw-r--r--org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF37
-rw-r--r--org.eclipse.jgit.pgm.test/pom.xml2
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DiffToolTest.java195
3 files changed, 215 insertions, 19 deletions
diff --git a/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF
index c5b6b8d0d9..3e0a4eaf20 100644
--- a/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF
@@ -3,28 +3,29 @@ Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Automatic-Module-Name: org.eclipse.jgit.pgm.test
Bundle-SymbolicName: org.eclipse.jgit.pgm.test
-Bundle-Version: 6.0.0.qualifier
+Bundle-Version: 6.1.0.qualifier
Bundle-Vendor: %Bundle-Vendor
Bundle-Localization: plugin
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-11
-Import-Package: org.eclipse.jgit.api;version="[6.0.0,6.1.0)",
- org.eclipse.jgit.api.errors;version="[6.0.0,6.1.0)",
- org.eclipse.jgit.diff;version="[6.0.0,6.1.0)",
- org.eclipse.jgit.dircache;version="[6.0.0,6.1.0)",
- org.eclipse.jgit.internal.storage.file;version="6.0.0",
- org.eclipse.jgit.junit;version="[6.0.0,6.1.0)",
- org.eclipse.jgit.lib;version="[6.0.0,6.1.0)",
- org.eclipse.jgit.merge;version="[6.0.0,6.1.0)",
- org.eclipse.jgit.pgm;version="[6.0.0,6.1.0)",
- org.eclipse.jgit.pgm.internal;version="[6.0.0,6.1.0)",
- org.eclipse.jgit.pgm.opt;version="[6.0.0,6.1.0)",
- org.eclipse.jgit.revwalk;version="[6.0.0,6.1.0)",
- org.eclipse.jgit.storage.file;version="[6.0.0,6.1.0)",
- org.eclipse.jgit.transport;version="[6.0.0,6.1.0)",
- org.eclipse.jgit.treewalk;version="[6.0.0,6.1.0)",
- org.eclipse.jgit.util;version="[6.0.0,6.1.0)",
- org.eclipse.jgit.util.io;version="[6.0.0,6.1.0)",
+Import-Package: org.eclipse.jgit.api;version="[6.1.0,6.2.0)",
+ org.eclipse.jgit.api.errors;version="[6.1.0,6.2.0)",
+ org.eclipse.jgit.diff;version="[6.1.0,6.2.0)",
+ org.eclipse.jgit.dircache;version="[6.1.0,6.2.0)",
+ org.eclipse.jgit.internal.storage.file;version="6.1.0",
+ org.eclipse.jgit.junit;version="[6.1.0,6.2.0)",
+ org.eclipse.jgit.lib;version="[6.1.0,6.2.0)",
+ org.eclipse.jgit.lib.internal;version="[6.1.0,6.2.0)",
+ org.eclipse.jgit.merge;version="[6.1.0,6.2.0)",
+ org.eclipse.jgit.pgm;version="[6.1.0,6.2.0)",
+ org.eclipse.jgit.pgm.internal;version="[6.1.0,6.2.0)",
+ org.eclipse.jgit.pgm.opt;version="[6.1.0,6.2.0)",
+ org.eclipse.jgit.revwalk;version="[6.1.0,6.2.0)",
+ org.eclipse.jgit.storage.file;version="[6.1.0,6.2.0)",
+ org.eclipse.jgit.transport;version="[6.1.0,6.2.0)",
+ org.eclipse.jgit.treewalk;version="[6.1.0,6.2.0)",
+ org.eclipse.jgit.util;version="[6.1.0,6.2.0)",
+ org.eclipse.jgit.util.io;version="[6.1.0,6.2.0)",
org.hamcrest.core;bundle-version="[2.2.0,3.0.0)",
org.junit;version="[4.13,5.0.0)",
org.junit.rules;version="[4.13,5.0.0)",
diff --git a/org.eclipse.jgit.pgm.test/pom.xml b/org.eclipse.jgit.pgm.test/pom.xml
index 83d5369363..eea5970ab1 100644
--- a/org.eclipse.jgit.pgm.test/pom.xml
+++ b/org.eclipse.jgit.pgm.test/pom.xml
@@ -17,7 +17,7 @@
<parent>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit-parent</artifactId>
- <version>6.0.0-SNAPSHOT</version>
+ <version>6.1.0-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.jgit.pgm.test</artifactId>
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
new file mode 100644
index 0000000000..2ce50c7827
--- /dev/null
+++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DiffToolTest.java
@@ -0,0 +1,195 @@
+/*
+ * Copyright (C) 2021, Simeon Andreev <simeon.danailov.andreev@gmail.com> and others.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+package org.eclipse.jgit.pgm;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.diff.DiffEntry;
+import org.eclipse.jgit.lib.CLIRepositoryTestCase;
+import org.eclipse.jgit.pgm.opt.CmdLineParser;
+import org.eclipse.jgit.pgm.opt.SubcommandHandler;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.treewalk.FileTreeIterator;
+import org.eclipse.jgit.treewalk.TreeWalk;
+import org.junit.Before;
+import org.junit.Test;
+import org.kohsuke.args4j.Argument;
+
+/**
+ * Testing the {@code difftool} command.
+ */
+public class DiffToolTest extends CLIRepositoryTestCase {
+ public static class GitCliJGitWrapperParser {
+ @Argument(index = 0, metaVar = "metaVar_command", required = true, handler = SubcommandHandler.class)
+ TextBuiltin subcommand;
+
+ @Argument(index = 1, metaVar = "metaVar_arg")
+ List<String> arguments = new ArrayList<>();
+ }
+
+ private String[] runAndCaptureUsingInitRaw(String... args)
+ throws Exception {
+ CLIGitCommand.Result result = new CLIGitCommand.Result();
+
+ GitCliJGitWrapperParser bean = new GitCliJGitWrapperParser();
+ CmdLineParser clp = new CmdLineParser(bean);
+ clp.parseArgument(args);
+
+ TextBuiltin cmd = bean.subcommand;
+ cmd.initRaw(db, null, null, result.out, result.err);
+ cmd.execute(bean.arguments.toArray(new String[bean.arguments.size()]));
+ if (cmd.getOutputWriter() != null) {
+ cmd.getOutputWriter().flush();
+ }
+ if (cmd.getErrorWriter() != null) {
+ cmd.getErrorWriter().flush();
+ }
+ return result.outLines().toArray(new String[0]);
+ }
+
+ private Git git;
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ git = new Git(db);
+ git.commit().setMessage("initial commit").call();
+ }
+
+ @Test
+ public void testTool() throws Exception {
+ RevCommit commit = createUnstagedChanges();
+ List<DiffEntry> changes = getRepositoryChanges(commit);
+ String[] expectedOutput = getExpectedDiffToolOutput(changes);
+
+ String[] options = {
+ "--tool",
+ "-t",
+ };
+
+ for (String option : options) {
+ assertArrayOfLinesEquals("Incorrect output for option: " + option,
+ expectedOutput,
+ runAndCaptureUsingInitRaw("difftool", option,
+ "some_tool"));
+ }
+ }
+
+ @Test
+ public void testToolTrustExitCode() throws Exception {
+ RevCommit commit = createUnstagedChanges();
+ List<DiffEntry> changes = getRepositoryChanges(commit);
+ String[] expectedOutput = getExpectedDiffToolOutput(changes);
+
+ String[] options = { "--tool", "-t", };
+
+ for (String option : options) {
+ assertArrayOfLinesEquals("Incorrect output for option: " + option,
+ expectedOutput, runAndCaptureUsingInitRaw("difftool",
+ "--trust-exit-code", option, "some_tool"));
+ }
+ }
+
+ @Test
+ public void testToolNoGuiNoPromptNoTrustExitcode() throws Exception {
+ RevCommit commit = createUnstagedChanges();
+ List<DiffEntry> changes = getRepositoryChanges(commit);
+ String[] expectedOutput = getExpectedDiffToolOutput(changes);
+
+ String[] options = { "--tool", "-t", };
+
+ for (String option : options) {
+ assertArrayOfLinesEquals("Incorrect output for option: " + option,
+ expectedOutput, runAndCaptureUsingInitRaw("difftool",
+ "--no-gui", "--no-prompt", "--no-trust-exit-code",
+ option, "some_tool"));
+ }
+ }
+
+ @Test
+ public void testToolCached() throws Exception {
+ RevCommit commit = createStagedChanges();
+ List<DiffEntry> changes = getRepositoryChanges(commit);
+ String[] expectedOutput = getExpectedDiffToolOutput(changes);
+
+ String[] options = { "--cached", "--staged", };
+
+ for (String option : options) {
+ assertArrayOfLinesEquals("Incorrect output for option: " + option,
+ expectedOutput, runAndCaptureUsingInitRaw("difftool",
+ option, "--tool", "some_tool"));
+ }
+ }
+
+ @Test
+ public void testToolHelp() throws Exception {
+ String[] expectedOutput = {
+ "git difftool --tool=<tool> may be set to one of the following:",
+ "user-defined:",
+ "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.", };
+
+ String option = "--tool-help";
+ assertArrayOfLinesEquals("Incorrect output for option: " + option,
+ expectedOutput, runAndCaptureUsingInitRaw("difftool", option));
+ }
+
+ private RevCommit createUnstagedChanges() throws Exception {
+ writeTrashFile("a", "Hello world a");
+ writeTrashFile("b", "Hello world b");
+ git.add().addFilepattern(".").call();
+ RevCommit commit = git.commit().setMessage("files a & b").call();
+ writeTrashFile("a", "New Hello world a");
+ writeTrashFile("b", "New Hello world b");
+ return commit;
+ }
+
+ private RevCommit createStagedChanges() throws Exception {
+ RevCommit commit = createUnstagedChanges();
+ git.add().addFilepattern(".").call();
+ return commit;
+ }
+
+ private List<DiffEntry> getRepositoryChanges(RevCommit commit)
+ throws Exception {
+ TreeWalk tw = new TreeWalk(db);
+ tw.addTree(commit.getTree());
+ FileTreeIterator modifiedTree = new FileTreeIterator(db);
+ tw.addTree(modifiedTree);
+ List<DiffEntry> changes = DiffEntry.scan(tw);
+ return changes;
+ }
+
+ private String[] getExpectedDiffToolOutput(List<DiffEntry> changes) {
+ String[] expectedToolOutput = new String[changes.size()];
+ for (int i = 0; i < changes.size(); ++i) {
+ DiffEntry change = changes.get(i);
+ String newPath = change.getNewPath();
+ String oldPath = change.getOldPath();
+ String newIdName = change.getNewId().name();
+ String oldIdName = change.getOldId().name();
+ String expectedLine = "M\t" + newPath + " (" + newIdName + ")"
+ + "\t" + oldPath + " (" + oldIdName + ")";
+ expectedToolOutput[i] = expectedLine;
+ }
+ return expectedToolOutput;
+ }
+
+ private static void assertArrayOfLinesEquals(String failMessage,
+ String[] expected, String[] actual) {
+ assertEquals(failMessage, toString(expected), toString(actual));
+ }
+}