func copyRecipes(c config.CodeResourceOperator, path string) error { if err := prepareDir(c, path); err != nil { return err } destDir := filepath.Join(path, c.DesticationPath()) srcDir := filepath.Join(c.CacheRepoPath(), c.SourcePath()) fmt.Printf(" -- copy %s to %s\n", srcDir, destDir) cmd := exec.Command("cp", "-rf", srcDir+"/", destDir) if err := cmd.Run(); err != nil { return err } return nil }
func updateCookbook(c config.CodeResourceOperator) error { path := c.CacheRepoPath() if _, err := os.Stat(path + "/.git"); os.IsNotExist(err) { gitCloneOption := new(git.CloneOptions) fmt.Println(c.RemotoRepoUrl()) if _, err := git.Clone(c.RemotoRepoUrl(), path, gitCloneOption); err != nil { return err } fmt.Printf("clone to locat from %s\n", c.RemotoRepoUrl()) } else { repo, err := git.OpenRepository(path) if err != nil { return err } remote, err := repo.Remotes.Lookup("origin") fmt.Printf("fetching to locat from %s\n", remote.Url()) if err != nil { return err } if err := remote.Fetch([]string{}, nil, ""); err != nil { return err } remoteLs, err := remote.Ls("HEAD") if err != nil { return err } remoteOid := remoteLs[0].Id headCommit, err := repo.LookupCommit(remoteOid) if err != nil { return err } if err := repo.ResetToCommit(headCommit, git.ResetHard, &git.CheckoutOpts{}); err != nil { return err } // TODO use short ref id fmt.Printf(" -- now %s\n", remoteOid) } return nil }