Ejemplo n.º 1
0
func get(imp Import, done chan struct{}) {
	defer func() {
		done <- struct{}{}
	}()
	vcspath := filepath.Join(goPathSrc,
		strings.TrimRight(imp.Package, "/..."))
	if !exists(vcspath) {
		cmd := exec.Command("go", "get", "-d", imp.Package)
		cmd.Stderr = os.Stderr
		cmd.Stdout = os.Stdout
		cmd.Stdin = os.Stdin
		err := cmd.Run()
		if err != nil {
			elog.Print(err)
			return
		}
	}
	v, err := vcs.New(vcspath, goPathSrc)
	if err != nil {
		elog.Print(err)
		return
	}
	if imp.Hash != "" {
		err = v.Checkout(imp.Hash)
		if err != nil {
			// try fetching for the latest commit
			err = v.Fetch()
			if err != nil {
				elog.Print(err)
				return
			}
			err = v.Checkout(imp.Hash)
			if err != nil {
				elog.Printf("error checkout out %s: %s", imp.Package, err)
				return
			}
		}
		return
	}
	if err := v.Latest(); err != nil {
		elog.Printf("error trying to set %s to latest: %s", imp.Package, err)
	}
}
Ejemplo n.º 2
0
func list(dir string, recursive, hash bool) []Import {
	imports, err := getPackageImports(*listDir, *listRecursive, nil)
	if err != nil {
		elog.Fatal(err)
	}
	imports = purgeSubPackages(*listDir, imports)
	var ret []Import
	roots := make(map[string][]Import)
	for _, pkg := range imports {
		imp := Import{Package: pkg}
		if !*listHash {
			ret = append(ret, imp)
			continue
		}
		path := filepath.Join(goPathSrc, pkg)
		v, err := vcs.New(path, goPathSrc)
		if err != nil {
			continue
		}
		hash, err := v.CommitHash()
		if err != nil {
			elog.Println(err)
			continue
		}
		imp.Hash = hash
		roots[v.Root] = append(roots[v.Root], imp)
	}
	for root, imps := range roots {
		if len(imps) <= 1 {
			ret = append(ret, imps...)
			continue
		}
		root = pkgPath(root) + "/..."
		ret = append(ret, Import{Package: root, Hash: imps[0].Hash})
	}
	sort.Sort(Imports(ret))
	return ret
}