예제 #1
0
파일: check.go 프로젝트: vito/gocart
func checkForDirtyState(dep dependency.Dependency) error {
	repoPath := dep.FullPath(GOPATH)

	if _, err := os.Stat(repoPath); os.IsNotExist(err) {
		return nil
	}

	repo, err := repository.New(repoPath, command_runner.New(false))
	if err != nil {
		fatal(err)
	}

	statusOut, err := repo.Status()
	if err != nil {
		fatal(err)
	}

	if len(statusOut) != 0 {
		return DirtyState{
			Output: statusOut,
		}
	}

	currentStatus := getDependencyStatus(dep)
	if currentStatus != nil {
		if !currentStatus.VersionMatches {
			return VersionMismatch{
				Expected: dep.Version,
				Status:   *currentStatus,
			}
		}
	}

	return nil
}
예제 #2
0
파일: set.go 프로젝트: vito/gocart
func (s *Set) UnmarshalText(text []byte) error {
	lines := bufio.NewScanner(bytes.NewReader(text))

	for lines.Scan() {
		words := bufio.NewScanner(bytes.NewReader(lines.Bytes()))
		words.Split(bufio.ScanWords)

		count := 0
		dep := dependency.Dependency{}

		for words.Scan() {
			if strings.HasPrefix(words.Text(), "#") {
				break
			}

			if count == 0 {
				dep.Path = words.Text()
			} else if count == 1 {
				if words.Text() == "*" {
					dep.BleedingEdge = true
				} else {
					dep.Version = words.Text()
				}
			} else if count == 2 {
				dep.Tags = strings.Split(words.Text(), ",")
			}

			count++
		}

		if count == 0 {
			// blank line
			continue
		}

		if count == 1 {
			return MissingVersionError{dep.Path}
		}

		// check for dupes
		for _, existing := range s.Dependencies {
			if strings.HasPrefix(dep.Path+"/", existing.Path+"/") {
				return DuplicateDependencyError{existing, dep}
			}

			if strings.HasPrefix(existing.Path+"/", dep.Path+"/") {
				return DuplicateDependencyError{existing, dep}
			}
		}

		s.Dependencies = append(s.Dependencies, dep)
	}

	return nil
}
예제 #3
0
func findCurrentVersion(dep dependency.Dependency) string {
	repoPath := dep.FullPath(GOPATH)

	repo, err := repository.New(repoPath, command_runner.New(false))
	if err != nil {
		return ""
	}

	currentVersion, err := repo.CurrentVersion()
	if err != nil {
		return ""
	}

	return currentVersion
}
예제 #4
0
func getDependencyStatus(dep dependency.Dependency) *DependencyStatus {
	repoPath := dep.FullPath(GOPATH)

	repo, err := repository.New(repoPath, command_runner.New(false))
	if err != nil {
		return nil
	}

	status := &DependencyStatus{}

	status.CurrentVersion = findCurrentVersion(dep)
	status.VersionMatches = status.CurrentVersion == dep.Version

	if status.VersionMatches {
		return status
	}

	newer := true

	logOutput, err := repo.Log(dep.Version, status.CurrentVersion)

	// git or hg with both refs will show empty if newer..older
	if len(logOutput) == 0 {
		newer = false
	}

	// either bazaar, or dep.Version is not fetched
	if err != nil {
		newer = false
	}

	if newer {
		status.DeltaLog = logOutput
		status.Delta = len(strings.Split(status.DeltaLog, "\n")) - 1
	} else {
		logOutput, _ := repo.Log(status.CurrentVersion, dep.Version)

		status.DeltaLog = logOutput
		status.Delta = -(len(strings.Split(status.DeltaLog, "\n")) - 1)
	}

	return status
}
예제 #5
0
package dependency_test

import (
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	dependency_package "github.com/vito/gocart/dependency"
)

var _ = Describe("Dependency", func() {
	var dependency dependency_package.Dependency

	BeforeEach(func() {
		dependency = dependency_package.Dependency{
			Path:    "github.com/xoebus/kingpin",
			Version: "master",
		}
	})

	Describe("Stringer interface", func() {
		It("returns the string as it would appear in a Cartridge", func() {
			Expect(dependency.String()).To(Equal("github.com/xoebus/kingpin\tmaster"))
		})
	})

	Describe("the full path of the dependency", func() {
		It("prepends the passed in root path", func() {
			Expect(dependency.FullPath("/tmp")).To(Equal("/tmp/src/github.com/xoebus/kingpin"))
		})
	})
})
예제 #6
0
파일: fetcher.go 프로젝트: vito/gocart
func (f *Fetcher) Fetch(dep dependency.Dependency) (dependency.Dependency, error) {
	var goGet *exec.Cmd

	repoPath := dep.FullPath(f.gopath)

	lockDown := true
	updateRepo := false

	if dep.BleedingEdge {
		// update the repo only if bleeding-edge and repo is clean
		if _, err := os.Stat(repoPath); err == nil {
			lockDown = false

			repo, err := repository.New(repoPath, f.runner)
			if err != nil {
				return dependency.Dependency{}, err
			}

			statusOut, err := repo.Status()
			if err != nil {
				return dependency.Dependency{}, err
			}

			if len(statusOut) == 0 {
				updateRepo = true
			}
		}
	}

	if updateRepo {
		goGet = exec.Command("go", "get", "-u", "-d", "-v", dep.Path)
	} else {
		goGet = exec.Command("go", "get", "-d", "-v", dep.Path)
	}

	err := f.runner.Run(goGet)
	if err != nil {
		return dependency.Dependency{}, err
	}

	repo, err := repository.New(repoPath, f.runner)
	if err != nil {
		return dependency.Dependency{}, err
	}

	if lockDown {
		err := f.syncRepo(repo, dep.Version)
		if err != nil {
			return dependency.Dependency{}, err
		}
	}

	currentVersion, err := repo.CurrentVersion()
	if err != nil {
		return dependency.Dependency{}, err
	}

	dep.Version = currentVersion

	fetched, found := f.fetchedDependencies[dep.Path]
	if found {
		if fetched.Version != dep.Version {
			return dependency.Dependency{}, VersionConflictError{
				Path:     dep.Path,
				VersionA: fetched.Version,
				VersionB: dep.Version,
			}
		}
	} else {
		f.fetchedDependencies[dep.Path] = dep
	}

	return dep, nil
}
예제 #7
0
파일: fetcher_test.go 프로젝트: vito/gocart
import (
	"os"
	"os/exec"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/vito/gocart/command_runner/fake_command_runner"
	. "github.com/vito/gocart/command_runner/fake_command_runner/matchers"
	dependency_package "github.com/vito/gocart/dependency"
	. "github.com/vito/gocart/fetcher"
	"github.com/vito/gocart/gopath"
)

var _ = Describe("Fetcher", func() {
	var dependency dependency_package.Dependency
	var fetcher *Fetcher
	var runner *fake_command_runner.FakeCommandRunner

	BeforeEach(func() {
		var err error

		dependency = dependency_package.Dependency{
			Path:    "github.com/vito/gocart",
			Version: "v1.2",
		}

		runner = fake_command_runner.New()

		fetcher, err = New(runner)
		Expect(err).ToNot(HaveOccurred())