Skip to content

Commit

Permalink
[app][git] Finish the clone part
Browse files Browse the repository at this point in the history
TODO:
- http clone (currently we are forcing ssh clone)
- unify naming in `config.go` and `remote.go`

issues #13
  • Loading branch information
at15 committed Aug 10, 2016
1 parent 0483809 commit 1fc25b1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
16 changes: 11 additions & 5 deletions app/git/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
7 changes: 7 additions & 0 deletions app/git/repo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package git

// Repo is a repository with local path and remote
type Repo struct {
Remote Remote
LocalPath string
}
5 changes: 2 additions & 3 deletions cmd/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}

Expand Down

0 comments on commit 1fc25b1

Please sign in to comment.