Пример #1
0
func install(root string, recursive bool, exclude []string) {
	cartridge, err := set.LoadFrom(root)
	if err != nil {
		fatal(err)
	}

	runner := command_runner.New(false)

	fetcher, err := fetcher.New(runner)
	if err != nil {
		fatal(err)
	}

	err = installDependencies(fetcher, cartridge, recursive, exclude, 0)
	if err != nil {
		fatal(err)
	}

	err = cartridge.SaveTo(root)
	if err != nil {
		fatal(err)
	}

	fmt.Println(green("OK"))
}
Пример #2
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
}
Пример #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 command_runner_test

import (
	"os/exec"

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

	"github.com/vito/gocart/command_runner"
)

var _ = Describe("Running commands", func() {
	It("runs the command and returns nil", func() {
		runner := command_runner.New(false)

		cmd := exec.Command("ls")
		Expect(cmd.ProcessState).To(BeNil())

		err := runner.Run(cmd)
		Expect(err).ToNot(HaveOccurred())

		Expect(cmd.ProcessState).ToNot(BeNil())
	})

	Context("when the command fails", func() {
		It("returns an error containing its output", func() {
			runner := command_runner.New(false)

			err := runner.Run(exec.Command(
				"/bin/bash",
				"-c", "echo hi out; echo hi err >/dev/stderr; exit 42",