summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm.test
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2016-01-21 17:03:20 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2016-01-21 17:07:31 +0100
commit4ec84fac86c9652847630efc2dda3e69954fdb61 (patch)
tree537cf6ffb986dc361f25a91296c04c4b5599b705 /org.eclipse.jgit.pgm.test
parent7e8e4ec019f4ca4d9a1892c7c882eba6013fdeaa (diff)
parent7b6122908b2aa31555cee3e0cc9dde304e0d90b3 (diff)
downloadjgit-4ec84fac86c9652847630efc2dda3e69954fdb61.tar.gz
jgit-4ec84fac86c9652847630efc2dda3e69954fdb61.zip
Merge branch 'master' into stable-4.2
Change-Id: Ieec4f51aedadf5734ae0e3f4e8713248a3c4fc52 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.pgm.test')
-rw-r--r--org.eclipse.jgit.pgm.test/BUCK38
-rw-r--r--org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.jgit.pgm.test/org.eclipse.jgit.pgm--All-Tests (Java8) (de).launch30
-rw-r--r--org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java83
-rw-r--r--org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java177
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/AddTest.java15
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java95
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BranchTest.java196
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java41
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CommitTest.java100
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DescribeTest.java34
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeTest.java10
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/RepoTest.java28
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ResetTest.java39
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/StatusTest.java8
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/TagTest.java2
16 files changed, 769 insertions, 128 deletions
diff --git a/org.eclipse.jgit.pgm.test/BUCK b/org.eclipse.jgit.pgm.test/BUCK
new file mode 100644
index 0000000000..a3859c9b49
--- /dev/null
+++ b/org.eclipse.jgit.pgm.test/BUCK
@@ -0,0 +1,38 @@
+TESTS = glob(['tst/**/*.java'])
+
+for t in TESTS:
+ n = t[len('tst/'):len(t)-len('.java')].replace('/', '.')
+ java_test(
+ name = n,
+ labels = ['pgm'],
+ srcs = [t],
+ deps = [
+ ':helpers',
+ '//org.eclipse.jgit:jgit',
+ '//org.eclipse.jgit.archive:jgit-archive',
+ '//org.eclipse.jgit.junit:junit',
+ '//org.eclipse.jgit.pgm:pgm',
+ '//lib:hamcrest-core',
+ '//lib:hamcrest-library',
+ '//lib:javaewah',
+ '//lib:junit',
+ '//lib:slf4j-api',
+ '//lib:slf4j-simple',
+ '//lib:commons-compress',
+ '//lib:tukaani-xz',
+ ],
+ source_under_test = ['//org.eclipse.jgit.pgm:pgm'],
+ vm_args = ['-Xmx256m', '-Dfile.encoding=UTF-8'],
+ )
+
+java_library(
+ name = 'helpers',
+ srcs = glob(['src/**/*.java']),
+ deps = [
+ '//org.eclipse.jgit:jgit',
+ '//org.eclipse.jgit.pgm:pgm',
+ '//org.eclipse.jgit.junit:junit',
+ '//lib:args4j',
+ '//lib:junit',
+ ],
+)
diff --git a/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF
index db23c3b55f..2514fdff7e 100644
--- a/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF
@@ -11,6 +11,7 @@ Import-Package: org.eclipse.jgit.api;version="[4.2.0,4.3.0)",
org.eclipse.jgit.api.errors;version="[4.2.0,4.3.0)",
org.eclipse.jgit.diff;version="[4.2.0,4.3.0)",
org.eclipse.jgit.dircache;version="[4.2.0,4.3.0)",
+ org.eclipse.jgit.internal.storage.file;version="4.2.0",
org.eclipse.jgit.junit;version="[4.2.0,4.3.0)",
org.eclipse.jgit.lib;version="[4.2.0,4.3.0)",
org.eclipse.jgit.merge;version="[4.2.0,4.3.0)",
diff --git a/org.eclipse.jgit.pgm.test/org.eclipse.jgit.pgm--All-Tests (Java8) (de).launch b/org.eclipse.jgit.pgm.test/org.eclipse.jgit.pgm--All-Tests (Java8) (de).launch
new file mode 100644
index 0000000000..5c137f28fe
--- /dev/null
+++ b/org.eclipse.jgit.pgm.test/org.eclipse.jgit.pgm--All-Tests (Java8) (de).launch
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/org.eclipse.jgit.pgm.test/tst"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="2"/>
+</listAttribute>
+<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
+<mapAttribute key="org.eclipse.debug.core.environmentVariables">
+<mapEntry key="LANG" value="de_DE.UTF-8"/>
+</mapAttribute>
+<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
+<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
+<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=org.eclipse.jgit.pgm.test/tst"/>
+<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
+<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
+<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
+<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
+<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
+<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7&quot; path=&quot;1&quot; type=&quot;4&quot;/&gt;&#10;"/>
+<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;runtimeClasspathEntry id=&quot;org.eclipse.jdt.launching.classpathentry.defaultClasspath&quot;&gt;&#10;&lt;memento exportedEntriesOnly=&quot;false&quot; project=&quot;org.eclipse.jgit.pgm.test&quot;/&gt;&#10;&lt;/runtimeClasspathEntry&gt;&#10;"/>
+</listAttribute>
+<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
+<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.jgit.pgm.test"/>
+</launchConfiguration>
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 559a6d5d40..a6af077aa5 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
@@ -46,12 +46,16 @@ import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.pgm.CLIGitCommand;
+import org.eclipse.jgit.pgm.CLIGitCommand.Result;
+import org.eclipse.jgit.pgm.TextBuiltin.TerminatedByHelpException;
import org.junit.Before;
public class CLIRepositoryTestCase extends LocalDiskRepositoryTestCase {
@@ -69,13 +73,59 @@ public class CLIRepositoryTestCase extends LocalDiskRepositoryTestCase {
trash = db.getWorkTree();
}
+ /**
+ * Executes specified git commands (with arguments)
+ *
+ * @param cmds
+ * each string argument must be a valid git command line, e.g.
+ * "git branch -h"
+ * @return command output
+ * @throws Exception
+ */
+ protected String[] executeUnchecked(String... cmds) throws Exception {
+ List<String> result = new ArrayList<String>(cmds.length);
+ for (String cmd : cmds) {
+ result.addAll(CLIGitCommand.executeUnchecked(cmd, db));
+ }
+ return result.toArray(new String[0]);
+ }
+
+ /**
+ * Executes specified git commands (with arguments), throws exception and
+ * stops execution on first command which output contains a 'fatal:' error
+ *
+ * @param cmds
+ * each string argument must be a valid git command line, e.g.
+ * "git branch -h"
+ * @return command output
+ * @throws Exception
+ */
protected String[] execute(String... cmds) throws Exception {
List<String> result = new ArrayList<String>(cmds.length);
- for (String cmd : cmds)
- result.addAll(CLIGitCommand.execute(cmd, db));
+ for (String cmd : cmds) {
+ Result r = CLIGitCommand.executeRaw(cmd, db);
+ if (r.ex instanceof TerminatedByHelpException) {
+ result.addAll(r.errLines());
+ } else if (r.ex != null) {
+ throw r.ex;
+ }
+ result.addAll(r.outLines());
+ }
return result.toArray(new String[0]);
}
+ /**
+ * @param link
+ * the path of the symbolic link to create
+ * @param target
+ * the target of the symbolic link
+ * @return the path to the symbolic link
+ * @throws Exception
+ */
+ protected Path writeLink(String link, String target) throws Exception {
+ return JGitTestUtil.writeLink(db, link, target);
+ }
+
protected File writeTrashFile(final String name, final String data)
throws IOException {
return JGitTestUtil.writeTrashFile(db, name, data);
@@ -173,15 +223,36 @@ public class CLIRepositoryTestCase extends LocalDiskRepositoryTestCase {
}
protected void assertArrayOfLinesEquals(String[] expected, String[] actual) {
- assertEquals(toText(expected), toText(actual));
+ assertEquals(toString(expected), toString(actual));
+ }
+
+ public static String toString(String... lines) {
+ return toString(Arrays.asList(lines));
}
- private static String toText(String[] lines) {
+ public static String toString(List<String> lines) {
StringBuilder b = new StringBuilder();
for (String s : lines) {
- b.append(s);
- b.append('\n');
+ // trim indentation, to simplify tests
+ s = s.trim();
+ if (s != null && !s.isEmpty()) {
+ b.append(s);
+ b.append('\n');
+ }
+ }
+ // delete last line break to allow simpler tests with one line compare
+ if (b.length() > 0 && b.charAt(b.length() - 1) == '\n') {
+ b.deleteCharAt(b.length() - 1);
}
return b.toString();
}
+
+ public static boolean contains(List<String> lines, String str) {
+ for (String s : lines) {
+ if (s.contains(str)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java
index d77b1505ae..3f396563c2 100644
--- a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java
+++ b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java
@@ -42,71 +42,140 @@
*/
package org.eclipse.jgit.pgm;
+import static org.junit.Assert.assertNull;
+
import java.io.ByteArrayOutputStream;
-import java.text.MessageFormat;
+import java.io.File;
+
+import java.io.IOException;
+import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.pgm.internal.CLIText;
-import org.eclipse.jgit.pgm.opt.CmdLineParser;
-import org.eclipse.jgit.pgm.opt.SubcommandHandler;
+import org.eclipse.jgit.pgm.TextBuiltin.TerminatedByHelpException;
import org.eclipse.jgit.util.IO;
-import org.kohsuke.args4j.Argument;
-public class CLIGitCommand {
- @Argument(index = 0, metaVar = "metaVar_command", required = true, handler = SubcommandHandler.class)
- private TextBuiltin subcommand;
+public class CLIGitCommand extends Main {
- @Argument(index = 1, metaVar = "metaVar_arg")
- private List<String> arguments = new ArrayList<String>();
+ private final Result result;
- public TextBuiltin getSubcommand() {
- return subcommand;
+ private final Repository db;
+
+ public CLIGitCommand(Repository db) {
+ super();
+ this.db = db;
+ result = new Result();
}
- public List<String> getArguments() {
- return arguments;
+ /**
+ * Executes git commands (with arguments) specified on the command line. The
+ * git repository (same for all commands) can be specified via system
+ * property "-Dgit_work_tree=path_to_work_tree". If the property is not set,
+ * current directory is used.
+ *
+ * @param args
+ * each element in the array must be a valid git command line,
+ * e.g. "git branch -h"
+ * @throws Exception
+ */
+ public static void main(String[] args) throws Exception {
+ String workDir = System.getProperty("git_work_tree");
+ if (workDir == null) {
+ workDir = ".";
+ System.out.println(
+ "System property 'git_work_tree' not specified, using current directory: "
+ + new File(workDir).getAbsolutePath());
+ }
+ try (Repository db = new FileRepository(workDir + "/.git")) {
+ for (String cmd : args) {
+ List<String> result = execute(cmd, db);
+ for (String line : result) {
+ System.out.println(line);
+ }
+ }
+ }
}
public static List<String> execute(String str, Repository db)
throws Exception {
+ Result result = executeRaw(str, db);
+ return getOutput(result);
+ }
+
+ public static Result executeRaw(String str, Repository db)
+ throws Exception {
+ CLIGitCommand cmd = new CLIGitCommand(db);
+ cmd.run(str);
+ return cmd.result;
+ }
+
+ public static List<String> executeUnchecked(String str, Repository db)
+ throws Exception {
+ CLIGitCommand cmd = new CLIGitCommand(db);
+ try {
+ cmd.run(str);
+ return getOutput(cmd.result);
+ } catch (Throwable e) {
+ return cmd.result.errLines();
+ }
+ }
+
+ private static List<String> getOutput(Result result) {
+ if (result.ex instanceof TerminatedByHelpException) {
+ return result.errLines();
+ }
+ return result.outLines();
+ }
+
+ private void run(String commandLine) throws Exception {
+ String[] argv = convertToMainArgs(commandLine);
try {
- return IO.readLines(new String(rawExecute(str, db)));
- } catch (Die e) {
- return IO.readLines(MessageFormat.format(CLIText.get().fatalError,
- e.getMessage()));
+ super.run(argv);
+ } catch (TerminatedByHelpException e) {
+ // this is not a failure, super called exit() on help
+ } finally {
+ writer.flush();
}
}
- public static byte[] rawExecute(String str, Repository db)
+ private static String[] convertToMainArgs(String str)
throws Exception {
String[] args = split(str);
- if (!args[0].equalsIgnoreCase("git") || args.length < 2)
+ if (!args[0].equalsIgnoreCase("git") || args.length < 2) {
throw new IllegalArgumentException(
"Expected 'git <command> [<args>]', was:" + str);
+ }
String[] argv = new String[args.length - 1];
System.arraycopy(args, 1, argv, 0, args.length - 1);
+ return argv;
+ }
- CLIGitCommand bean = new CLIGitCommand();
- final CmdLineParser clp = new CmdLineParser(bean);
- clp.parseArgument(argv);
-
- final TextBuiltin cmd = bean.getSubcommand();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- cmd.outs = baos;
- if (cmd.requiresRepository())
- cmd.init(db, null);
- else
- cmd.init(null, null);
- try {
- cmd.execute(bean.getArguments().toArray(
- new String[bean.getArguments().size()]));
- } finally {
- if (cmd.outw != null)
- cmd.outw.flush();
+ @Override
+ PrintWriter createErrorWriter() {
+ return new PrintWriter(result.err);
+ }
+
+ void init(final TextBuiltin cmd) throws IOException {
+ cmd.outs = result.out;
+ cmd.errs = result.err;
+ super.init(cmd);
+ }
+
+ @Override
+ protected Repository openGitDir(String aGitdir) throws IOException {
+ assertNull(aGitdir);
+ return db;
+ }
+
+ @Override
+ void exit(int status, Exception t) throws Exception {
+ if (t == null) {
+ t = new IllegalStateException(Integer.toString(status));
}
- return baos.toByteArray();
+ result.ex = t;
+ throw t;
}
/**
@@ -164,4 +233,36 @@ public class CLIGitCommand {
return list.toArray(new String[list.size()]);
}
+ public static class Result {
+ public final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ public final ByteArrayOutputStream err = new ByteArrayOutputStream();
+
+ public Exception ex;
+
+ public byte[] outBytes() {
+ return out.toByteArray();
+ }
+
+ public byte[] errBytes() {
+ return err.toByteArray();
+ }
+
+ public String outString() {
+ return out.toString();
+ }
+
+ public List<String> outLines() {
+ return IO.readLines(out.toString());
+ }
+
+ public String errString() {
+ return err.toString();
+ }
+
+ public List<String> errLines() {
+ return IO.readLines(err.toString());
+ }
+ }
+
}
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/AddTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/AddTest.java
index 4253080a66..3edd9b88e8 100644
--- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/AddTest.java
+++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/AddTest.java
@@ -45,15 +45,12 @@ package org.eclipse.jgit.pgm;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-
-import java.lang.Exception;
-import java.lang.String;
+import static org.junit.Assert.fail;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
public class AddTest extends CLIRepositoryTestCase {
@@ -66,14 +63,16 @@ public class AddTest extends CLIRepositoryTestCase {
git = new Git(db);
}
- @Ignore("args4j exit()s on error instead of throwing, JVM goes down")
@Test
public void testAddNothing() throws Exception {
- assertEquals("fatal: Argument \"filepattern\" is required", //
- execute("git add")[0]);
+ try {
+ execute("git add");
+ fail("Must die");
+ } catch (Die e) {
+ // expected, requires argument
+ }
}
- @Ignore("args4j exit()s for --help, too")
@Test
public void testAddUsage() throws Exception {
execute("git add --help");
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 4222a2dcc3..a503ffdad0 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
@@ -52,17 +52,15 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
-import java.io.InputStreamReader;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.io.OutputStream;
-import java.lang.Object;
-import java.lang.String;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
-import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -71,9 +69,7 @@ import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
import org.eclipse.jgit.lib.FileMode;
-import org.eclipse.jgit.pgm.CLIGitCommand;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
public class ArchiveTest extends CLIRepositoryTestCase {
@@ -89,25 +85,26 @@ public class ArchiveTest extends CLIRepositoryTestCase {
emptyTree = db.resolve("HEAD^{tree}").abbreviate(12).name();
}
- @Ignore("Some versions of java.util.zip refuse to write an empty ZIP")
@Test
public void testEmptyArchive() throws Exception {
- byte[] result = CLIGitCommand.rawExecute(
- "git archive --format=zip " + emptyTree, db);
+ byte[] result = CLIGitCommand.executeRaw(
+ "git archive --format=zip " + emptyTree, db).outBytes();
assertArrayEquals(new String[0], listZipEntries(result));
}
@Test
public void testEmptyTar() throws Exception {
- byte[] result = CLIGitCommand.rawExecute(
- "git archive --format=tar " + emptyTree, db);
+ byte[] result = CLIGitCommand.executeRaw(
+ "git archive --format=tar " + emptyTree, db).outBytes();
assertArrayEquals(new String[0], listTarEntries(result));
}
@Test
public void testUnrecognizedFormat() throws Exception {
- String[] expect = new String[] { "fatal: Unknown archive format 'nonsense'" };
- String[] actual = execute("git archive --format=nonsense " + emptyTree);
+ String[] expect = new String[] {
+ "fatal: Unknown archive format 'nonsense'", "" };
+ String[] actual = executeUnchecked(
+ "git archive --format=nonsense " + emptyTree);
assertArrayEquals(expect, actual);
}
@@ -120,8 +117,8 @@ public class ArchiveTest extends CLIRepositoryTestCase {
git.add().addFilepattern("c").call();
git.commit().setMessage("populate toplevel").call();
- byte[] result = CLIGitCommand.rawExecute(
- "git archive --format=zip HEAD", db);
+ byte[] result = CLIGitCommand.executeRaw(
+ "git archive --format=zip HEAD", db).outBytes();
assertArrayEquals(new String[] { "a", "c" },
listZipEntries(result));
}
@@ -135,8 +132,8 @@ public class ArchiveTest extends CLIRepositoryTestCase {
@Test
public void testDefaultFormatIsTar() throws Exception {
commitGreeting();
- byte[] result = CLIGitCommand.rawExecute(
- "git archive HEAD", db);
+ byte[] result = CLIGitCommand.executeRaw(
+ "git archive HEAD", db).outBytes();
assertArrayEquals(new String[] { "greeting" },
listTarEntries(result));
}
@@ -302,8 +299,8 @@ public class ArchiveTest extends CLIRepositoryTestCase {
git.add().addFilepattern("b").call();
git.commit().setMessage("add subdir").call();
- byte[] result = CLIGitCommand.rawExecute(
- "git archive --format=zip master", db);
+ byte[] result = CLIGitCommand.executeRaw(
+ "git archive --format=zip master", db).outBytes();
String[] expect = { "a", "b.c", "b0c", "b/", "b/a", "b/b", "c" };
String[] actual = listZipEntries(result);
@@ -328,8 +325,8 @@ public class ArchiveTest extends CLIRepositoryTestCase {
git.add().addFilepattern("b").call();
git.commit().setMessage("add subdir").call();
- byte[] result = CLIGitCommand.rawExecute(
- "git archive --format=tar master", db);
+ byte[] result = CLIGitCommand.executeRaw(
+ "git archive --format=tar master", db).outBytes();
String[] expect = { "a", "b.c", "b0c", "b/", "b/a", "b/b", "c" };
String[] actual = listTarEntries(result);
@@ -349,8 +346,8 @@ public class ArchiveTest extends CLIRepositoryTestCase {
@Test
public void testArchivePrefixOption() throws Exception {
commitBazAndFooSlashBar();
- byte[] result = CLIGitCommand.rawExecute(
- "git archive --prefix=x/ --format=zip master", db);
+ byte[] result = CLIGitCommand.executeRaw(
+ "git archive --prefix=x/ --format=zip master", db).outBytes();
String[] expect = { "x/baz", "x/foo/", "x/foo/bar" };
String[] actual = listZipEntries(result);
@@ -362,8 +359,8 @@ public class ArchiveTest extends CLIRepositoryTestCase {
@Test
public void testTarPrefixOption() throws Exception {
commitBazAndFooSlashBar();
- byte[] result = CLIGitCommand.rawExecute(
- "git archive --prefix=x/ --format=tar master", db);
+ byte[] result = CLIGitCommand.executeRaw(
+ "git archive --prefix=x/ --format=tar master", db).outBytes();
String[] expect = { "x/baz", "x/foo/", "x/foo/bar" };
String[] actual = listTarEntries(result);
@@ -381,8 +378,8 @@ public class ArchiveTest extends CLIRepositoryTestCase {
@Test
public void testPrefixDoesNotNormalizeDoubleSlash() throws Exception {
commitFoo();
- byte[] result = CLIGitCommand.rawExecute(
- "git archive --prefix=x// --format=zip master", db);
+ byte[] result = CLIGitCommand.executeRaw(
+ "git archive --prefix=x// --format=zip master", db).outBytes();
String[] expect = { "x//foo" };
assertArrayEquals(expect, listZipEntries(result));
}
@@ -390,8 +387,8 @@ public class ArchiveTest extends CLIRepositoryTestCase {
@Test
public void testPrefixDoesNotNormalizeDoubleSlashInTar() throws Exception {
commitFoo();
- byte[] result = CLIGitCommand.rawExecute(
- "git archive --prefix=x// --format=tar master", db);
+ byte[] result = CLIGitCommand.executeRaw(
+ "git archive --prefix=x// --format=tar master", db).outBytes();
String[] expect = { "x//foo" };
assertArrayEquals(expect, listTarEntries(result));
}
@@ -408,8 +405,8 @@ public class ArchiveTest extends CLIRepositoryTestCase {
@Test
public void testPrefixWithoutTrailingSlash() throws Exception {
commitBazAndFooSlashBar();
- byte[] result = CLIGitCommand.rawExecute(
- "git archive --prefix=my- --format=zip master", db);
+ byte[] result = CLIGitCommand.executeRaw(
+ "git archive --prefix=my- --format=zip master", db).outBytes();
String[] expect = { "my-baz", "my-foo/", "my-foo/bar" };
String[] actual = listZipEntries(result);
@@ -421,8 +418,8 @@ public class ArchiveTest extends CLIRepositoryTestCase {
@Test
public void testTarPrefixWithoutTrailingSlash() throws Exception {
commitBazAndFooSlashBar();
- byte[] result = CLIGitCommand.rawExecute(
- "git archive --prefix=my- --format=tar master", db);
+ byte[] result = CLIGitCommand.executeRaw(
+ "git archive --prefix=my- --format=tar master", db).outBytes();
String[] expect = { "my-baz", "my-foo/", "my-foo/bar" };
String[] actual = listTarEntries(result);
@@ -441,8 +438,8 @@ public class ArchiveTest extends CLIRepositoryTestCase {
git.submoduleAdd().setURI("./.").setPath("b").call().close();
git.commit().setMessage("add submodule").call();
- byte[] result = CLIGitCommand.rawExecute(
- "git archive --format=zip master", db);
+ byte[] result = CLIGitCommand.executeRaw(
+ "git archive --format=zip master", db).outBytes();
String[] expect = { ".gitmodules", "a", "b/", "c" };
String[] actual = listZipEntries(result);
@@ -461,8 +458,8 @@ public class ArchiveTest extends CLIRepositoryTestCase {
git.submoduleAdd().setURI("./.").setPath("b").call().close();
git.commit().setMessage("add submodule").call();
- byte[] result = CLIGitCommand.rawExecute(
- "git archive --format=tar master", db);
+ byte[] result = CLIGitCommand.executeRaw(
+ "git archive --format=tar master", db).outBytes();
String[] expect = { ".gitmodules", "a", "b/", "c" };
String[] actual = listTarEntries(result);
@@ -491,8 +488,8 @@ public class ArchiveTest extends CLIRepositoryTestCase {
git.commit().setMessage("three files with different modes").call();
- byte[] zipData = CLIGitCommand.rawExecute(
- "git archive --format=zip master", db);
+ byte[] zipData = CLIGitCommand.executeRaw(
+ "git archive --format=zip master", db).outBytes();
writeRaw("zip-with-modes.zip", zipData);
assertContainsEntryWithMode("zip-with-modes.zip", "-rw-", "plain");
assertContainsEntryWithMode("zip-with-modes.zip", "-rwx", "executable");
@@ -520,8 +517,8 @@ public class ArchiveTest extends CLIRepositoryTestCase {
git.commit().setMessage("three files with different modes").call();
- byte[] archive = CLIGitCommand.rawExecute(
- "git archive --format=tar master", db);
+ byte[] archive = CLIGitCommand.executeRaw(
+ "git archive --format=tar master", db).outBytes();
writeRaw("with-modes.tar", archive);
assertTarContainsEntry("with-modes.tar", "-rw-r--r--", "plain");
assertTarContainsEntry("with-modes.tar", "-rwxr-xr-x", "executable");
@@ -543,8 +540,8 @@ public class ArchiveTest extends CLIRepositoryTestCase {
git.add().addFilepattern("1234567890").call();
git.commit().setMessage("file with long name").call();
- byte[] result = CLIGitCommand.rawExecute(
- "git archive --format=zip HEAD", db);
+ byte[] result = CLIGitCommand.executeRaw(
+ "git archive --format=zip HEAD", db).outBytes();
assertArrayEquals(l.toArray(new String[l.size()]),
listZipEntries(result));
}
@@ -563,8 +560,8 @@ public class ArchiveTest extends CLIRepositoryTestCase {
git.add().addFilepattern("1234567890").call();
git.commit().setMessage("file with long name").call();
- byte[] result = CLIGitCommand.rawExecute(
- "git archive --format=tar HEAD", db);
+ byte[] result = CLIGitCommand.executeRaw(
+ "git archive --format=tar HEAD", db).outBytes();
assertArrayEquals(l.toArray(new String[l.size()]),
listTarEntries(result));
}
@@ -576,8 +573,8 @@ public class ArchiveTest extends CLIRepositoryTestCase {
git.add().addFilepattern("xyzzy").call();
git.commit().setMessage("add file with content").call();
- byte[] result = CLIGitCommand.rawExecute(
- "git archive --format=zip HEAD", db);
+ byte[] result = CLIGitCommand.executeRaw(
+ "git archive --format=zip HEAD", db).outBytes();
assertArrayEquals(new String[] { payload },
zipEntryContent(result, "xyzzy"));
}
@@ -589,8 +586,8 @@ public class ArchiveTest extends CLIRepositoryTestCase {
git.add().addFilepattern("xyzzy").call();
git.commit().setMessage("add file with content").call();
- byte[] result = CLIGitCommand.rawExecute(
- "git archive --format=tar HEAD", db);
+ byte[] result = CLIGitCommand.executeRaw(
+ "git archive --format=tar HEAD", db).outBytes();
assertArrayEquals(new String[] { payload },
tarEntryContent(result, "xyzzy"));
}
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BranchTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BranchTest.java
index d1bd5baceb..55f4d8b1b8 100644
--- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BranchTest.java
+++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BranchTest.java
@@ -43,11 +43,17 @@
package org.eclipse.jgit.pgm;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.RefUpdate;
+import org.eclipse.jgit.pgm.internal.CLIText;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Before;
import org.junit.Test;
@@ -63,9 +69,19 @@ public class BranchTest extends CLIRepositoryTestCase {
}
@Test
+ public void testHelpAfterDelete() throws Exception {
+ String err = toString(executeUnchecked("git branch -d"));
+ String help = toString(executeUnchecked("git branch -h"));
+ String errAndHelp = toString(executeUnchecked("git branch -d -h"));
+ assertEquals(CLIText.fatalError(CLIText.get().branchNameRequired), err);
+ assertEquals(toString(err, help), errAndHelp);
+ }
+
+ @Test
public void testList() throws Exception {
+ assertEquals("* master", toString(execute("git branch")));
assertEquals("* master 6fd41be initial commit",
- execute("git branch -v")[0]);
+ toString(execute("git branch -v")));
}
@Test
@@ -73,26 +89,188 @@ public class BranchTest extends CLIRepositoryTestCase {
RefUpdate updateRef = db.updateRef(Constants.HEAD, true);
updateRef.setNewObjectId(db.resolve("6fd41be"));
updateRef.update();
- assertEquals("* (no branch) 6fd41be initial commit",
- execute("git branch -v")[0]);
+ assertEquals(
+ toString("* (no branch) 6fd41be initial commit",
+ "master 6fd41be initial commit"),
+ toString(execute("git branch -v")));
}
@Test
public void testListContains() throws Exception {
try (Git git = new Git(db)) {
- git.branchCreate().setName("initial").call();
+ git.branchCreate().setName("initial").call();
RevCommit second = git.commit().setMessage("second commit")
.call();
- assertArrayOfLinesEquals(new String[] { " initial", "* master", "" },
- execute("git branch --contains 6fd41be"));
- assertArrayOfLinesEquals(new String[] { "* master", "" },
- execute("git branch --contains " + second.name()));
+ assertEquals(toString(" initial", "* master"),
+ toString(execute("git branch --contains 6fd41be")));
+ assertEquals("* master",
+ toString(execute("git branch --contains " + second.name())));
}
}
@Test
public void testExistingBranch() throws Exception {
assertEquals("fatal: A branch named 'master' already exists.",
- execute("git branch master")[0]);
+ toString(executeUnchecked("git branch master")));
+ }
+
+ @Test
+ public void testRenameSingleArg() throws Exception {
+ try {
+ toString(execute("git branch -m"));
+ fail("Must die");
+ } catch (Die e) {
+ // expected, requires argument
+ }
+ String result = toString(execute("git branch -m slave"));
+ assertEquals("", result);
+ result = toString(execute("git branch -a"));
+ assertEquals("* slave", result);
+ }
+
+ @Test
+ public void testRenameTwoArgs() throws Exception {
+ String result = toString(execute("git branch -m master slave"));
+ assertEquals("", result);
+ result = toString(execute("git branch -a"));
+ assertEquals("* slave", result);
+ }
+
+ @Test
+ public void testCreate() throws Exception {
+ try {
+ toString(execute("git branch a b"));
+ fail("Must die");
+ } catch (Die e) {
+ // expected, too many arguments
+ }
+ String result = toString(execute("git branch second"));
+ assertEquals("", result);
+ result = toString(execute("git branch"));
+ assertEquals(toString("* master", "second"), result);
+ result = toString(execute("git branch -v"));
+ assertEquals(toString("* master 6fd41be initial commit",
+ "second 6fd41be initial commit"), result);
+ }
+
+ @Test
+ public void testDelete() throws Exception {
+ try {
+ toString(execute("git branch -d"));
+ fail("Must die");
+ } catch (Die e) {
+ // expected, requires argument
+ }
+ String result = toString(execute("git branch second"));
+ assertEquals("", result);
+ result = toString(execute("git branch -d second"));
+ assertEquals("", result);
+ result = toString(execute("git branch"));
+ assertEquals("* master", result);
+ }
+
+ @Test
+ public void testDeleteMultiple() throws Exception {
+ String result = toString(execute("git branch second",
+ "git branch third", "git branch fourth"));
+ assertEquals("", result);
+ result = toString(execute("git branch -d second third fourth"));
+ assertEquals("", result);
+ result = toString(execute("git branch"));
+ assertEquals("* master", result);
+ }
+
+ @Test
+ public void testDeleteForce() throws Exception {
+ try {
+ toString(execute("git branch -D"));
+ fail("Must die");
+ } catch (Die e) {
+ // expected, requires argument
+ }
+ String result = toString(execute("git branch second"));
+ assertEquals("", result);
+ result = toString(execute("git checkout second"));
+ assertEquals("Switched to branch 'second'", result);
+
+ File a = writeTrashFile("a", "a");
+ assertTrue(a.exists());
+ execute("git add a", "git commit -m 'added a'");
+
+ result = toString(execute("git checkout master"));
+ assertEquals("Switched to branch 'master'", result);
+
+ result = toString(execute("git branch"));
+ assertEquals(toString("* master", "second"), result);
+
+ try {
+ toString(execute("git branch -d second"));
+ fail("Must die");
+ } catch (Die e) {
+ // expected, the current HEAD is on second and not merged to master
+ }
+ result = toString(execute("git branch -D second"));
+ assertEquals("", result);
+
+ result = toString(execute("git branch"));
+ assertEquals("* master", result);
+ }
+
+ @Test
+ public void testDeleteForceMultiple() throws Exception {
+ String result = toString(execute("git branch second",
+ "git branch third", "git branch fourth"));
+
+ assertEquals("", result);
+ result = toString(execute("git checkout second"));
+ assertEquals("Switched to branch 'second'", result);
+
+ File a = writeTrashFile("a", "a");
+ assertTrue(a.exists());
+ execute("git add a", "git commit -m 'added a'");
+
+ result = toString(execute("git checkout master"));
+ assertEquals("Switched to branch 'master'", result);
+
+ result = toString(execute("git branch"));
+ assertEquals(toString("fourth", "* master", "second", "third"), result);
+
+ try {
+ toString(execute("git branch -d second third fourth"));
+ fail("Must die");
+ } catch (Die e) {
+ // expected, the current HEAD is on second and not merged to master
+ }
+ result = toString(execute("git branch"));
+ assertEquals(toString("fourth", "* master", "second", "third"), result);
+
+ result = toString(execute("git branch -D second third fourth"));
+ assertEquals("", result);
+
+ result = toString(execute("git branch"));
+ assertEquals("* master", result);
+ }
+
+ @Test
+ public void testCreateFromOldCommit() throws Exception {
+ File a = writeTrashFile("a", "a");
+ assertTrue(a.exists());
+ execute("git add a", "git commit -m 'added a'");
+ File b = writeTrashFile("b", "b");
+ assertTrue(b.exists());
+ execute("git add b", "git commit -m 'added b'");
+ String result = toString(execute("git log -n 1 --reverse"));
+ String firstCommitId = result.substring("commit ".length(),
+ result.indexOf('\n'));
+
+ result = toString(execute("git branch -f second " + firstCommitId));
+ assertEquals("", result);
+
+ result = toString(execute("git branch"));
+ assertEquals(toString("* master", "second"), result);
+
+ result = toString(execute("git checkout second"));
+ assertEquals("Switched to branch 'second'", result);
+ assertFalse(b.exists());
}
}
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java
index cb36d057e4..e690ad6964 100644
--- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java
+++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java
@@ -44,9 +44,14 @@ package org.eclipse.jgit.pgm;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
import java.util.List;
import org.eclipse.jgit.api.Git;
@@ -59,7 +64,9 @@ import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.FileTreeIterator.FileEntry;
import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FileUtils;
+import org.junit.Assume;
import org.junit.Test;
public class CheckoutTest extends CLIRepositoryTestCase {
@@ -109,14 +116,14 @@ public class CheckoutTest extends CLIRepositoryTestCase {
assertStringArrayEquals(
"fatal: A branch named 'master' already exists.",
- execute("git checkout -b master"));
+ executeUnchecked("git checkout -b master"));
}
}
@Test
public void testCheckoutNewBranchOnBranchToBeBorn() throws Exception {
assertStringArrayEquals("fatal: You are on a branch yet to be born",
- execute("git checkout -b side"));
+ executeUnchecked("git checkout -b side"));
}
@Test
@@ -599,4 +606,34 @@ public class CheckoutTest extends CLIRepositoryTestCase {
assertEquals("Hello world b", read(b));
}
}
+
+ @Test
+ public void testCheckouSingleFile() throws Exception {
+ try (Git git = new Git(db)) {
+ File a = writeTrashFile("a", "file a");
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("commit file a").call();
+ writeTrashFile("a", "b");
+ assertEquals("b", read(a));
+ assertEquals("[]", Arrays.toString(execute("git checkout -- a")));
+ assertEquals("file a", read(a));
+ }
+ }
+
+ @Test
+ public void testCheckoutLink() throws Exception {
+ Assume.assumeTrue(FS.DETECTED.supportsSymlinks());
+ try (Git git = new Git(db)) {
+ Path path = writeLink("a", "link_a");
+ assertTrue(Files.isSymbolicLink(path));
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("commit link a").call();
+ deleteTrashFile("a");
+ writeTrashFile("a", "Hello world a");
+ assertFalse(Files.isSymbolicLink(path));
+ assertEquals("[]", Arrays.toString(execute("git checkout -- a")));
+ assertEquals("link_a", FileUtils.readSymLink(path.toFile()));
+ assertTrue(Files.isSymbolicLink(path));
+ }
+ }
}
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CommitTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CommitTest.java
new file mode 100644
index 0000000000..6bccb6d4a7
--- /dev/null
+++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CommitTest.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2015, Andrey Loskutov <loskutov@gmx.de>
+ * 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 static org.junit.Assert.assertEquals;
+
+import org.eclipse.jgit.lib.CLIRepositoryTestCase;
+import org.junit.Test;
+
+public class CommitTest extends CLIRepositoryTestCase {
+
+ @Test
+ public void testCommitPath() throws Exception {
+ writeTrashFile("a", "a");
+ writeTrashFile("b", "a");
+ String result = toString(execute("git add a"));
+ assertEquals("", result);
+
+ result = toString(execute("git status -- a"));
+ assertEquals(toString("On branch master", "Changes to be committed:",
+ "new file: a"), result);
+
+ result = toString(execute("git status -- b"));
+ assertEquals(toString("On branch master", "Untracked files:", "b"),
+ result);
+
+ result = toString(execute("git commit a -m 'added a'"));
+ assertEquals(
+ "[master 8cb3ef7e5171aaee1792df6302a5a0cd30425f7a] added a",
+ result);
+
+ result = toString(execute("git status -- a"));
+ assertEquals("On branch master", result);
+
+ result = toString(execute("git status -- b"));
+ assertEquals(toString("On branch master", "Untracked files:", "b"),
+ result);
+ }
+
+ @Test
+ public void testCommitAll() throws Exception {
+ writeTrashFile("a", "a");
+ writeTrashFile("b", "a");
+ String result = toString(execute("git add a b"));
+ assertEquals("", result);
+
+ result = toString(execute("git status -- a b"));
+ assertEquals(toString("On branch master", "Changes to be committed:",
+ "new file: a", "new file: b"), result);
+
+ result = toString(execute("git commit -m 'added a b'"));
+ assertEquals(
+ "[master 3c93fa8e3a28ee26690498be78016edcb3a38c73] added a b",
+ result);
+
+ result = toString(execute("git status -- a b"));
+ assertEquals("On branch master", result);
+ }
+
+}
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DescribeTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DescribeTest.java
index 6352a26524..086e72e9a4 100644
--- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DescribeTest.java
+++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DescribeTest.java
@@ -43,9 +43,15 @@
package org.eclipse.jgit.pgm;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
+import org.eclipse.jgit.pgm.internal.CLIText;
import org.junit.Before;
import org.junit.Test;
@@ -67,17 +73,15 @@ public class DescribeTest extends CLIRepositoryTestCase {
@Test
public void testNoHead() throws Exception {
- assertArrayEquals(
- new String[] { "fatal: No names found, cannot describe anything." },
- execute("git describe"));
+ assertEquals(CLIText.fatalError(CLIText.get().noNamesFound),
+ toString(executeUnchecked("git describe")));
}
@Test
public void testHeadNoTag() throws Exception {
git.commit().setMessage("initial commit").call();
- assertArrayEquals(
- new String[] { "fatal: No names found, cannot describe anything." },
- execute("git describe"));
+ assertEquals(CLIText.fatalError(CLIText.get().noNamesFound),
+ toString(executeUnchecked("git describe")));
}
@Test
@@ -103,4 +107,22 @@ public class DescribeTest extends CLIRepositoryTestCase {
assertArrayEquals(new String[] { "v1.0-0-g6fd41be", "" },
execute("git describe --long HEAD"));
}
+
+ @Test
+ public void testHelpArgumentBeforeUnknown() throws Exception {
+ String[] output = execute("git describe -h -XYZ");
+ String all = Arrays.toString(output);
+ assertTrue("Unexpected help output: " + all,
+ all.contains("jgit describe"));
+ assertFalse("Unexpected help output: " + all, all.contains("fatal"));
+ }
+
+ @Test
+ public void testHelpArgumentAfterUnknown() throws Exception {
+ String[] output = executeUnchecked("git describe -XYZ -h");
+ String all = Arrays.toString(output);
+ assertTrue("Unexpected help output: " + all,
+ all.contains("jgit describe"));
+ assertTrue("Unexpected help output: " + all, all.contains("fatal"));
+ }
}
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeTest.java
index 975e8c4f76..47199016d4 100644
--- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeTest.java
+++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeTest.java
@@ -50,6 +50,7 @@ import java.util.Iterator;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
import org.eclipse.jgit.merge.MergeStrategy;
+import org.eclipse.jgit.pgm.internal.CLIText;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Before;
import org.junit.Test;
@@ -194,8 +195,9 @@ public class MergeTest extends CLIRepositoryTestCase {
@Test
public void testNoFastForwardAndSquash() throws Exception {
- assertEquals("fatal: You cannot combine --squash with --no-ff.",
- execute("git merge master --no-ff --squash")[0]);
+ assertEquals(
+ CLIText.fatalError(CLIText.get().cannotCombineSquashWithNoff),
+ executeUnchecked("git merge master --no-ff --squash")[0]);
}
@Test
@@ -209,8 +211,8 @@ public class MergeTest extends CLIRepositoryTestCase {
git.add().addFilepattern("file").call();
git.commit().setMessage("commit#2").call();
- assertEquals("fatal: Not possible to fast-forward, aborting.",
- execute("git merge master --ff-only")[0]);
+ assertEquals(CLIText.fatalError(CLIText.get().ffNotPossibleAborting),
+ executeUnchecked("git merge master --ff-only")[0]);
}
@Test
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/RepoTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/RepoTest.java
index 90efae286b..0eee771d2c 100644
--- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/RepoTest.java
+++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/RepoTest.java
@@ -44,8 +44,11 @@ package org.eclipse.jgit.pgm;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
+import java.util.Arrays;
+
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
@@ -98,6 +101,31 @@ public class RepoTest extends CLIRepositoryTestCase {
}
@Test
+ public void testMissingPath() throws Exception {
+ try {
+ execute("git repo");
+ fail("Must die");
+ } catch (Die e) {
+ // expected, requires argument
+ }
+ }
+
+ /**
+ * See bug 484951: "git repo -h" should not print unexpected values
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testZombieHelpArgument() throws Exception {
+ String[] output = execute("git repo -h");
+ String all = Arrays.toString(output);
+ assertTrue("Unexpected help output: " + all,
+ all.contains("jgit repo"));
+ assertFalse("Unexpected help output: " + all,
+ all.contains("jgit repo VAL"));
+ }
+
+ @Test
public void testAddRepoManifest() throws Exception {
StringBuilder xmlContent = new StringBuilder();
xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ResetTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ResetTest.java
index dae477928b..16c5889c48 100644
--- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ResetTest.java
+++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ResetTest.java
@@ -48,6 +48,7 @@ import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
public class ResetTest extends CLIRepositoryTestCase {
@@ -62,6 +63,20 @@ public class ResetTest extends CLIRepositoryTestCase {
}
@Test
+ public void testPathOptionHelp() throws Exception {
+ String[] result = execute("git reset -h");
+ assertTrue("Unexpected argument: " + result[1],
+ result[1].endsWith("[-- path ... ...]"));
+ }
+
+ @Test
+ public void testZombieArgument_Bug484951() throws Exception {
+ String[] result = execute("git reset -h");
+ assertFalse("Unexpected argument: " + result[0],
+ result[0].contains("[VAL ...]"));
+ }
+
+ @Test
public void testResetSelf() throws Exception {
RevCommit commit = git.commit().setMessage("initial commit").call();
assertStringArrayEquals("",
@@ -91,15 +106,28 @@ public class ResetTest extends CLIRepositoryTestCase {
@Test
public void testResetPathDoubleDash() throws Exception {
- resetPath(true);
+ resetPath(true, true);
}
@Test
public void testResetPathNoDoubleDash() throws Exception {
- resetPath(false);
+ resetPath(false, true);
+ }
+
+ @Test
+ public void testResetPathDoubleDashNoRef() throws Exception {
+ resetPath(true, false);
+ }
+
+ @Ignore("Currently we cannote recognize if a name is a commit-ish or a path, "
+ + "so 'git reset a' will not work if 'a' is not a branch name but a file path")
+ @Test
+ public void testResetPathNoDoubleDashNoRef() throws Exception {
+ resetPath(false, false);
}
- private void resetPath(boolean useDoubleDash) throws Exception {
+ private void resetPath(boolean useDoubleDash, boolean supplyCommit)
+ throws Exception {
// create files a and b
writeTrashFile("a", "Hello world a");
writeTrashFile("b", "Hello world b");
@@ -115,8 +143,9 @@ public class ResetTest extends CLIRepositoryTestCase {
git.add().addFilepattern(".").call();
// reset only file a
- String cmd = String.format("git reset %s%s a", commit.getId().name(),
- (useDoubleDash) ? " --" : "");
+ String cmd = String.format("git reset %s%s a",
+ supplyCommit ? commit.getId().name() : "",
+ useDoubleDash ? " --" : "");
assertStringArrayEquals("", execute(cmd));
assertEquals(commit.getId(),
git.getRepository().exactRef("HEAD").getObjectId());
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/StatusTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/StatusTest.java
index 854c52d88b..368047c602 100644
--- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/StatusTest.java
+++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/StatusTest.java
@@ -44,6 +44,7 @@ package org.eclipse.jgit.pgm;
import static org.eclipse.jgit.lib.Constants.MASTER;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
@@ -56,6 +57,13 @@ import org.junit.Test;
public class StatusTest extends CLIRepositoryTestCase {
@Test
+ public void testPathOptionHelp() throws Exception {
+ String[] result = execute("git status -h");
+ assertTrue("Unexpected argument: " + result[1],
+ result[1].endsWith("[-- path ... ...]"));
+ }
+
+ @Test
public void testStatusDefault() throws Exception {
executeTest("git status", false, true);
}
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/TagTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/TagTest.java
index ab09db5a56..0fe25f550a 100644
--- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/TagTest.java
+++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/TagTest.java
@@ -68,6 +68,6 @@ public class TagTest extends CLIRepositoryTestCase {
git.commit().setMessage("commit").call();
assertEquals("fatal: tag 'test' already exists",
- execute("git tag test")[0]);
+ executeUnchecked("git tag test")[0]);
}
}