Beispiel #1
0
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
}
Beispiel #2
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
}
Beispiel #3
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
}
Beispiel #4
0
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"))
		})
	})
})
Beispiel #5
0
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
}
Beispiel #6
0
			})

			dep, err := fetcher.Fetch(dependency)
			Expect(err).ToNot(HaveOccurred())

			gopath, _ := gopath.InstallationDirectory(os.Getenv("GOPATH"))

			Ω(runner).Should(HaveExecutedSerially(
				fake_command_runner.CommandSpec{
					Path: exec.Command("go").Path,
					Args: []string{"get", "-d", "-v", dependency.Path},
				},
				fake_command_runner.CommandSpec{
					Path: exec.Command("git").Path,
					Args: []string{"fetch"},
					Dir:  dependency.FullPath(gopath),
				},
				fake_command_runner.CommandSpec{
					Path: exec.Command("git").Path,
					Args: []string{"checkout", "v1.2"},
					Dir:  dependency.FullPath(gopath),
				},
			))

			Ω(dep.Version).Should(Equal("some-sha"))
		})

		Context("when the repo exists and is already on the correct version", func() {
			BeforeEach(func() {
				gopath, _ := gopath.InstallationDirectory(os.Getenv("GOPATH"))