示例#1
0
func (s *GitSuite) TestIsGitBranch(c *C) {
	g := new(Git)

	parts := strings.Split(os.Getenv("GOPATH"), ":")

	var path string

	for _, v := range parts {
		p := filepath.Join(v, "src", "github.com", "vube", "depman")
		if util.Exists(p) {
			path = p
		}
	}

	c.Assert(path, Not(Equals), "")

	util.Cd(path)
	c.Check(g.isBranch("master"), Equals, true)

	c.Check(g.isBranch("2.1.0"), Equals, false)
	c.Check(g.isBranch("7da42054c10f55d5f479b84f59013818ccbd1fd7"), Equals, false)

	util.Cd("/")

	c.Check(g.isBranch("master"), Equals, false)
	output := "pwd: /\n" +
		"git branch -r\n" +
		"fatal: Not a git repository (or any of the parent directories): .git\n" +
		"exit status 128\n"
	c.Check(s.buf.String(), Equals, output)
}
示例#2
0
// Path returns the path for this dependency
// searches for the appropriate directory in each part of the GOPATH (delimited by ':')
// if not found return the path using the first port of GOPATH
func (d *Dependency) Path() (p string) {
	parts := strings.Split(os.Getenv("GOPATH"), ":")

	for _, path := range parts {
		p = filepath.Join(path, "src")
		if d.Alias == "" {
			p = filepath.Join(p, d.Repo)
		} else {
			p = filepath.Join(p, d.Alias)
		}

		if util.Exists(p) {
			return
		}
	}

	// didn't find a directory, use the first part of gopath
	p = filepath.Join(parts[0], "src")
	if d.Alias == "" {
		p = filepath.Join(p, d.Repo)
	} else {
		p = filepath.Join(p, d.Alias)
	}

	return

}
示例#3
0
func Read() {
	cacheFile = filepath.Join(os.Getenv("GOPATH"), cacheFileName)

	cache = make(map[string]time.Time)

	if !util.Exists(cacheFile) {
		return
	}

	if clear {
		err := os.Remove(cacheFile)
		if err != nil {
			util.Fatal(err)
		}
		return
	}

	util.Verbose("Reading cache file from " + cacheFile)

	data, err := ioutil.ReadFile(cacheFile)
	if err != nil {
		util.Fatal(err)
	}

	err = json.Unmarshal(data, &cache)
	if err != nil {
		return
	}
}
示例#4
0
// Clone clones d.Repo into d.Path() if d.Path does not exist, otherwise it will cd to d.Path() and run git fetch
func (g *Git) Clone(d *Dependency) (err error) {
	if !util.Exists(d.Path()) {
		if d.Type == TypeGitClone {
			err = util.RunCommand("git clone " + d.Repo + " " + d.Path())
		} else {
			err = util.RunCommand("go get -u " + d.Repo)
		}
	}
	return
}
示例#5
0
// Create writes an empty deps.json at the location specified by path
func Create(path string) {
	if util.Exists(path) {
		util.Fatal(colors.Red(dep.DepsFile + " already exists!"))
	}
	util.Print(colors.Blue("Initializing:"))
	err := ioutil.WriteFile(path, []byte(template), 0644)
	if err == nil {
		util.Print("Empty " + dep.DepsFile + " created (" + path + ")")
	} else {
		util.Fatal(colors.Red("Error creating "+dep.DepsFile+": "), err)
	}
	return
}
示例#6
0
// Read reads the cache from disk
func Read() {
	parts := strings.Split(os.Getenv("GOPATH"), ":")
	cacheFile = filepath.Join(parts[0], cacheFileName)

	cache = make(map[string]time.Time)

	if !util.Exists(cacheFile) {
		return
	}

	util.Verbose("Reading cache file from " + cacheFile)

	data, err := ioutil.ReadFile(cacheFile)
	if err != nil {
		util.Fatal(err)
	}

	err = json.Unmarshal(data, &cache)
	if err != nil {
		return
	}
}
示例#7
0
// Clone clones a bzr repo
func (b *Bzr) Clone(d *Dependency) (err error) {
	if !util.Exists(d.Path()) {
		err = util.RunCommand("go get -u " + d.Repo)
	}
	return
}