COMMON: COMMAND BAR: Supports for git clone and init 32/15732/1
authorkh5325.kim <kh5325.kim@samsung.com>
Mon, 27 Jan 2014 15:52:46 +0000 (00:52 +0900)
committerkh5325.kim <kh5325.kim@samsung.com>
Mon, 27 Jan 2014 15:52:46 +0000 (00:52 +0900)
Supports for git clone and init.

Change-Id: Iee73da24c8f0a2eda672576636b51bce0bffc06f
Signed-off-by: kh5325.kim <kh5325.kim@samsung.com>
org.tizen.common.ui/src/org/tizen/common/ui/commandbar/command/git/JGitCLI.java

index dfa0749..cba9018 100644 (file)
@@ -31,12 +31,15 @@ package org.tizen.common.ui.commandbar.command.git;
 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
@@ -49,27 +52,22 @@ public class JGitCLI extends Main {
     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
@@ -82,8 +80,24 @@ public class JGitCLI extends Main {
                 // /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
@@ -120,4 +134,33 @@ public class JGitCLI extends Main {
     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