Clone: test we clone something usable and fix constructor

Clone was still trying to do its own initialisation, which was missing
all of the namespacing changes.
This commit is contained in:
Carlos Martín Nieto 2015-06-30 19:08:29 +02:00
parent 66d266f971
commit b6811196e4
2 changed files with 13 additions and 5 deletions

View File

@ -20,8 +20,6 @@ type CloneOptions struct {
} }
func Clone(url string, path string, options *CloneOptions) (*Repository, error) { func Clone(url string, path string, options *CloneOptions) (*Repository, error) {
repo := new(Repository)
curl := C.CString(url) curl := C.CString(url)
defer C.free(unsafe.Pointer(curl)) defer C.free(unsafe.Pointer(curl))
@ -37,7 +35,8 @@ func Clone(url string, path string, options *CloneOptions) (*Repository, error)
runtime.LockOSThread() runtime.LockOSThread()
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
ret := C.git_clone(&repo.ptr, curl, cpath, copts) var ptr *C.git_repository
ret := C.git_clone(&ptr, curl, cpath, copts)
freeCheckoutOpts(&copts.checkout_opts) freeCheckoutOpts(&copts.checkout_opts)
C.free(unsafe.Pointer(copts.checkout_branch)) C.free(unsafe.Pointer(copts.checkout_branch))
C.free(unsafe.Pointer(copts)) C.free(unsafe.Pointer(copts))
@ -46,8 +45,7 @@ func Clone(url string, path string, options *CloneOptions) (*Repository, error)
return nil, MakeGitError(ret) return nil, MakeGitError(ret)
} }
runtime.SetFinalizer(repo, (*Repository).Free) return newRepositoryFromC(ptr), nil
return repo, nil
} }
func populateCloneOptions(ptr *C.git_clone_options, opts *CloneOptions) { func populateCloneOptions(ptr *C.git_clone_options, opts *CloneOptions) {

View File

@ -15,8 +15,18 @@ func TestClone(t *testing.T) {
path, err := ioutil.TempDir("", "git2go") path, err := ioutil.TempDir("", "git2go")
checkFatal(t, err) checkFatal(t, err)
ref, err := repo.References.Lookup("refs/heads/master")
checkFatal(t, err)
repo2, err := Clone(repo.Path(), path, &CloneOptions{Bare: true}) repo2, err := Clone(repo.Path(), path, &CloneOptions{Bare: true})
defer cleanupTestRepo(t, repo2) defer cleanupTestRepo(t, repo2)
checkFatal(t, err) checkFatal(t, err)
ref2, err := repo2.References.Lookup("refs/heads/master")
checkFatal(t, err)
if ref.Cmp(ref2) != 0 {
t.Fatal("reference in clone does not match original ref")
}
} }