diff options
| author | Carlos Martín Nieto <[email protected]> | 2015-06-30 19:08:29 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <[email protected]> | 2015-06-30 19:08:29 +0200 |
| commit | b6811196e4f7728b25ab37ce2a0862aa74c22253 (patch) | |
| tree | 9760d516785beb8345f500634d7d64667c5ed395 | |
| parent | 66d266f97185020fe80f4b573411c39fc354fc91 (diff) | |
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.
| -rw-r--r-- | clone.go | 8 | ||||
| -rw-r--r-- | clone_test.go | 10 |
2 files changed, 13 insertions, 5 deletions
@@ -20,8 +20,6 @@ type CloneOptions struct { } func Clone(url string, path string, options *CloneOptions) (*Repository, error) { - repo := new(Repository) - curl := C.CString(url) defer C.free(unsafe.Pointer(curl)) @@ -37,7 +35,8 @@ func Clone(url string, path string, options *CloneOptions) (*Repository, error) runtime.LockOSThread() 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) C.free(unsafe.Pointer(copts.checkout_branch)) C.free(unsafe.Pointer(copts)) @@ -46,8 +45,7 @@ func Clone(url string, path string, options *CloneOptions) (*Repository, error) return nil, MakeGitError(ret) } - runtime.SetFinalizer(repo, (*Repository).Free) - return repo, nil + return newRepositoryFromC(ptr), nil } func populateCloneOptions(ptr *C.git_clone_options, opts *CloneOptions) { diff --git a/clone_test.go b/clone_test.go index fd83fec..7cdc362 100644 --- a/clone_test.go +++ b/clone_test.go @@ -15,8 +15,18 @@ func TestClone(t *testing.T) { path, err := ioutil.TempDir("", "git2go") checkFatal(t, err) + ref, err := repo.References.Lookup("refs/heads/master") + checkFatal(t, err) + repo2, err := Clone(repo.Path(), path, &CloneOptions{Bare: true}) defer cleanupTestRepo(t, repo2) 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") + } } |
