diff --git a/README.mkd b/README.mkd index 2995903..0166e75 100644 --- a/README.mkd +++ b/README.mkd @@ -89,7 +89,7 @@ If you want to bundle specified tag, branch or commit If you want to bundle a repository that `go get` can't access - gom 'github.com/username/repository', :command => 'git clone http://example.com/repository.git' + gom 'github.com/username/repository', :command => 'git clone http://example.com/repository.git', :update => 'git fetch' Todo ---- diff --git a/install.go b/install.go index f01a795..08502b8 100644 --- a/install.go +++ b/install.go @@ -109,15 +109,25 @@ func (gom *Gom) Clone(args []string) error { target = gom.name } + var customCmd []string srcdir := filepath.Join(vendor, "src", target) - customCmd := strings.Split(command, " ") - customCmd = append(customCmd, srcdir) - - fmt.Printf("fetching %s (%v)\n", gom.name, customCmd) - err = run(customCmd, Blue) - if err != nil { - return err + if _, err := os.Stat(srcdir); err == nil || os.IsExist(err) { + if update, ok := gom.options["update"].(string); ok { + customCmd = strings.Split(update, " ") + customCmd = append(customCmd) + fmt.Printf("updating %s (%v)\n", gom.name, customCmd) + vcsExec(srcdir, customCmd...) + } + } else { + customCmd := strings.Split(command, " ") + customCmd = append(customCmd, srcdir) + fmt.Printf("fetching %s (%v)\n", gom.name, customCmd) + err = run(customCmd, Blue) + if err != nil { + return err + } } + } else if private, ok := gom.options["private"].(string); ok { if private == "true" { target, ok := gom.options["target"].(string)