123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package git
- import (
- "buildme/utils"
- "io/ioutil"
- "os"
- "path/filepath"
- "buildme"
- "dev.hexasoftware.com/hxs/prettylog"
- git "gopkg.in/src-d/go-git.v4"
- )
- var (
- log = prettylog.New("GitFetcher")
- )
- func init() {
- // Register fetcher
- buildme.RegisterFetcher("git", &Git{})
- }
- type Git struct{}
- // Fetcher return a project
- func (g *Git) Fetch(fpath string) (*buildme.Project, error) {
- log.Println("Building git repo:", fpath)
- // File possibilities, does not cover the folder/subfolder
- if fpath == "." || fpath[0:2] == "./" || fpath[0] == '/' {
- absPath, err := filepath.Abs(fpath)
- if err != nil {
- return nil, err
- }
- fpath = "file://" + absPath
- }
- // Create tmpdir to clone project
- tmpdirname, err := ioutil.TempDir(buildme.TempDir(), "buildme.")
- if err != nil {
- return nil, err
- }
- log.Println("Cloning to:", tmpdirname)
- _, err = git.PlainClone(tmpdirname, false, &git.CloneOptions{URL: fpath, Progress: os.Stdout})
- if err != nil {
- log.Println("Err:", err)
- return nil, err
- }
- projName := filepath.Base(fpath)
- //git.
- log.Println("Taring content")
- /*tarfile, err := ioutil.TempFile("/tmp", "tarbuildme.")
- reader, err := utils.TarDir(tmpdir, tarfile)*/
- // Create a temporary tar file from tmpdirname
- tarFile, err := utils.TempTar(tmpdirname, buildme.TempDir(), "buildme.tar")
- log.Println("Tar file:", tarFile.Name())
- log.Println("Removing dir", tmpdirname)
- os.RemoveAll(tmpdirname)
- proj := buildme.NewProject(projName)
- proj.SetTarFile(tarFile.Name(), true) // Set as temporary will delete as soon as project closes
- return proj, nil
- }
|