import java.io.File;\r
import java.io.PrintStream;\r
import java.net.URL;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
\r
import org.eclipse.jgit.pgm.Main;\r
import org.tizen.common.ui.Activator;\r
import org.tizen.common.util.HostUtil;\r
import org.tizen.common.util.OSChecker;\r
import org.tizen.common.util.PluginUtil;\r
+import org.tizen.common.util.StringUtil;\r
\r
public class JGitCLI extends Main {\r
private String gitdir;\r
public void run(PrintStream out) throws Exception {\r
String origDirectory = getDirectory();\r
try {\r
- if (getCommand() == null || getCommand().isEmpty()) {\r
+ if (StringUtil.isEmpty(getCommand())) {\r
// to print "The most commonly used commands are:"\r
setDirectory(null);\r
}\r
- /*\r
List<String> args = new ArrayList<String>();\r
- if (getDirectory() != null) {\r
- args.add("--git-dir");\r
- args.add(getDirectory() + File.separator + ".git");\r
- }\r
+ GitCommandType cmdType = null;\r
if (getCommand() != null) {\r
- for (String c : getCommand().split(" "))\r
- args.add(c);\r
+ String[] gitCommands = getCommand().split(" ");\r
+ for (String gitCommand : gitCommands)\r
+ args.add(gitCommand);\r
+ try {\r
+ cmdType = GitCommandType.valueOf(args.get(0));\r
+ } catch (Exception e) {\r
+ }\r
}\r
- */\r
\r
- File gitPath = findGitDir();\r
- if (gitPath == null) {\r
- out.println("fatal: Not a git repository (or any of the parent directories): .git");\r
- return;\r
- }\r
// I'll run jgit-cli by another process:\r
// - To display process OutputStream in ConsoleManager\r
// - To prevent System.exit() codes in org.eclipse.jgit.pgm.Main\r
// /D:/common-eplugin/org.tizen.common.ui/lib/jgit-cli.jar\r
jarPath = jarPath.substring(1);\r
}\r
- String command = String.format("java -jar %s --git-dir %s %s", jarPath, gitPath, getCommand());\r
- String returnExecute = HostUtil.returnExecute(command, null, true);\r
+\r
+ String jarCommand = String.format("java -jar %s", jarPath);\r
+ String executeCommand = null;\r
+ if (cmdType != null) {\r
+ File gitPath = findGitDir();\r
+ if (cmdType.needsDotGit && gitPath == null) {\r
+ out.println("fatal: Not a git repository (or any of the parent directories): .git");\r
+ return;\r
+ }\r
+ if (cmdType.needsGitDir) {\r
+ executeCommand = String.format("%s --git-dir %s %s", jarCommand, cmdType.findsGitDir ? gitPath : getDirectory(), getCommand());\r
+ } else {\r
+ executeCommand = String.format("%s %s", jarCommand, getCommand());\r
+ }\r
+ } else {\r
+ executeCommand = String.format("%s %s", jarCommand, getCommand());\r
+ }\r
+ String returnExecute = HostUtil.returnExecute(executeCommand, null, true);\r
out.println(returnExecute);\r
} finally {\r
setDirectory(origDirectory);\r
public void setCommand(String command) {\r
this.command = command;\r
}\r
+\r
+ enum GitCommandType {\r
+ add(true, true, true),\r
+ branch(true, true, true),\r
+ checkout(true, true, true),\r
+ clone(false, false, false),\r
+ commit(true, true, true),\r
+ diff(true, true, true),\r
+ fetch(true, true, true),\r
+ init(false, true, false),\r
+ log(true, true, true),\r
+ merge(true, true, true),\r
+ push(true, true, true),\r
+ reset(true, true, true),\r
+ rm(true, true, true),\r
+ show(true, true, true),\r
+ status(true, true, true),\r
+ tag(true, true, true);\r
+\r
+ private boolean needsDotGit;\r
+ private boolean needsGitDir;\r
+ private boolean findsGitDir;\r
+\r
+ private GitCommandType(boolean needsDotGit, boolean needsGitDir, boolean findsGitDir) {\r
+ this.needsDotGit = needsDotGit;\r
+ this.needsGitDir = needsGitDir;\r
+ this.findsGitDir = findsGitDir;\r
+ }\r
+ }\r
}\r