summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit
diff options
context:
space:
mode:
authorAndrey Loskutov <loskutov@gmx.de>2015-12-28 15:42:04 +0100
committerAndrey Loskutov <loskutov@gmx.de>2015-12-28 22:59:59 +0100
commit241b50be319e29cfae2ab1a5fcec94e7931074f8 (patch)
tree2d061ed7fe68dedb2cd31fef1d07689072c83296 /org.eclipse.jgit.pgm.test/src/org/eclipse/jgit
parentef757a7e126e059bd0afe64949440813df791de3 (diff)
downloadjgit-241b50be319e29cfae2ab1a5fcec94e7931074f8.tar.gz
jgit-241b50be319e29cfae2ab1a5fcec94e7931074f8.zip
Simplify development of commands: added main() to CLIGitCommand
This will execute git commands (with arguments) specified on the command line, handy for developing/debugging a sequence of arbitrary git commands working on same repository. The git working dir path can be specified via Java system property "git_work_tree". If not specified, current directory will be used. Change-Id: I621a9ec198c31e28a383818efeb4b3f835ba1d6f Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Diffstat (limited to 'org.eclipse.jgit.pgm.test/src/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java12
-rw-r--r--org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java31
2 files changed, 42 insertions, 1 deletions
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 4bdfa4d5bc..4bf9b43cbb 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
@@ -70,10 +70,20 @@ 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[] execute(String... cmds) throws Exception {
List<String> result = new ArrayList<String>(cmds.length);
- for (String cmd : cmds)
+ for (String cmd : cmds) {
result.addAll(CLIGitCommand.execute(cmd, db));
+ }
return result.toArray(new String[0]);
}
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..bf15fed812 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
@@ -43,10 +43,12 @@
package org.eclipse.jgit.pgm;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.text.MessageFormat;
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;
@@ -69,6 +71,35 @@ public class CLIGitCommand {
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 {
try {