func (h *hgrepo) Checkout(branch, tag, revision string) (WorkingCopy, error) { if !atMostOne(tag, revision) { return nil, fmt.Errorf("only one of tag or revision may be supplied") } dir, err := mktmp() if err != nil { return nil, err } args := []string{ "clone", h.url, dir, "--noninteractive", } if branch != "" { args = append(args, "--branch", branch) } if err := runOut(os.Stderr, "hg", args...); err != nil { fileutils.RemoveAll(dir) return nil, err } if revision != "" { if err := runOut(os.Stderr, "hg", "--cwd", dir, "update", "-r", revision); err != nil { fileutils.RemoveAll(dir) return nil, err } } return &HgClone{ workingcopy{ path: dir, }, }, nil }
func (w workingcopy) Destroy() error { if err := fileutils.RemoveAll(w.path); err != nil { return err } parent := filepath.Dir(w.path) return cleanPath(parent) }
func cleanPath(path string) error { if files, _ := ioutil.ReadDir(path); len(files) > 0 || filepath.Base(path) == "src" { return nil } parent := filepath.Dir(path) if err := fileutils.RemoveAll(path); err != nil { return err } return cleanPath(parent) }
func (b *bzrrepo) Checkout(branch, tag, revision string) (WorkingCopy, error) { if !atMostOne(tag, revision) { return nil, fmt.Errorf("only one of tag or revision may be supplied") } dir, err := mktmp() if err != nil { return nil, err } wc := filepath.Join(dir, "wc") if err := runOut(os.Stderr, "bzr", "branch", b.url, wc); err != nil { fileutils.RemoveAll(dir) return nil, err } return &BzrClone{ workingcopy{ path: wc, }, }, nil }
if strings.HasPrefix(i, d) { return true } } return false } dependencies := make([]vendor.Dependency, len(m.Dependencies)) copy(dependencies, m.Dependencies) for _, d := range dependencies { if !hasImportWithPrefix(d.Importpath) { dep, err := m.GetDependencyForImportpath(d.Importpath) if err != nil { return errors.Wrap(err, "could not get get dependency") } if err := m.RemoveDependency(dep); err != nil { return errors.Wrap(err, "dependency could not be removed") } if err := fileutils.RemoveAll(filepath.Join(ctx.Projectdir(), "vendor", "src", filepath.FromSlash(d.Importpath))); err != nil { // TODO(dfc) need to apply vendor.cleanpath here to remove indermediate directories. return errors.Wrap(err, "dependency could not be deleted") } } } return vendor.WriteManifest(manifestFile(ctx), m) }, }