Exemple #1
0
// Create creates a new copy of repo in dir.
// The parent of dir must exist; dir must not.
func (c *Cmd) Create(dir, repo string) error {
	for _, cmd := range c.CreateCmd {
		if !go15vendorexperiment.On() && strings.Contains(cmd, "submodule") {
			continue
		}
		if err := c.run(".", cmd, "dir", dir, "repo", repo); err != nil {
			return err
		}
	}
	return nil
}
Exemple #2
0
// TagSync syncs the repo in dir to the named tag,
// which either is a tag returned by tags or is v.tagDefault.
func (c *Cmd) TagSync(dir, tag string) error {
	if c.TagSyncCmd == nil {
		return nil
	}
	if tag != "" {
		for _, tc := range c.TagLookupCmd {
			out, err := c.runOutput(dir, tc.Cmd, "tag", tag)
			if err != nil {
				return err
			}
			re := regexp.MustCompile(`(?m-s)` + tc.Pattern)
			m := re.FindStringSubmatch(string(out))
			if len(m) > 1 {
				tag = m[1]
				break
			}
		}
	}

	if tag == "" && c.TagSyncDefault != nil {
		for _, cmd := range c.TagSyncDefault {
			if !go15vendorexperiment.On() && strings.Contains(cmd, "submodule") {
				continue
			}
			if err := c.run(dir, cmd); err != nil {
				return err
			}
		}
		return nil
	}

	for _, cmd := range c.TagSyncCmd {
		if !go15vendorexperiment.On() && strings.Contains(cmd, "submodule") {
			continue
		}
		if err := c.run(dir, cmd, "tag", tag); err != nil {
			return err
		}
	}
	return nil
}
Exemple #3
0
// Download downloads any new changes for the repo in dir.
func (c *Cmd) Download(dir string, verbose bool) error {
	if err := c.fixDetachedHead(dir, verbose); err != nil {
		return err
	}
	for _, cmd := range c.DownloadCmd {
		if !go15vendorexperiment.On() && strings.Contains(cmd, "submodule") {
			continue
		}
		if err := c.run(dir, cmd); err != nil {
			return err
		}
	}
	return nil
}
Exemple #4
0
// Vendor
func Vendor(pkgs []string, update, verbose, tree, results, commands, lock bool, format string) error {

	// ensure that the locally installed version of go supports vendoring
	if !go15vendorexperiment.Version() {
		return errors.New("govend requires go versions 1.5+")
	}

	// ensure that the GO15VENDOREXPERIMENT env var is set to '1'
	if !go15vendorexperiment.On() {
		return errors.New("govend requires 'GO15VENDOREXPERIMENT=1'")
	}

	// attempt to load the manifest file
	m, err := manifest.Load(format)
	if err != nil {
		return err
	}

	// it is important to save the manifest length before syncing, so that
	// if a manifest file existed previously it continues to update even if
	// no current vendors are valid.
	initManifestLen := m.Len()

	// sync ensures that if a vendor is specified in the manifest, that
	// repository root is also currently present in the vendor directory, this
	// allows us to trust the manifest file
	m.Sync()

	// if no packages were provided as arguments, assume the current directory is
	// a go project and scan it for external pacakges.
	if len(pkgs) == 0 {
		pkgs, err = packages.ScanProject(".")
		if err != nil {
			return err
		}
	}

	// download that dependency and any external deps it has
	bpkgs := &badpkgs{}
	numOfpkgs := 0
	for _, pkg := range pkgs {
		lastimport = pkg
		n, err := deptree(pkg, m, bpkgs, 0, verbose, tree)
		if err != nil {
			return err
		}
		numOfpkgs += n
	}

	if verbose && results {
		fmt.Printf("\npackages scanned: %d\n", numOfpkgs)
		fmt.Printf("packages skipped: %d\n", bpkgs.len())
		fmt.Printf("repos downloaded: %d\n", m.Len())
	}

	if lock || initManifestLen > 0 {
		if err := m.Write(); err != nil {
			return err
		}
	}

	return nil
}