Example #1
0
File: vcs.go Project: rasky/godep
// VCSForImportPath returns a VCS value for an import path.
func VCSForImportPath(importPath string) (*VCS, error) {
	rr, err := vcs.RepoRootForImportPath(importPath, verbose)
	if err != nil {
		return nil, err
	}
	vcs := cmd[rr.VCS]
	if vcs == nil {
		return nil, fmt.Errorf("%s is unsupported: %s", rr.VCS.Name, importPath)
	}
	return vcs, nil
}
Example #2
0
// download downloads the given dependency.
// 2 Passes: 1) go get -d <pkg>, 2) git pull (if necessary)
func download(dep *Dependency) error {

	rr, err := vcs.RepoRootForImportPath(dep.ImportPath, debug)
	if err != nil {
		debugln("Error determining repo root for", dep.ImportPath)
		return err
	}
	ppln("rr", rr)

	dep.vcs = cmd[rr.VCS]

	// try to find an existing directory in the GOPATHs
	for _, gp := range filepath.SplitList(build.Default.GOPATH) {
		t := filepath.Join(gp, "src", rr.Root)
		fi, err := os.Stat(t)
		if err != nil {
			continue
		}
		if fi.IsDir() {
			dep.root = t
			break
		}
	}

	// If none found, just pick the first GOPATH entry (AFAICT that's what go get does)
	if dep.root == "" {
		dep.root = filepath.Join(filepath.SplitList(build.Default.GOPATH)[0], "src", rr.Root)
	}
	ppln("dep", dep)

	if downloaded[rr.Repo] {
		verboseln("Skipping already downloaded repo", rr.Repo)
		return nil
	}

	fi, err := os.Stat(dep.root)
	if err != nil {
		if os.IsNotExist(err) {
			if err := os.MkdirAll(filepath.Dir(dep.root), os.ModePerm); err != nil {
				debugln("Error creating base dir of", dep.root)
				return err
			}
			err := rr.VCS.CreateAtRev(dep.root, rr.Repo, dep.Rev)
			debugln("CreatedAtRev", dep.root, rr.Repo, dep.Rev)
			if err != nil {
				debugln("CreateAtRev error", err)
				return err
			}
			downloaded[rr.Repo] = true
			return nil
		}
		debugln("Error checking repo root for", dep.ImportPath, "at", dep.root, ":", err)
		return err
	}

	if !fi.IsDir() {
		return errors.New("repo root src dir exists, but isn't a directory for " + dep.ImportPath + " at " + dep.root)
	}

	if !dep.vcs.exists(dep.root, dep.Rev) {
		debugln("Updating existing", dep.root)
		dep.vcs.vcs.Download(dep.root)
		downloaded[rr.Repo] = true
	}

	debugln("Nothing to download")
	return nil
}