From ad128bdefb58927762798a5b708a63bff43b627e Mon Sep 17 00:00:00 2001 From: Carlos Martín Nieto Date: Wed, 19 Mar 2014 07:54:52 +0100 Subject: Remote: don't mix allocators We cannot ask libgit2 to free the memory we have allocated ourselves, as it cannot know how to do it. Let's free the strarray ourselves. --- remote_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 remote_test.go (limited to 'remote_test.go') diff --git a/remote_test.go b/remote_test.go new file mode 100644 index 0000000..16675fc --- /dev/null +++ b/remote_test.go @@ -0,0 +1,27 @@ +package git + +import ( + "os" + "testing" +) + +func TestRefspecs(t *testing.T) { + repo := createTestRepo(t) + defer os.RemoveAll(repo.Workdir()) + + remote, err := repo.CreateRemoteInMemory("refs/heads/*:refs/heads/*", "git://foo/bar") + checkFatal(t, err) + + expected := []string{ + "refs/heads/*:refs/remotes/origin/*", + "refs/pull/*/head:refs/remotes/origin/*", + } + + err = remote.SetFetchRefspecs(expected) + checkFatal(t, err) + + actual, err := remote.GetFetchRefspecs() + checkFatal(t, err) + + compareStringList(t, expected, actual) +} -- cgit v1.2.3 From 574f0dd12da2eae6f26ae35f197b2ec7a9328249 Mon Sep 17 00:00:00 2001 From: Carlos Martín Nieto Date: Thu, 20 Mar 2014 03:29:54 +0100 Subject: Remote: remove Get prefix from refspecs Idiomatic Go is to omit the Get from the getter methods. --- remote.go | 4 ++-- remote_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'remote_test.go') diff --git a/remote.go b/remote.go index 3e01ce1..d556f99 100644 --- a/remote.go +++ b/remote.go @@ -316,7 +316,7 @@ func freeStrarray(arr *C.git_strarray) { C.free(unsafe.Pointer(arr.strings)) } -func (o *Remote) GetFetchRefspecs() ([]string, error) { +func (o *Remote) FetchRefspecs() ([]string, error) { crefspecs := C.git_strarray{} runtime.LockOSThread() @@ -362,7 +362,7 @@ func (o *Remote) AddPush(refspec string) error { return nil } -func (o *Remote) GetPushRefspecs() ([]string, error) { +func (o *Remote) PushRefspecs() ([]string, error) { crefspecs := C.git_strarray{} runtime.LockOSThread() diff --git a/remote_test.go b/remote_test.go index 16675fc..04b3a57 100644 --- a/remote_test.go +++ b/remote_test.go @@ -20,7 +20,7 @@ func TestRefspecs(t *testing.T) { err = remote.SetFetchRefspecs(expected) checkFatal(t, err) - actual, err := remote.GetFetchRefspecs() + actual, err := remote.FetchRefspecs() checkFatal(t, err) compareStringList(t, expected, actual) -- cgit v1.2.3 From 99d7f66477aa09915821659087da8b91e593f4eb Mon Sep 17 00:00:00 2001 From: Jesse Ezell Date: Thu, 20 Mar 2014 02:06:56 -0700 Subject: add remote list --- remote.go | 12 ++++++++++++ remote_test.go | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'remote_test.go') diff --git a/remote.go b/remote.go index d556f99..d675ab8 100644 --- a/remote.go +++ b/remote.go @@ -132,6 +132,18 @@ func (r *Remote) Free() { C.git_remote_free(r.ptr) } +func (repo *Repository) ListRemotes() ([]string, error) { + var r C.git_strarray + ecode := C.git_remote_list(&r, repo.ptr) + if ecode < 0 { + return make([]string, 0), MakeGitError(ecode) + } + defer C.git_strarray_free(&r) + + remotes := makeStringsFromCStrings(r.strings, int(r.count)) + return remotes, nil +} + func (repo *Repository) CreateRemote(name string, url string) (*Remote, error) { remote := &Remote{} diff --git a/remote_test.go b/remote_test.go index 04b3a57..90e24ae 100644 --- a/remote_test.go +++ b/remote_test.go @@ -8,6 +8,7 @@ import ( func TestRefspecs(t *testing.T) { repo := createTestRepo(t) defer os.RemoveAll(repo.Workdir()) + defer repo.Free() remote, err := repo.CreateRemoteInMemory("refs/heads/*:refs/heads/*", "git://foo/bar") checkFatal(t, err) @@ -25,3 +26,22 @@ func TestRefspecs(t *testing.T) { compareStringList(t, expected, actual) } + +func TestListRemotes(t *testing.T) { + repo := createTestRepo(t) + defer os.RemoveAll(repo.Workdir()) + defer repo.Free() + + _, err := repo.CreateRemote("test", "git://foo/bar") + + checkFatal(t, err) + + expected := []string{ + "test", + } + + actual, err := repo.ListRemotes() + checkFatal(t, err) + + compareStringList(t, expected, actual) +} -- cgit v1.2.3 From 9d0d814f19e9d31caeeb68abce84f9eba9659737 Mon Sep 17 00:00:00 2001 From: Jesse Ezell Date: Tue, 1 Apr 2014 11:06:47 -0700 Subject: rename inmemory to anonymous remote --- remote.go | 4 ++-- remote_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'remote_test.go') diff --git a/remote.go b/remote.go index 66097b8..da04d2a 100644 --- a/remote.go +++ b/remote.go @@ -184,7 +184,7 @@ func (repo *Repository) CreateRemoteWithFetchspec(name string, url string, fetch return remote, nil } -func (repo *Repository) CreateRemoteInMemory(fetch string, url string) (*Remote, error) { +func (repo *Repository) CreateAnonymousRemote(fetch string, url string) (*Remote, error) { remote := &Remote{} curl := C.CString(url) @@ -195,7 +195,7 @@ func (repo *Repository) CreateRemoteInMemory(fetch string, url string) (*Remote, runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_remote_create_inmemory(&remote.ptr, repo.ptr, cfetch, curl) + ret := C.git_remote_create_anonymous(&remote.ptr, repo.ptr, cfetch, curl) if ret < 0 { return nil, MakeGitError(ret) } diff --git a/remote_test.go b/remote_test.go index 90e24ae..37ed8c3 100644 --- a/remote_test.go +++ b/remote_test.go @@ -10,7 +10,7 @@ func TestRefspecs(t *testing.T) { defer os.RemoveAll(repo.Workdir()) defer repo.Free() - remote, err := repo.CreateRemoteInMemory("refs/heads/*:refs/heads/*", "git://foo/bar") + remote, err := repo.CreateAnonymousRemote("refs/heads/*:refs/heads/*", "git://foo/bar") checkFatal(t, err) expected := []string{ -- cgit v1.2.3 From 9cd1d129bcd567ef65137783a603f8d898d8d933 Mon Sep 17 00:00:00 2001 From: Carlos Martín Nieto Date: Tue, 1 Apr 2014 20:10:20 +0200 Subject: Remote: The whole point of the anonymous change Was that it would break and we'd remember that the order changed. Oh well. --- remote.go | 4 ++-- remote_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'remote_test.go') diff --git a/remote.go b/remote.go index da04d2a..eb5d7a7 100644 --- a/remote.go +++ b/remote.go @@ -184,7 +184,7 @@ func (repo *Repository) CreateRemoteWithFetchspec(name string, url string, fetch return remote, nil } -func (repo *Repository) CreateAnonymousRemote(fetch string, url string) (*Remote, error) { +func (repo *Repository) CreateAnonymousRemote(url, fetch string) (*Remote, error) { remote := &Remote{} curl := C.CString(url) @@ -195,7 +195,7 @@ func (repo *Repository) CreateAnonymousRemote(fetch string, url string) (*Remote runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_remote_create_anonymous(&remote.ptr, repo.ptr, cfetch, curl) + ret := C.git_remote_create_anonymous(&remote.ptr, repo.ptr, curl, cfetch) if ret < 0 { return nil, MakeGitError(ret) } diff --git a/remote_test.go b/remote_test.go index 37ed8c3..7cef1ec 100644 --- a/remote_test.go +++ b/remote_test.go @@ -10,7 +10,7 @@ func TestRefspecs(t *testing.T) { defer os.RemoveAll(repo.Workdir()) defer repo.Free() - remote, err := repo.CreateAnonymousRemote("refs/heads/*:refs/heads/*", "git://foo/bar") + remote, err := repo.CreateAnonymousRemote("git://foo/bar", "refs/heads/*:refs/heads/*") checkFatal(t, err) expected := []string{ -- cgit v1.2.3