From 04838092eee20b3c55d82d442450a97405c79542 Mon Sep 17 00:00:00 2001 From: at15 Date: Wed, 10 Aug 2016 10:37:48 +0800 Subject: [PATCH] [app][git] run real command for clone --- app/git/clone.go | 11 ++++++++--- app/git/workspace.go | 11 +++++++++++ cmd/git.go | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/git/clone.go b/app/git/clone.go index 9b7305b..3413229 100644 --- a/app/git/clone.go +++ b/app/git/clone.go @@ -1,5 +1,9 @@ package git +import ( + "github.com/dyweb/Ayi/util" +) + // CloneFromURL will clone a repository based on short url or normal git clone url func CloneFromURL(repoURL string) error { // get the remote from url @@ -14,7 +18,8 @@ func CloneFromURL(repoURL string) error { // Clone clones a remote git repo func Clone(r Remote) error { - log.Info(r.GetSSH()) - log.Info("git clone " + r.GetSSH() + " " + GetRepoBasePath() + "/" + r.Repo) - return nil + // log.Info("git clone " + r.GetSSH() + " " + GetCloneDirectory(r)) + cmdStr := "git clone " + r.GetSSH() + " " + GetCloneDirectory(r) + log.Info(cmdStr) + return util.RunCommand(cmdStr) } diff --git a/app/git/workspace.go b/app/git/workspace.go index 1ec1f8a..6b75450 100644 --- a/app/git/workspace.go +++ b/app/git/workspace.go @@ -3,6 +3,7 @@ package git import ( "os" "path/filepath" + "strings" "github.com/spf13/viper" ) @@ -21,3 +22,13 @@ func GetRepoBasePath() string { } return "" } + +// GetCloneDirectory return path for clone destination +func GetCloneDirectory(r Remote) string { + base := GetRepoBasePath() + if base == "" { + return "" + } + // git clone does not accept windows format path, so all / + return strings.Replace(base+"/"+r.Host+"/"+r.Owner+"/"+r.Repo, "\\", "/", -1) +} diff --git a/cmd/git.go b/cmd/git.go index 1a1fd85..3f0cf0c 100644 --- a/cmd/git.go +++ b/cmd/git.go @@ -34,7 +34,7 @@ var gitCloneCmd = &cobra.Command{ repoURL := args[0] err := git.CloneFromURL(repoURL) if err != nil { - log.Warn(err.Error()) + log.Error(err.Error()) return } // TODO: clone may need to return more information