diff --git a/app/git/clone.go b/app/git/clone.go index 3413229..d4c0e1d 100644 --- a/app/git/clone.go +++ b/app/git/clone.go @@ -5,21 +5,27 @@ import ( ) // CloneFromURL will clone a repository based on short url or normal git clone url -func CloneFromURL(repoURL string) error { +func CloneFromURL(repoURL string) (Repo, error) { // get the remote from url r, err := NewFromURL(repoURL) log.Debug(r) // TODO: may wrap the error to have stack included if err != nil { - return err + return Repo{}, err } return Clone(r) } // Clone clones a remote git repo -func Clone(r Remote) error { +func Clone(r Remote) (Repo, error) { // log.Info("git clone " + r.GetSSH() + " " + GetCloneDirectory(r)) - cmdStr := "git clone " + r.GetSSH() + " " + GetCloneDirectory(r) + repo := Repo{Remote: r, LocalPath: GetCloneDirectory(r)} + cmdStr := "git clone " + r.GetSSH() + " " + repo.LocalPath log.Info(cmdStr) - return util.RunCommand(cmdStr) + err := util.RunCommand(cmdStr) + if err != nil { + // TODO: may wrap the error + return repo, err + } + return repo, nil } diff --git a/app/git/repo.go b/app/git/repo.go new file mode 100644 index 0000000..c5d2e76 --- /dev/null +++ b/app/git/repo.go @@ -0,0 +1,7 @@ +package git + +// Repo is a repository with local path and remote +type Repo struct { + Remote Remote + LocalPath string +} diff --git a/cmd/git.go b/cmd/git.go index 3f0cf0c..ce305c1 100644 --- a/cmd/git.go +++ b/cmd/git.go @@ -32,13 +32,12 @@ var gitCloneCmd = &cobra.Command{ return } repoURL := args[0] - err := git.CloneFromURL(repoURL) + repo, err := git.CloneFromURL(repoURL) if err != nil { log.Error(err.Error()) return } - // TODO: clone may need to return more information - log.Info("Sucessfully cloned ... repo to ...") + log.Infof("Sucessfully cloned to: %s", repo.LocalPath) }, }