Beispiel #1
0
Datei: repo.go Projekt: arya/gvt
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
}
Beispiel #2
0
Datei: repo.go Projekt: arya/gvt
func (w workingcopy) Destroy() error {
	if err := fileutils.RemoveAll(w.path); err != nil {
		return err
	}
	parent := filepath.Dir(w.path)
	return cleanPath(parent)
}
Beispiel #3
0
func downloadDependency(dep vendor.Dependency) error {
	log.Printf("fetching %s", dep.Importpath)
	repo, _, err := vendor.DeduceRemoteRepo(dep.Importpath, rbInsecure)
	if err != nil {
		return fmt.Errorf("dependency could not be processed: %s", err)
	}
	wc, err := repo.Checkout("", "", dep.Revision)
	if err != nil {
		return fmt.Errorf("dependency could not be fetched: %s", err)
	}
	dst := filepath.Join(vendorDir(), dep.Importpath)
	src := filepath.Join(wc.Dir(), dep.Path)

	if _, err := os.Stat(dst); err == nil {
		if err := fileutils.RemoveAll(dst); err != nil {
			return fmt.Errorf("dependency could not be deleted: %v", err)
		}
	}

	if err := fileutils.Copypath(dst, src); err != nil {
		return err
	}

	if err := wc.Destroy(); err != nil {
		return err
	}

	return nil
}
Beispiel #4
0
func downloadDependency(dep vendor.Dependency) error {
	log.Printf("fetching %s", dep.Importpath)
	repo, _, err := vendor.DeduceRemoteRepo(dep.Importpath, rbInsecure)
	if err != nil {
		return fmt.Errorf("dependency could not be processed: %s", err)
	}
	// We can't pass the branch here, and benefit from narrow clones, as the
	// revision might not be in the branch tree anymore. Thanks rebase.
	wc, err := repo.Checkout("", "", dep.Revision)
	if err != nil {
		return fmt.Errorf("dependency could not be fetched: %s", err)
	}
	dst := filepath.Join(vendorDir(), dep.Importpath)
	src := filepath.Join(wc.Dir(), dep.Path)

	if _, err := os.Stat(dst); err == nil {
		if err := fileutils.RemoveAll(dst); err != nil {
			return fmt.Errorf("dependency could not be deleted: %v", err)
		}
	}

	if err := fileutils.Copypath(dst, src); err != nil {
		return err
	}

	if err := wc.Destroy(); err != nil {
		return err
	}

	return nil
}
Beispiel #5
0
Datei: repo.go Projekt: arya/gvt
func cleanPath(path string) error {
	if files, _ := ioutil.ReadDir(path); len(files) > 0 || filepath.Base(path) == "vendor" {
		return nil
	}
	parent := filepath.Dir(path)
	if err := fileutils.RemoveAll(path); err != nil {
		return err
	}
	return cleanPath(parent)
}
Beispiel #6
0
func downloadDependency(dep vendor.Dependency, vendorDir string, recursive bool) error {
	if recursive {
		log.Printf("fetching recursive %s", dep.Importpath)
	} else {
		log.Printf("fetching %s", dep.Importpath)
	}

	repo, _, err := vendor.DeduceRemoteRepo(dep.Importpath, rbInsecure)
	if err != nil {
		return fmt.Errorf("dependency could not be processed: %s", err)
	}
	// We can't pass the branch here, and benefit from narrow clones, as the
	// revision might not be in the branch tree anymore. Thanks rebase.
	wc, err := repo.Checkout("", "", dep.Revision)
	if err != nil {
		return fmt.Errorf("dependency could not be fetched: %s", err)
	}
	dst := filepath.Join(vendorDir, dep.Importpath)
	src := filepath.Join(wc.Dir(), dep.Path)

	if _, err := os.Stat(dst); err == nil {
		if err := fileutils.RemoveAll(dst); err != nil {
			return fmt.Errorf("dependency could not be deleted: %v", err)
		}
	}

	if err := fileutils.Copypath(dst, src); err != nil {
		return err
	}

	if err := wc.Destroy(); err != nil {
		return err
	}

	// Check for for manifests in dependencies
	man := filepath.Join(dst, "vendor", "manifest")
	venDir := filepath.Join(dst, "vendor")
	if _, err := os.Stat(man); err == nil {
		m, err := vendor.ReadManifest(man)
		if err != nil {
			return fmt.Errorf("could not load manifest: %v", err)
		}
		var errors uint32
		for _, d := range m.Dependencies {
			if err := downloadDependency(d, venDir, true); err != nil {
				log.Printf("%s: %v", d.Importpath, err)
				atomic.AddUint32(&errors, 1)
			}
		}
	}

	return nil
}
Beispiel #7
0
func TestManifest(t *testing.T) {
	root := mktemp(t)
	defer fileutils.RemoveAll(root)

	mf := filepath.Join(root, "vendor")

	// check that reading an non existant manifest
	// does not return an error
	m, err := ReadManifest(mf)
	if err != nil {
		t.Fatalf("reading a non existant manifest should not fail: %v", err)
	}

	// check that no manifest file was created
	assertNotExists(t, mf)

	// add a dep
	m.Dependencies = append(m.Dependencies, Dependency{
		Importpath: "github.com/foo/bar/baz",
		Repository: "https://github.com/foo/bar",
		Revision:   "cafebad",
		Branch:     "master",
		Path:       "/baz",
	})

	// write it back
	if err := WriteManifest(mf, m); err != nil {
		t.Fatalf("WriteManifest failed: %v", err)
	}

	// check the manifest was written
	assertExists(t, mf)

	// remove it
	m.Dependencies = nil
	if err := WriteManifest(mf, m); err != nil {
		t.Fatalf("WriteManifest failed: %v", err)
	}

	// check that no manifest file was removed
	assertNotExists(t, mf)
}
Beispiel #8
0
Datei: repo.go Projekt: arya/gvt
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
}
Beispiel #9
0
				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 fmt.Errorf("could not get get dependency: %v", err)
				}

				if err := m.RemoveDependency(dep); err != nil {
					return fmt.Errorf("dependency could not be removed: %v", err)
				}
				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 fmt.Errorf("dependency could not be deleted: %v", err)
				}
			}
		}

		return vendor.WriteManifest(manifestFile(ctx), m)
	},
}
Beispiel #10
0
			}

			branch, err := wc.Branch()
			if err != nil {
				return err
			}

			dep := vendor.Dependency{
				Importpath: d.Importpath,
				Repository: repo.URL(),
				Revision:   rev,
				Branch:     branch,
				Path:       extra,
			}

			if err := fileutils.RemoveAll(filepath.Join(vendorDir(), filepath.FromSlash(d.Importpath))); err != nil {
				// TODO(dfc) need to apply vendor.cleanpath here to remove intermediate directories.
				return fmt.Errorf("dependency could not be deleted: %v", err)
			}

			dst := filepath.Join(vendorDir(), filepath.FromSlash(dep.Importpath))
			src := filepath.Join(wc.Dir(), dep.Path)

			if err := fileutils.Copypath(dst, src); err != nil {
				return err
			}

			if err := m.AddDependency(dep); err != nil {
				return err
			}
Beispiel #11
0
func (w workingcopy) Destroy() error {
	return fileutils.RemoveAll(w.path)
}