Example #1
0
func (repo *Repository) ListRemotes() ([]string, error) {
	var r C.git_strarray
	ecode := C.git_remote_list(&r, repo.ptr)
	if ecode < 0 {
		return nil, MakeGitError(ecode)
	}
	defer C.git_strarray_free(&r)

	remotes := makeStringsFromCStrings(r.strings, int(r.count))
	return remotes, nil
}
Example #2
0
func (c *RemoteCollection) List() ([]string, error) {
	var r C.git_strarray

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ecode := C.git_remote_list(&r, c.repo.ptr)
	if ecode < 0 {
		return nil, MakeGitError(ecode)
	}
	defer C.git_strarray_free(&r)

	remotes := makeStringsFromCStrings(r.strings, int(r.count))
	return remotes, nil
}
Example #3
0
func (repo *Repository) ListRemotes() ([]string, error) {
	var cremotes C.git_strarray
	defer C.git_strarray_free(&cremotes)
	ecode := C.git_remote_list(&cremotes, repo.git_repository)
	if ecode != git_SUCCESS {
		return nil, gitError()
	}

	// TODO: Find a safer way if one exists.
	var remotesSlice reflect.SliceHeader
	length := int(cremotes.count)
	remotesSlice.Data = uintptr(unsafe.Pointer(cremotes.strings))
	remotesSlice.Len = length
	remotesSlice.Cap = length
	cremoteStrings := *(*[]*C.char)(unsafe.Pointer(&remotesSlice))

	remotes := make([]string, length)
	for i := 0; i < len(cremoteStrings); i++ {
		remotes[i] = C.GoString(cremoteStrings[i])
	}

	return remotes, nil
}