Пример #1
0
//GetHead - Render a revspec to a commit ID
func (g *Git) GetHead(d *Dependency) (hash string, err error) {
	var pwd string

	pwd = util.Pwd()
	util.Cd(d.Path())

	c := exec.Command("git", "rev-parse", d.Version)
	{
		var out_bytes []byte
		out_bytes, err = c.CombinedOutput()
		hash = strings.TrimSuffix(string(out_bytes), "\n")
	}

	util.Cd(pwd)

	if err != nil {
		util.Print("pwd: " + util.Pwd())
		util.PrintIndent(colors.Red("git rev-parse " + d.Version))
		util.PrintIndent(colors.Red(string(hash)))
		util.PrintIndent(colors.Red(err.Error()))
		util.Fatal("")
	}

	return
}
Пример #2
0
// IsBranch determines if a version (branch, commit hash, tag) is a branch (i.e. can we pull from the remote).
// Assumes we are already in a sub directory of the repo
func (g *Git) isBranch(name string) (result bool) {
	c := exec.Command("git", "branch", "-r")
	out, err := c.CombinedOutput()

	if err != nil {
		util.Print("pwd: " + util.Pwd())
		util.PrintIndent(colors.Red("git branch -r"))
		util.PrintIndent(colors.Red(string(out)))
		util.PrintIndent(colors.Red(err.Error()))
		return false
	}

	// get the string version but also strip the trailing newline
	stringOut := string(out[0 : len(out)-1])

	lines := strings.Split(stringOut, "\n")
	for _, val := range lines {
		// for "origin/HEAD -> origin/master"
		arr := strings.Split(val, " -> ")
		remoteBranch := arr[0]

		// for normal "origin/develop"
		arr = strings.Split(remoteBranch, "/")
		branch := arr[1]
		if branch == name {
			return true
		}
	}

	return
}
Пример #3
0
//GetHead - Render a revspec to a commit ID
func (b *Bzr) GetHead(d *Dependency) (hash string, err error) {
	var pwd string

	pwd = util.Pwd()
	util.Cd(d.Path())
	defer util.Cd(pwd)

	out, err := exec.Command("bzr", "revno", d.Version).CombinedOutput()
	hash = strings.TrimSuffix(string(out), "\n")

	if err != nil {
		util.Print("pwd: " + util.Pwd())
		util.PrintIndent(colors.Red("bzr revno " + d.Version))
		util.PrintIndent(colors.Red(hash))
		util.PrintIndent(colors.Red(err.Error()))
		util.Fatal("")
	}

	return
}
Пример #4
0
//GetHead - Render a revspec to a commit ID
func (h *Hg) GetHead(d *Dependency) (hash string, err error) {
	var pwd string

	pwd = util.Pwd()
	util.Cd(d.Path())
	defer util.Cd(pwd)

	out, err := exec.Command("hg", "id", "-i").CombinedOutput()
	hash = strings.TrimSuffix(string(out), "\n")

	if err != nil {
		util.Print("pwd: " + util.Pwd())
		util.PrintIndent(colors.Red("hg id -i"))
		util.PrintIndent(colors.Red(hash))
		util.PrintIndent(colors.Red(err.Error()))
		util.Fatal("")
	}

	return
}
Пример #5
0
// LastCommit retrieves the version number of the last commit on branch
// Assumes that the current working directory is in the bzr repo
func (b *Bzr) LastCommit(d *Dependency, branch string) (hash string, err error) {
	c := exec.Command("bzr", "log", "--line")
	out, err := c.CombinedOutput()

	if err != nil {
		util.Print("pwd: " + util.Pwd())
		util.PrintIndent(colors.Red("bzr log --line"))
		util.PrintIndent(colors.Red(string(out)))
		util.PrintIndent(colors.Red(err.Error()))
		util.Fatal("")
	}

	hash = strings.Split(string(out), ":")[0]
	return
}
Пример #6
0
//GetHead - Render a revspec to a commit ID
func (h *Hg) GetHead(d *Dependency) (hash string, err error) {
	var pwd string

	pwd = util.Pwd()
	util.Cd(d.Path())

	{
		var out_bytes []byte
		out_bytes, err = exec.Command("hg", "id", "-i", d.Version).CombinedOutput()
		hash = strings.TrimSuffix(string(out_bytes), "\n")
	}

	util.Cd(pwd)

	if err != nil {
		util.Print("pwd: " + util.Pwd())
		util.PrintIndent(colors.Red("hg id -i " + d.Version))
		util.PrintIndent(colors.Red(hash))
		util.PrintIndent(colors.Red(err.Error()))
		util.Fatal("")
	}

	return
}
Пример #7
0
// LastCommit retrieves the version number of the last commit on branch
// Assumes that the current working directory is in the hg repo
func (h *Hg) LastCommit(d *Dependency, branch string) (hash string, err error) {
	c := exec.Command("hg", "log", "--template='{node}\n'", "--limit=1")
	out, err := c.CombinedOutput()

	if err != nil {
		util.Print("pwd: " + util.Pwd())
		util.PrintIndent(colors.Red("hg log --template='{node}\n' --limit=1"))
		util.PrintIndent(colors.Red(string(out)))
		util.PrintIndent(colors.Red(err.Error()))
		util.Fatal("")
	}

	hash = strings.Replace(string(out), "\n", "", -1)
	return
}
Пример #8
0
// LastCommit retrieves the version number of the last commit on branch
// Assumes that the current working directory is in the git repo
func (g *Git) LastCommit(d *Dependency, branch string) (hash string, err error) {
	if !g.isBranch(branch) {
		err = errors.New("Branch '" + branch + "' is not a valid branch")
		return
	}

	c := exec.Command("git", "log", "-1", "--format=%H")
	out, err := c.CombinedOutput()

	if err != nil {
		util.Print("pwd: " + util.Pwd())
		util.PrintIndent(colors.Red("git log -1 --format=%H"))
		util.PrintIndent(colors.Red(string(out)))
		util.PrintIndent(colors.Red(err.Error()))
		util.Fatal("")
	}

	hash = strings.Replace(string(out), "\n", "", -1)
	return
}
Пример #9
0
// Update rewrites Dependency name in deps.json to use the last commit in branch as version
func Update(deps dep.DependencyMap, name string, branch string) {
	util.Print(colors.Blue("Updating:"))

	d, ok := deps.Map[name]
	if !ok {
		util.Fatal(colors.Red("Dependency Name '" + name + "' not found in deps.json"))
	}

	// record the old version
	oldVersion := d.Version

	// temporarily use the branch
	d.Version = branch

	pwd := util.Pwd()
	util.Cd(d.Path())
	d.VCS.Checkout(d)
	d.VCS.Update(d)

	// get the last commit on the newly checked out branch
	v, err := d.VCS.LastCommit(d, branch)
	if err != nil {
		util.Fatal(err)
	}

	// set the version to be the last commit
	d.Version = v

	util.PrintIndent(colors.Blue(name) + " (" + oldVersion + " --> " + d.Version + ")")

	util.Cd(pwd)
	deps.Map[name] = d
	deps.Write()

	install.Install(deps)

}