package forgepb import ( "errors" "fmt" "os" "path/filepath" "go.wit.com/lib/gui/shell" "go.wit.com/log" ) // git clone (also downloads git notes) // newdir = helloworld // basedir = /home/jcarr/go/src/go.wit.com/apps // giturl = https://gitea.wit.com/gui/helloworld func RunGitClone(newdir, basedir, giturl string) error { log.Info("runGitClone() newdir =", newdir) log.Info("runGitClone() basedir =", basedir) log.Info("runGitClone() giturl =", giturl) if !shell.IsDir(basedir) { os.MkdirAll(basedir, os.ModePerm) } err := os.Chdir(basedir) if err != nil { // log.Warn("chdir failed", basedir, err) return err } cmd := []string{"git", "clone", "--verbose", "--progress", giturl, newdir} log.Info("Running:", basedir, cmd) r := shell.PathRunRealtime(basedir, cmd) if r.Error != nil { // log.Warn("git clone error", r.Error) return r.Error } fullpath := filepath.Join(basedir, newdir) if !shell.IsDir(fullpath) { // log.Info("git clone failed", giturl) return fmt.Errorf("git clone %s failed to create a directory", giturl) } gitdir := filepath.Join(fullpath, ".git") if shell.IsDir(gitdir) { // log.Info("git cloned worked to", fullpath) // also clone notes -- this can store the go.mod and go.sum files cmd := []string{"git", "fetch", "origin", "refs/notes/*:refs/notes/*"} shell.PathRunRealtime(fullpath, cmd) return nil } // git clone didn't really work but did make a directory log.Info("fullpath is probably empty", fullpath) return errors.New("crapnuts. rmdir fullpath here? " + fullpath) }