diff options
author | Andrey Loskutov <loskutov@gmx.de> | 2022-05-30 12:42:20 -0400 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2022-05-30 12:42:20 -0400 |
commit | bb30be6b3335c67ee59d3705d5e04e2dbb688128 (patch) | |
tree | 6bb2c4188f1fac42120407a425774ad713e42780 /org.eclipse.jgit.pgm.test/tst/org/eclipse | |
parent | 8c681aac500d0755bd68f8b322f7fdb20cd2b8a1 (diff) | |
parent | e81085944f1a039566f2972c863d189724988b46 (diff) | |
download | jgit-bb30be6b3335c67ee59d3705d5e04e2dbb688128.tar.gz jgit-bb30be6b3335c67ee59d3705d5e04e2dbb688128.zip |
Merge "Add filtering with help of DirCacheCheckout.getContent()"
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 | 55 | ||||
-rw-r--r-- | org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ToolTestCase.java | 49 |
2 files changed, 47 insertions, 57 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 dc34c0d67b..8daaa6ad9e 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 @@ -21,10 +21,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.eclipse.jgit.diff.DiffEntry; import org.eclipse.jgit.internal.diffmergetool.CommandLineDiffTool; import org.eclipse.jgit.lib.StoredConfig; -import org.eclipse.jgit.revwalk.RevCommit; import org.junit.Before; import org.junit.Test; @@ -49,9 +47,8 @@ public class DiffToolTest extends ToolTestCase { "y", // accept launching diff tool }; - RevCommit commit = createUnstagedChanges(); - List<DiffEntry> changes = getRepositoryChanges(commit); - String[] expectedOutput = getExpectedCompareOutput(changes); + String[] conflictingFilenames = createUnstagedChanges(); + String[] expectedOutput = getExpectedCompareOutput(conflictingFilenames); String option = "--tool"; @@ -68,10 +65,9 @@ public class DiffToolTest extends ToolTestCase { "n", // don't launch diff tool }; - RevCommit commit = createUnstagedChanges(); - List<DiffEntry> changes = getRepositoryChanges(commit); + String[] conflictingFilenames = createUnstagedChanges(); int abortIndex = 1; - String[] expectedOutput = getExpectedAbortOutput(changes, abortIndex); + String[] expectedOutput = getExpectedAbortOutput(conflictingFilenames, abortIndex); String option = "--tool"; @@ -92,9 +88,8 @@ public class DiffToolTest extends ToolTestCase { @Test public void testTool() throws Exception { - RevCommit commit = createUnstagedChanges(); - List<DiffEntry> changes = getRepositoryChanges(commit); - String[] expectedOutput = getExpectedToolOutputNoPrompt(changes); + String[] conflictFilenames = createUnstagedChanges(); + String[] expectedOutput = getExpectedToolOutputNoPrompt(conflictFilenames); String[] options = { "--tool", @@ -111,9 +106,8 @@ public class DiffToolTest extends ToolTestCase { @Test public void testToolTrustExitCode() throws Exception { - RevCommit commit = createUnstagedChanges(); - List<DiffEntry> changes = getRepositoryChanges(commit); - String[] expectedOutput = getExpectedToolOutputNoPrompt(changes); + String[] conflictingFilenames = createUnstagedChanges(); + String[] expectedOutput = getExpectedToolOutputNoPrompt(conflictingFilenames); String[] options = { "--tool", "-t", }; @@ -126,9 +120,8 @@ public class DiffToolTest extends ToolTestCase { @Test public void testToolNoGuiNoPromptNoTrustExitcode() throws Exception { - RevCommit commit = createUnstagedChanges(); - List<DiffEntry> changes = getRepositoryChanges(commit); - String[] expectedOutput = getExpectedToolOutputNoPrompt(changes); + String[] conflictingFilenames = createUnstagedChanges(); + String[] expectedOutput = getExpectedToolOutputNoPrompt(conflictingFilenames); String[] options = { "--tool", "-t", }; @@ -142,9 +135,8 @@ public class DiffToolTest extends ToolTestCase { @Test public void testToolCached() throws Exception { - RevCommit commit = createStagedChanges(); - List<DiffEntry> changes = getRepositoryChanges(commit); - String[] expectedOutput = getExpectedToolOutputNoPrompt(changes); + String[] conflictingFilenames = createStagedChanges(); + String[] expectedOutput = getExpectedToolOutputNoPrompt(conflictingFilenames); String[] options = { "--cached", "--staged", }; @@ -201,23 +193,21 @@ public class DiffToolTest extends ToolTestCase { String.valueOf(false)); } - 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); - String newPath = change.getNewPath(); + private static String[] getExpectedToolOutputNoPrompt(String[] conflictingFilenames) { + String[] expectedToolOutput = new String[conflictingFilenames.length]; + for (int i = 0; i < conflictingFilenames.length; ++i) { + String newPath = conflictingFilenames[i]; String expectedLine = newPath; expectedToolOutput[i] = expectedLine; } return expectedToolOutput; } - private static String[] getExpectedCompareOutput(List<DiffEntry> changes) { + private static String[] getExpectedCompareOutput(String[] conflictingFilenames) { List<String> expected = new ArrayList<>(); - int n = changes.size(); + int n = conflictingFilenames.length; for (int i = 0; i < n; ++i) { - DiffEntry change = changes.get(i); - String newPath = change.getNewPath(); + String newPath = conflictingFilenames[i]; expected.add( "Viewing (" + (i + 1) + "/" + n + "): '" + newPath + "'"); expected.add("Launch '" + TOOL_NAME + "' [Y/n]?"); @@ -226,13 +216,12 @@ public class DiffToolTest extends ToolTestCase { return expected.toArray(new String[0]); } - private static String[] getExpectedAbortOutput(List<DiffEntry> changes, + private static String[] getExpectedAbortOutput(String[] conflictingFilenames, int abortIndex) { List<String> expected = new ArrayList<>(); - int n = changes.size(); + int n = conflictingFilenames.length; for (int i = 0; i < n; ++i) { - DiffEntry change = changes.get(i); - String newPath = change.getNewPath(); + String newPath = conflictingFilenames[i]; expected.add( "Viewing (" + (i + 1) + "/" + n + "): '" + newPath + "'"); expected.add("Launch '" + TOOL_NAME + "' [Y/n]?"); diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ToolTestCase.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ToolTestCase.java index d13eeb7e4d..933f19bcc4 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ToolTestCase.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ToolTestCase.java @@ -94,15 +94,15 @@ public abstract class ToolTestCase extends CLIRepositoryTestCase { 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"); + writeTrashFile("dir1/a", "Hello world a"); + writeTrashFile("dir2/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"); + writeTrashFile("dir1/a", "Hello world a 1"); + writeTrashFile("dir2/b", "Hello world b 1"); git.add().addFilepattern(".").call(); RevCommit commit1 = git.commit() .setMessage("files a & b modified commit 1").call(); @@ -111,28 +111,28 @@ public abstract class ToolTestCase extends CLIRepositoryTestCase { // 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"); + writeTrashFile("dir1/a", "Hello world a 2"); + writeTrashFile("dir2/b", "Hello world b 2"); git.add().addFilepattern(".").call(); git.commit().setMessage("files a & b modified commit 2").call(); // cherry-pick conflicting changes git.cherryPick().include(commit1).call(); - String[] conflictingFilenames = { "a", "b" }; + String[] conflictingFilenames = { "dir1/a", "dir2/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"); + writeTrashFile("dir1/a", "Hello world a"); + writeTrashFile("dir2/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"); + writeTrashFile("dir1/a", "Hello world a 1"); + writeTrashFile("dir2/b", "Hello world b 1"); git.add().addFilepattern(".").call(); RevCommit commit1 = git.commit() .setMessage("files a & b modified commit 1").call(); @@ -141,29 +141,30 @@ public abstract class ToolTestCase extends CLIRepositoryTestCase { // create another branch and change files git.branchCreate().setName("branch_2").call(); git.checkout().setName("branch_2").call(); - git.rm().addFilepattern("a").call(); - git.rm().addFilepattern("b").call(); + git.rm().addFilepattern("dir1/a").call(); + git.rm().addFilepattern("dir2/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" }; + String[] conflictingFilenames = { "dir1/a", "dir2/b" }; return conflictingFilenames; } - protected RevCommit createUnstagedChanges() throws Exception { - writeTrashFile("a", "Hello world a"); - writeTrashFile("b", "Hello world b"); + protected String[] createUnstagedChanges() throws Exception { + writeTrashFile("dir1/a", "Hello world a"); + writeTrashFile("dir2/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; + git.commit().setMessage("files a & b").call(); + writeTrashFile("dir1/a", "New Hello world a"); + writeTrashFile("dir2/b", "New Hello world b"); + String[] conflictingFilenames = { "dir1/a", "dir2/b" }; + return conflictingFilenames; } - protected RevCommit createStagedChanges() throws Exception { - RevCommit commit = createUnstagedChanges(); + protected String[] createStagedChanges() throws Exception { + String[] conflictingFilenames = createUnstagedChanges(); git.add().addFilepattern(".").call(); - return commit; + return conflictingFilenames; } protected List<DiffEntry> getRepositoryChanges(RevCommit commit) |