예제 #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
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
}
예제 #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
}
예제 #4
0
		var err error

		BeforeEach(func() {
			repoPath, err = ioutil.TempDir(os.TempDir(), "git_repo")
			Expect(err).ToNot(HaveOccurred())

			os.Mkdir(path.Join(repoPath, ".git"), 0600)
		})

		AfterEach(func() {
			os.RemoveAll(repoPath)
		})

		Describe("type identification", func() {
			It("returns that it is a GitRepository", func() {
				repo, err := repository.New(repoPath, runner)
				Expect(err).ToNot(HaveOccurred())

				_, correctType := repo.(*repository.GitRepository)
				Expect(correctType).To(BeTrue())
			})
		})
	})

	Describe("a hg repository", func() {
		var repoPath string
		var err error

		BeforeEach(func() {
			repoPath, err = ioutil.TempDir(os.TempDir(), "hg_repo")
			Expect(err).ToNot(HaveOccurred())
예제 #5
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
}