Example #1
0
File: goat.go Project: pib/goat
func main() {

	cwd, err := os.Getwd()
	if err != nil {
		fatal(err)
	}

	projroot, err := env.FindProjRoot(cwd)
	var genv *env.GoatEnv
	if err == nil {
		genv, err = env.NewGoatEnv(projroot)
		if err != nil {
			fatal(err)
		}

		if err = genv.PrependToGoPath(); err != nil {
			fatal(err)
		}

		if err = genv.Setup(); err != nil {
			fatal(err)
		}
	}

	args := os.Args[1:]
	if len(args) < 1 {
		printGhelp()
	}

	switch args[0] {
	case "deps":
		if genv != nil {
			err := genv.FetchDependencies(genv.AbsDepDir())
			if err != nil {
				fatal(err)
			}
		} else {
			fatal(errors.New(".go.yaml file not found on current path"))
		}
	case "ghelp":
		printGhelp()
	default:
		if actualgo, ok := ActualGo(); ok {
			err := exec.PipedCmd(actualgo, args...)
			if err != nil {
				os.Exit(1)
			}
		} else {
			newargs := make([]string, len(args)+1)
			copy(newargs[1:], args)
			newargs[0] = "go"
			err := exec.PipedCmd("/usr/bin/env", newargs...)
			if err != nil {
				os.Exit(1)
			}
		}
	}
}
Example #2
0
File: git.go Project: pib/goat
func Git(depdir string, dep *Dependency) error {
	localloc := filepath.Join(depdir, "src", dep.Path)

	if _, err := os.Stat(localloc); os.IsNotExist(err) {
		fmt.Println("git", "clone", dep.Location, localloc)
		err := exec.PipedCmd("git", "clone", dep.Location, localloc)
		if err != nil {
			return err
		}
	} else {
		fmt.Println(localloc, "exists")
	}

	origcwd, err := os.Getwd()
	if err != nil {
		return err
	}

	err = os.Chdir(localloc)
	if err != nil {
		return err
	}
	defer os.Chdir(origcwd)

	fmt.Println("git", "fetch", "-pv", "--all")
	err = exec.PipedCmd("git", "fetch", "-pv", "--all")
	if err != nil {
		return err
	}

	if dep.Reference == "" {
		dep.Reference = "master"
	}
	if exists, err := originBranchExists(dep.Reference); err != nil {
		return err
	} else if exists {
		dep.Reference = "origin/" + dep.Reference
	}
	fmt.Println("git", "checkout", dep.Reference)
	stdout, stderr, err := exec.TrimmedCmd("git", "checkout", dep.Reference)
	if err != nil {
		return err
	}
	if stdout != "" {
		fmt.Println(stdout)
	}
	// Moving to a 'detached HEAD' state causes git to output a huge explanation
	// to stderr.  We only want the last line.
	lines := strings.Split(stderr, "\n")
	fmt.Println(lines[len(lines)-1])

	fmt.Println("git", "clean", "-f", "-d")
	err = exec.PipedCmd("git", "clean", "-f", "-d")

	return err

}
Example #3
0
File: hg.go Project: pib/goat
func Hg(depdir string, dep *Dependency) error {
	localloc := filepath.Join(depdir, "src", dep.Path)

	if _, err := os.Stat(localloc); os.IsNotExist(err) {
		fmt.Println("hg", "clone", dep.Location, localloc)
		err := exec.PipedCmd("hg", "clone", dep.Location, localloc)
		if err != nil {
			return err
		}
	} else {
		fmt.Println(localloc, "exists")
	}

	origcwd, err := os.Getwd()
	if err != nil {
		return err
	}

	err = os.Chdir(localloc)
	if err != nil {
		return err
	}
	defer os.Chdir(origcwd)

	fmt.Println("hg", "pull")
	err = exec.PipedCmd("hg", "pull")
	if err != nil {
		return err
	}

	if dep.Reference == "" {
		dep.Reference = "tip"
	}
	fmt.Println("hg", "update", "-C", dep.Reference)
	err = exec.PipedCmd("hg", "update", "-C", dep.Reference)

	return err

}
Example #4
0
File: goget.go Project: pib/goat
func GoGet(depdir string, dep *Dependency) error {
	fmt.Println("go", "get", dep.Location)
	return exec.PipedCmd("go", "get", dep.Location)
}