diff options
Diffstat (limited to 'org.eclipse.jgit.pgm.test')
8 files changed, 171 insertions, 43 deletions
diff --git a/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF index b3d615c53c..4f747529f8 100644 --- a/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF @@ -1,30 +1,30 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 -Bundle-Name: %plugin_name +Bundle-Name: %Bundle-Name Automatic-Module-Name: org.eclipse.jgit.pgm.test Bundle-SymbolicName: org.eclipse.jgit.pgm.test -Bundle-Version: 5.4.4.qualifier -Bundle-Vendor: %provider_name +Bundle-Version: 5.5.0.qualifier +Bundle-Vendor: %Bundle-Vendor Bundle-Localization: plugin Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Import-Package: org.eclipse.jgit.api;version="[5.4.4,5.5.0)", - org.eclipse.jgit.api.errors;version="[5.4.4,5.5.0)", - org.eclipse.jgit.diff;version="[5.4.4,5.5.0)", - org.eclipse.jgit.dircache;version="[5.4.4,5.5.0)", - org.eclipse.jgit.internal.storage.file;version="5.4.4", - org.eclipse.jgit.junit;version="[5.4.4,5.5.0)", - org.eclipse.jgit.lib;version="[5.4.4,5.5.0)", - org.eclipse.jgit.merge;version="[5.4.4,5.5.0)", - org.eclipse.jgit.pgm;version="[5.4.4,5.5.0)", - org.eclipse.jgit.pgm.internal;version="[5.4.4,5.5.0)", - org.eclipse.jgit.pgm.opt;version="[5.4.4,5.5.0)", - org.eclipse.jgit.revwalk;version="[5.4.4,5.5.0)", - org.eclipse.jgit.storage.file;version="[5.4.4,5.5.0)", - org.eclipse.jgit.transport;version="[5.4.4,5.5.0)", - org.eclipse.jgit.treewalk;version="[5.4.4,5.5.0)", - org.eclipse.jgit.util;version="[5.4.4,5.5.0)", - org.eclipse.jgit.util.io;version="[5.4.4,5.5.0)", +Import-Package: org.eclipse.jgit.api;version="[5.5.0,5.6.0)", + org.eclipse.jgit.api.errors;version="[5.5.0,5.6.0)", + org.eclipse.jgit.diff;version="[5.5.0,5.6.0)", + org.eclipse.jgit.dircache;version="[5.5.0,5.6.0)", + org.eclipse.jgit.internal.storage.file;version="5.5.0", + org.eclipse.jgit.junit;version="[5.5.0,5.6.0)", + org.eclipse.jgit.lib;version="[5.5.0,5.6.0)", + org.eclipse.jgit.merge;version="[5.5.0,5.6.0)", + org.eclipse.jgit.pgm;version="[5.5.0,5.6.0)", + org.eclipse.jgit.pgm.internal;version="[5.5.0,5.6.0)", + org.eclipse.jgit.pgm.opt;version="[5.5.0,5.6.0)", + org.eclipse.jgit.revwalk;version="[5.5.0,5.6.0)", + org.eclipse.jgit.storage.file;version="[5.5.0,5.6.0)", + org.eclipse.jgit.transport;version="[5.5.0,5.6.0)", + org.eclipse.jgit.treewalk;version="[5.5.0,5.6.0)", + org.eclipse.jgit.util;version="[5.5.0,5.6.0)", + org.eclipse.jgit.util.io;version="[5.5.0,5.6.0)", org.hamcrest.core;bundle-version="[1.1.0,2.0.0)", org.junit;version="[4.12,5.0.0)", org.junit.rules;version="[4.12,5.0.0)", diff --git a/org.eclipse.jgit.pgm.test/plugin.properties b/org.eclipse.jgit.pgm.test/plugin.properties index e131c6970f..61cae8e35f 100644 --- a/org.eclipse.jgit.pgm.test/plugin.properties +++ b/org.eclipse.jgit.pgm.test/plugin.properties @@ -1,2 +1,2 @@ -plugin_name=JGit Command Line Interface Tests -provider_name=Eclipse JGit +Bundle-Name=JGit Command Line Interface Tests +Bundle-Vendor=Eclipse JGit diff --git a/org.eclipse.jgit.pgm.test/pom.xml b/org.eclipse.jgit.pgm.test/pom.xml index ecf3d70d5d..1d1c03b827 100644 --- a/org.eclipse.jgit.pgm.test/pom.xml +++ b/org.eclipse.jgit.pgm.test/pom.xml @@ -50,7 +50,7 @@ <parent> <groupId>org.eclipse.jgit</groupId> <artifactId>org.eclipse.jgit-parent</artifactId> - <version>5.4.4-SNAPSHOT</version> + <version>5.5.0-SNAPSHOT</version> </parent> <artifactId>org.eclipse.jgit.pgm.test</artifactId> diff --git a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java index a830ff2849..befb7f62ac 100644 --- a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java +++ b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java @@ -211,6 +211,14 @@ public class CLIRepositoryTestCase extends LocalDiskRepositoryTestCase { .replaceAll("\t", "\\\\t"); } + protected String shellQuote(String s) { + return "'" + s.replace("'", "'\\''") + "'"; + } + + protected String shellQuote(File f) { + return "'" + f.getPath().replace("'", "'\\''") + "'"; + } + protected void assertStringArrayEquals(String expected, String[] actual) { // if there is more than one line, ignore last one if empty assertEquals(1, diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java index e07fdd50d2..03aa469898 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java @@ -139,10 +139,6 @@ public class ArchiveTest extends CLIRepositoryTestCase { listTarEntries(result)); } - private static String shellQuote(String s) { - return "'" + s.replace("'", "'\\''") + "'"; - } - @Test public void testFormatOverridesFilename() throws Exception { File archive = new File(db.getWorkTree(), "format-overrides-name.tar"); diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BlameTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BlameTest.java new file mode 100644 index 0000000000..e806872c14 --- /dev/null +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BlameTest.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2019 Thomas Wolf <thomas.wolf@paranor.ch> + * and other copyright owners as documented in the project's IP log. + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Distribution License v1.0 which + * accompanies this distribution, is reproduced below, and is + * available at http://www.eclipse.org/org/documents/edl-v10.php + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.eclipse.jgit.pgm; + +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.lib.CLIRepositoryTestCase; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class BlameTest extends CLIRepositoryTestCase { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void testBlameNoHead() throws Exception { + try (Git git = new Git(db)) { + writeTrashFile("inIndex.txt", "index"); + git.add().addFilepattern("inIndex.txt").call(); + } + thrown.expect(Die.class); + thrown.expectMessage("no such ref: HEAD"); + execute("git blame inIndex.txt"); + } + + @Test + public void testBlameCommitted() throws Exception { + try (Git git = new Git(db)) { + git.commit().setMessage("initial commit").call(); + writeTrashFile("committed.txt", "committed"); + git.add().addFilepattern("committed.txt").call(); + git.commit().setMessage("commit").call(); + } + assertStringArrayEquals( + "1ad3399c (GIT_COMMITTER_NAME 2009-08-15 20:12:58 -0330 1) committed", + execute("git blame committed.txt")); + } + + @Test + public void testBlameStaged() throws Exception { + try (Git git = new Git(db)) { + git.commit().setMessage("initial commit").call(); + writeTrashFile("inIndex.txt", "index"); + git.add().addFilepattern("inIndex.txt").call(); + } + assertStringArrayEquals( + " (Not Committed Yet 1) index", + execute("git blame inIndex.txt")); + } + + @Test + public void testBlameUnstaged() throws Exception { + try (Git git = new Git(db)) { + git.commit().setMessage("initial commit").call(); + } + writeTrashFile("onlyInWorkingTree.txt", "not in repo"); + thrown.expect(Die.class); + thrown.expectMessage("no such path 'onlyInWorkingTree.txt' in HEAD"); + execute("git blame onlyInWorkingTree.txt"); + } + + @Test + public void testBlameNonExisting() throws Exception { + try (Git git = new Git(db)) { + git.commit().setMessage("initial commit").call(); + } + thrown.expect(Die.class); + thrown.expectMessage("no such path 'does_not_exist.txt' in HEAD"); + execute("git blame does_not_exist.txt"); + } + + @Test + public void testBlameNonExistingInSubdir() throws Exception { + try (Git git = new Git(db)) { + git.commit().setMessage("initial commit").call(); + } + thrown.expect(Die.class); + thrown.expectMessage("no such path 'sub/does_not_exist.txt' in HEAD"); + execute("git blame sub/does_not_exist.txt"); + } +} diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CloneTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CloneTest.java index 2c0abd78a5..c31f28c256 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CloneTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CloneTest.java @@ -78,9 +78,9 @@ public class CloneTest extends CLIRepositoryTestCase { File gitDir = db.getDirectory(); String sourceURI = gitDir.toURI().toString(); File target = createTempDirectory("target"); - StringBuilder cmd = new StringBuilder("git clone ").append(sourceURI - + " " + target.getPath()); - String[] result = execute(cmd.toString()); + String cmd = "git clone " + sourceURI + " " + + shellQuote(target.getPath()); + String[] result = execute(cmd); assertArrayEquals(new String[] { "Cloning into '" + target.getPath() + "'...", "", "" }, result); @@ -101,9 +101,9 @@ public class CloneTest extends CLIRepositoryTestCase { File gitDir = db.getDirectory(); String sourceURI = gitDir.toURI().toString(); File target = createTempDirectory("target"); - StringBuilder cmd = new StringBuilder("git clone ").append(sourceURI - + " " + target.getPath()); - String[] result = execute(cmd.toString()); + String cmd = "git clone " + sourceURI + " " + + shellQuote(target.getPath()); + String[] result = execute(cmd); assertArrayEquals(new String[] { "Cloning into '" + target.getPath() + "'...", "warning: You appear to have cloned an empty repository.", "", @@ -125,8 +125,8 @@ public class CloneTest extends CLIRepositoryTestCase { File gitDir = db.getDirectory(); String sourceURI = gitDir.toURI().toString(); String name = new URIish(sourceURI).getHumanishName(); - StringBuilder cmd = new StringBuilder("git clone ").append(sourceURI); - String[] result = execute(cmd.toString()); + String cmd = "git clone " + sourceURI; + String[] result = execute(cmd); assertArrayEquals(new String[] { "Cloning into '" + new File(target, name).getName() + "'...", "", "" }, result); @@ -143,10 +143,10 @@ public class CloneTest extends CLIRepositoryTestCase { String sourcePath = gitDir.getAbsolutePath(); String targetPath = (new File(sourcePath)).getParentFile() .getParentFile().getAbsolutePath() - + "/target.git"; - StringBuilder cmd = new StringBuilder("git clone --bare ") - .append(sourcePath + " " + targetPath); - String[] result = execute(cmd.toString()); + + File.separator + "target.git"; + String cmd = "git clone --bare " + shellQuote(sourcePath) + " " + + shellQuote(targetPath); + String[] result = execute(cmd); assertArrayEquals(new String[] { "Cloning into '" + targetPath + "'...", "", "" }, result); Git git2 = Git.open(new File(targetPath)); diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/LsRemoteTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/LsRemoteTest.java index ba6b771de5..fd3c383764 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/LsRemoteTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/LsRemoteTest.java @@ -80,7 +80,7 @@ public class LsRemoteTest extends CLIRepositoryTestCase { @Test public void testLsRemote() throws Exception { final List<String> result = CLIGitCommand.execute( - "git ls-remote " + db.getDirectory(), db); + "git ls-remote " + shellQuote(db.getDirectory()), db); assertArrayEquals(new String[] { "d0b1ef2b3dea02bb2ca824445c04e6def012c32c HEAD", "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/master", @@ -98,7 +98,8 @@ public class LsRemoteTest extends CLIRepositoryTestCase { public void testLsRemoteHeads() throws Exception { final List<String> result = CLIGitCommand.execute( "git ls-remote --heads " - + db.getDirectory(), db); + + shellQuote(db.getDirectory()), + db); assertArrayEquals(new String[] { "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/master", "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/test", @@ -108,7 +109,7 @@ public class LsRemoteTest extends CLIRepositoryTestCase { @Test public void testLsRemoteTags() throws Exception { final List<String> result = CLIGitCommand.execute( - "git ls-remote --tags " + db.getDirectory(), db); + "git ls-remote --tags " + shellQuote(db.getDirectory()), db); assertArrayEquals(new String[] { "efc02078d83a5226986ae917323acec7e1e8b7cb refs/tags/tag1", "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/tags/tag1^{}", @@ -122,7 +123,8 @@ public class LsRemoteTest extends CLIRepositoryTestCase { @Test public void testLsRemoteHeadsTags() throws Exception { final List<String> result = CLIGitCommand.execute( - "git ls-remote --heads --tags " + db.getDirectory(), db); + "git ls-remote --heads --tags " + shellQuote(db.getDirectory()), + db); assertArrayEquals(new String[] { "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/master", "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/test", |