Ejemplo n.º 1
0
// RemoveRepo removes go-gettable repo with no local changes (by moving it into trash).
// importPathPattern must match exactly with the repo root.
// For example, "github.com/user/repo/...".
func RemoveRepo(importPathPattern string) error {
	// TODO: Use an official Go package for `go list` functionality whenever possible.
	importPaths := gotool.ImportPaths([]string{importPathPattern})
	if len(importPaths) == 0 {
		return errors.New("no packages to remove")
	}

	var firstGoPackage *gist7480523.GoPackage
	for i, importPath := range importPaths {
		goPackage := gist7480523.GoPackageFromImportPath(importPath)
		if goPackage == nil {
			return errors.New("Import Path not found: " + importPath)
		}

		if goPackage.Bpkg.Goroot {
			return errors.New("can't remove packages from GOROOT")
		}

		goPackage.UpdateVcs()

		if goPackage.Dir.Repo == nil {
			return errors.New("can't get repo status")
		}

		if i == 0 {
			firstGoPackage = goPackage
		} else if firstGoPackage.Dir.Repo != goPackage.Dir.Repo {
			return errors.New("matched Go Packages span more than 1 repo: " + firstGoPackage.Dir.Repo.Vcs.RootPath() + " != " + goPackage.Dir.Repo.Vcs.RootPath())
		} else if !strings.HasPrefix(goPackage.Bpkg.Dir, firstGoPackage.Dir.Repo.Vcs.RootPath()) { // TODO: This is probably not neccessary...
			return errors.New("Go Package not inside repo: " + goPackage.Bpkg.Dir + " doesn't have prefix " + firstGoPackage.Dir.Repo.Vcs.RootPath())
		}
	}

	if repoImportPathPattern := gist7480523.GetRepoImportPathPattern(firstGoPackage.Dir.Repo.Vcs.RootPath(), firstGoPackage.Bpkg.SrcRoot); repoImportPathPattern != importPathPattern {
		return errors.New("importPathPattern not exact repo root match: " + importPathPattern + " != " + repoImportPathPattern)
	}

	firstGoPackage.UpdateVcsFields()

	cleanStatus := func(goPackage *gist7480523.GoPackage) bool {
		packageStatus := status.PlumbingPresenterV2(goPackage)[:4]
		return packageStatus == "    " || packageStatus == "  + " // Updates are okay to ignore.
	}

	if !cleanStatus(firstGoPackage) {
		return errors.New("non-clean status: " + status.PorcelainPresenter(firstGoPackage))
	}

	err := trash.MoveTo(firstGoPackage.Dir.Repo.Vcs.RootPath())
	return err

	// TODO: Clean up /pkg folder contents, if any, etc.
}
Ejemplo n.º 2
0
// shouldPresentUpdate determines if the given goPackage should be presented as an available update.
// It checks that the Go package is on default branch, does not have a dirty working tree, and does not have the remote revision.
func shouldPresentUpdate(goPackage *gist7480523.GoPackage) bool {
	return status.PlumbingPresenterV2(goPackage)[:3] == "  +" // Ignore stash.
}