// ensureRepo ensures that the repo exists and is checked out. // DEPRECATED: You should use the functions in package `repo` instead. func ensureRepo(repo, home string) *vcs.GitRepo { if err := os.Chdir(home); err != nil { log.Die("Could not change to directory %q: %s", home, err) } git, err := vcs.NewGitRepo(repo, home) if err != nil { log.Die("Could not get repository %q: %s", repo, err) } git.Logger = log.New() if !git.CheckLocal() { log.Debug("Cloning repo into %q. Please wait.", home) if err := git.Get(); err != nil { log.Die("Could not create repository in %q: %s", home, err) } } return git }
func ensureRepo(repo, dir string) (*vcs.GitRepo, error) { if fi, err := os.Stat(dir); err != nil { if err := os.MkdirAll(dir, 0755); err != nil { return nil, err } } else if !fi.IsDir() { return nil, fmt.Errorf("File %s exists, but is not a directory.", dir) } git, err := vcs.NewGitRepo(repo, dir) if err != nil { return nil, err } git.Logger = log.New() if !git.CheckLocal() { if err := git.Get(); err != nil { return git, err } } return git, nil }