diff options
4 files changed, 44 insertions, 2 deletions
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/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 { diff --git a/org.eclipse.jgit/META-INF/MANIFEST.MF b/org.eclipse.jgit/META-INF/MANIFEST.MF index 2a953b559d..66529d3afb 100644 --- a/org.eclipse.jgit/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit/META-INF/MANIFEST.MF @@ -65,7 +65,7 @@ Export-Package: org.eclipse.jgit.annotations;version="4.2.0", org.eclipse.jgit.junit, org.eclipse.jgit.junit.http, org.eclipse.jgit.http.server, - org.eclipse.jgit.java7.test, + org.eclipse.jgit.pgm.test, org.eclipse.jgit.pgm", org.eclipse.jgit.internal.storage.pack;version="4.2.0";x-friends:="org.eclipse.jgit.junit,org.eclipse.jgit.test,org.eclipse.jgit.pgm", org.eclipse.jgit.lib;version="4.2.0"; |