Exemple #1
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
}
// 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.")
	}
}