Ejemplo n.º 1
1
// Clone clones a repo and also updates the repos submodules.
func Clone(url string, path string, branch string) (*git.Repository, error) {
	co := &git.CloneOptions{
		CheckoutOpts: &git.CheckoutOpts{
			Strategy: git.CheckoutForce | git.CheckoutUpdateSubmodules,
		},
		CheckoutBranch: branch,
	}

	repo, err := git.Clone(url, path, co)
	if err != nil {
		return repo, err
	}

	// At the moments the submodules are not updated recursively.
	repo.Submodules.Foreach(func(sub *git.Submodule, name string) int {
		err = sub.Update(true, &git.SubmoduleUpdateOptions{
			CheckoutOpts: &git.CheckoutOpts{
				Strategy: git.CheckoutForce,
			},
			FetchOptions:          &git.FetchOptions{},
			CloneCheckoutStrategy: git.CheckoutForce,
		})

		return 0
	})

	return repo, nil
}
Ejemplo n.º 2
0
func Clone(url, dir string, opt vcs.CloneOpt) (vcs.Repository, error) {
	clopt := git2go.CloneOptions{Bare: opt.Bare}

	rc, cfs, err := makeRemoteCallbacks(url, opt.RemoteOpts)
	if err != nil {
		return nil, err
	}
	if cfs != nil {
		defer cfs.run()
	}
	if rc != nil {
		clopt.FetchOptions = &git2go.FetchOptions{RemoteCallbacks: *rc}
	}

	u, err := git2go.Clone(url, dir, &clopt)
	if err != nil {
		return nil, err
	}
	cr, err := gitcmd.Open(dir)
	if err != nil {
		return nil, err
	}
	r := &Repository{Repository: cr, u: u}
	if _, err := r.UpdateEverything(opt.RemoteOpts); err != nil {
		return nil, err
	}
	return r, nil
}
Ejemplo n.º 3
0
Archivo: .go Proyecto: shadowhq/nyx
func GetRepo(repo_url string) (*git.Repository, error) {
	repo, err := git.Clone(repo_url, "sample_repo", &git.CloneOptions{})
	if err != nil {
		// Pass error up to be dealt with by handler
		return nil, err
	}
	if repo == nil {
		// TODO: Figure out if this would happen without err returned
		panic(err)
	}

	return repo, nil
}
Ejemplo n.º 4
0
func main() {

	cbs := &git.RemoteCallbacks{
		CredentialsCallback:      credentialsCallback,
		CertificateCheckCallback: certificateCheckCallback,
	}

	cloneOptions := &git.CloneOptions{}
	//cloneOptions.RemoteCallbacks = cbs
	_ = cbs

	repo, err := git.Clone("/Users/realbot/Dropbox/gitos/veles.git", "veles", cloneOptions)
	if err != nil {
		log.Panic(err)
	}

	log.Print(repo)
}
Ejemplo n.º 5
0
// generateTestRepo clones a dummy repository to be used for testing.
func generateTestRepo() {
	// Check if dummy_repo exists and only clone if repo does not exist.
	if _, err := os.Stat("test_dir/dummy_repo"); err != nil {
		log.Print("Dummy repository not found, cloning to test_dir/dummy_repo...")
		// Check if dummy_repo is a directory
		cloneOptions := git.CloneOptions{}
		cloneOptions.FetchOptions = &git.FetchOptions{
			RemoteCallbacks: git.RemoteCallbacks{
				CredentialsCallback:      credentialsCallback,
				CertificateCheckCallback: certificateCheckCallback,
			},
		}
		_, err := git.Clone(DummyRepoUrl, "test_dir/", &cloneOptions)
		if err != nil {
			log.Fatal(err)
		}
	} else {
		log.Print("Dummy repository found.")
	}
}
Ejemplo n.º 6
0
func new(templateName string) {
	repoName := templateName + suffix
	repoURL := "https://github.com/" + repoName + ".git"

	fullPath = path.Join(cwd, name)
	gitopts := &git.CloneOptions{}

	boldWhite.Printf("Retrieving %s via %s\n", templateName, repoURL)
	_, err := git.Clone(repoURL, fullPath, gitopts)

	if err != nil {
		log.Fatal(err)
	} else {
		println()
	}

	config(name, path.Join(fullPath, templateFile))
	askForVariables()
	clean()
	compile()
	commands()
	fmt.Printf("Your %s project was created successfully.\n", templateName)
}
Ejemplo n.º 7
0
func describe(templateName string) {
	repoName := templateName + suffix
	repoURL := "https://github.com/" + repoName + ".git"

	tempDir := os.TempDir()
	fullPath = path.Join(tempDir, "prueba")
	gitopts := &git.CloneOptions{}

	_, err := git.Clone(repoURL, fullPath, gitopts)
	if err != nil {
		os.RemoveAll(fullPath)
		log.Fatal(err)
	} else {
		println()
	}

	config(name, path.Join(fullPath, templateFile))

	boldWhite.Println("Variables in template")
	for key, defaultValue := range templateConfig.Variables {
		if key != "name" {
			fmt.Printf("%s [%s]\n", key, defaultValue)
		}
	}

	println()

	boldWhite.Println("Commands in template")
	for n, command := range templateConfig.Commands {
		fmt.Printf("%d. ", n+1)
		fmt.Printf("%s", command)
		println()
	}

	os.RemoveAll(fullPath)
}