Update to libgit2 b6011e29
This commit is contained in:
parent
85fde1fcfb
commit
36e0a256fe
4
clone.go
4
clone.go
|
@ -12,7 +12,7 @@ import (
|
||||||
|
|
||||||
type CloneOptions struct {
|
type CloneOptions struct {
|
||||||
*CheckoutOpts
|
*CheckoutOpts
|
||||||
*RemoteCallbacks
|
*FetchOptions
|
||||||
Bare bool
|
Bare bool
|
||||||
CheckoutBranch string
|
CheckoutBranch string
|
||||||
RemoteCreateCallback C.git_remote_create_cb
|
RemoteCreateCallback C.git_remote_create_cb
|
||||||
|
@ -55,7 +55,7 @@ func populateCloneOptions(ptr *C.git_clone_options, opts *CloneOptions) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
populateCheckoutOpts(&ptr.checkout_opts, opts.CheckoutOpts)
|
populateCheckoutOpts(&ptr.checkout_opts, opts.CheckoutOpts)
|
||||||
populateRemoteCallbacks(&ptr.remote_callbacks, opts.RemoteCallbacks)
|
populateFetchOptions(&ptr.fetch_opts, opts.FetchOptions)
|
||||||
ptr.bare = cbool(opts.Bare)
|
ptr.bare = cbool(opts.Bare)
|
||||||
|
|
||||||
if opts.RemoteCreateCallback != nil {
|
if opts.RemoteCreateCallback != nil {
|
||||||
|
|
4
git.go
4
git.go
|
@ -76,8 +76,8 @@ const (
|
||||||
ErrNonFastForward ErrorCode = C.GIT_ENONFASTFORWARD
|
ErrNonFastForward ErrorCode = C.GIT_ENONFASTFORWARD
|
||||||
// Name/ref spec was not in a valid format
|
// Name/ref spec was not in a valid format
|
||||||
ErrInvalidSpec ErrorCode = C.GIT_EINVALIDSPEC
|
ErrInvalidSpec ErrorCode = C.GIT_EINVALIDSPEC
|
||||||
// Merge conflicts prevented operation
|
// Checkout conflicts prevented operation
|
||||||
ErrMergeConflict ErrorCode = C.GIT_EMERGECONFLICT
|
ErrConflict ErrorCode = C.GIT_ECONFLICT
|
||||||
// Lock file prevented operation
|
// Lock file prevented operation
|
||||||
ErrLocked ErrorCode = C.GIT_ELOCKED
|
ErrLocked ErrorCode = C.GIT_ELOCKED
|
||||||
// Reference value does not match expected
|
// Reference value does not match expected
|
||||||
|
|
42
index.go
42
index.go
|
@ -12,7 +12,6 @@ import "C"
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -31,13 +30,18 @@ type Index struct {
|
||||||
ptr *C.git_index
|
ptr *C.git_index
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type IndexTime struct {
|
||||||
|
seconds int32
|
||||||
|
nanoseconds uint32
|
||||||
|
}
|
||||||
|
|
||||||
type IndexEntry struct {
|
type IndexEntry struct {
|
||||||
Ctime time.Time
|
Ctime IndexTime
|
||||||
Mtime time.Time
|
Mtime IndexTime
|
||||||
Mode Filemode
|
Mode Filemode
|
||||||
Uid uint
|
Uid uint32
|
||||||
Gid uint
|
Gid uint32
|
||||||
Size uint
|
Size uint32
|
||||||
Id *Oid
|
Id *Oid
|
||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
|
@ -47,26 +51,26 @@ func newIndexEntryFromC(entry *C.git_index_entry) *IndexEntry {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &IndexEntry{
|
return &IndexEntry{
|
||||||
time.Unix(int64(entry.ctime.seconds), int64(entry.ctime.nanoseconds)),
|
IndexTime { int32(entry.ctime.seconds), uint32(entry.ctime.nanoseconds) },
|
||||||
time.Unix(int64(entry.mtime.seconds), int64(entry.mtime.nanoseconds)),
|
IndexTime { int32(entry.mtime.seconds), uint32(entry.mtime.nanoseconds) },
|
||||||
Filemode(entry.mode),
|
Filemode(entry.mode),
|
||||||
uint(entry.uid),
|
uint32(entry.uid),
|
||||||
uint(entry.gid),
|
uint32(entry.gid),
|
||||||
uint(entry.file_size),
|
uint32(entry.file_size),
|
||||||
newOidFromC(&entry.id),
|
newOidFromC(&entry.id),
|
||||||
C.GoString(entry.path),
|
C.GoString(entry.path),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateCIndexEntry(source *IndexEntry, dest *C.git_index_entry) {
|
func populateCIndexEntry(source *IndexEntry, dest *C.git_index_entry) {
|
||||||
dest.ctime.seconds = C.git_time_t(source.Ctime.Unix())
|
dest.ctime.seconds = C.int32_t(source.Ctime.seconds)
|
||||||
dest.ctime.nanoseconds = C.uint(source.Ctime.UnixNano())
|
dest.ctime.nanoseconds = C.uint32_t(source.Ctime.nanoseconds)
|
||||||
dest.mtime.seconds = C.git_time_t(source.Mtime.Unix())
|
dest.mtime.seconds = C.int32_t(source.Mtime.seconds)
|
||||||
dest.mtime.nanoseconds = C.uint(source.Mtime.UnixNano())
|
dest.mtime.nanoseconds = C.uint32_t(source.Mtime.nanoseconds)
|
||||||
dest.mode = C.uint(source.Mode)
|
dest.mode = C.uint32_t(source.Mode)
|
||||||
dest.uid = C.uint(source.Uid)
|
dest.uid = C.uint32_t(source.Uid)
|
||||||
dest.gid = C.uint(source.Gid)
|
dest.gid = C.uint32_t(source.Gid)
|
||||||
dest.file_size = C.git_off_t(source.Size)
|
dest.file_size = C.uint32_t(source.Size)
|
||||||
dest.id = *source.Id.toC()
|
dest.id = *source.Id.toC()
|
||||||
dest.path = C.CString(source.Path)
|
dest.path = C.CString(source.Path)
|
||||||
}
|
}
|
||||||
|
|
8
odb.go
8
odb.go
|
@ -11,6 +11,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Odb struct {
|
type Odb struct {
|
||||||
|
@ -106,7 +107,9 @@ func odbForEachCb(id *C.git_oid, handle unsafe.Pointer) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
err := data.callback(newOidFromC(id))
|
err := data.callback(newOidFromC(id))
|
||||||
|
fmt.Println("err %v", err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println("returning EUSER")
|
||||||
data.err = err
|
data.err = err
|
||||||
return C.GIT_EUSER
|
return C.GIT_EUSER
|
||||||
}
|
}
|
||||||
|
@ -127,6 +130,7 @@ func (v *Odb) ForEach(callback OdbForEachCallback) error {
|
||||||
defer pointerHandles.Untrack(handle)
|
defer pointerHandles.Untrack(handle)
|
||||||
|
|
||||||
ret := C._go_git_odb_foreach(v.ptr, handle)
|
ret := C._go_git_odb_foreach(v.ptr, handle)
|
||||||
|
fmt.Println("ret %v", ret);
|
||||||
if ret == C.GIT_EUSER {
|
if ret == C.GIT_EUSER {
|
||||||
return data.err
|
return data.err
|
||||||
} else if ret < 0 {
|
} else if ret < 0 {
|
||||||
|
@ -172,13 +176,13 @@ func (v *Odb) NewReadStream(id *Oid) (*OdbReadStream, error) {
|
||||||
// NewWriteStream opens a write stream to the ODB, which allows you to
|
// NewWriteStream opens a write stream to the ODB, which allows you to
|
||||||
// create a new object in the database. The size and type must be
|
// create a new object in the database. The size and type must be
|
||||||
// known in advance
|
// known in advance
|
||||||
func (v *Odb) NewWriteStream(size int, otype ObjectType) (*OdbWriteStream, error) {
|
func (v *Odb) NewWriteStream(size int64, otype ObjectType) (*OdbWriteStream, error) {
|
||||||
stream := new(OdbWriteStream)
|
stream := new(OdbWriteStream)
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ret := C.git_odb_open_wstream(&stream.ptr, v.ptr, C.size_t(size), C.git_otype(otype))
|
ret := C.git_odb_open_wstream(&stream.ptr, v.ptr, C.git_off_t(size), C.git_otype(otype))
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ func TestOdbStream(t *testing.T) {
|
||||||
|
|
||||||
str := "hello, world!"
|
str := "hello, world!"
|
||||||
|
|
||||||
stream, error := odb.NewWriteStream(len(str), ObjectBlob)
|
stream, error := odb.NewWriteStream(int64(len(str)), ObjectBlob)
|
||||||
checkFatal(t, error)
|
checkFatal(t, error)
|
||||||
n, error := io.WriteString(stream, str)
|
n, error := io.WriteString(stream, str)
|
||||||
checkFatal(t, error)
|
checkFatal(t, error)
|
||||||
|
|
184
remote.go
184
remote.go
|
@ -69,6 +69,51 @@ type RemoteCallbacks struct {
|
||||||
PushUpdateReferenceCallback
|
PushUpdateReferenceCallback
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FetchPrune uint
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Use the setting from the configuration
|
||||||
|
FetchPruneFallback FetchPrune = C.GIT_FETCH_PRUNE_FALLBACK
|
||||||
|
// Force pruning on
|
||||||
|
FetchPruneOn FetchPrune = C.GIT_FETCH_PRUNE
|
||||||
|
// Force pruning off
|
||||||
|
FetchNoPrune FetchPrune = C.GIT_FETCH_NO_PRUNE
|
||||||
|
)
|
||||||
|
|
||||||
|
type DownloadTags uint
|
||||||
|
|
||||||
|
const (
|
||||||
|
|
||||||
|
// Use the setting from the configuration.
|
||||||
|
DownloadTagsFallback DownloadTags = C.GIT_REMOTE_DOWNLOAD_TAGS_FALLBACK
|
||||||
|
// Ask the server for tags pointing to objects we're already
|
||||||
|
// downloading.
|
||||||
|
DownloadTagsAuto DownloadTags = C.GIT_REMOTE_DOWNLOAD_TAGS_AUTO
|
||||||
|
|
||||||
|
// Don't ask for any tags beyond the refspecs.
|
||||||
|
DownloadTagsNone DownloadTags = C.GIT_REMOTE_DOWNLOAD_TAGS_NONE
|
||||||
|
|
||||||
|
// Ask for the all the tags.
|
||||||
|
DownloadTagsAll DownloadTags = C.GIT_REMOTE_DOWNLOAD_TAGS_ALL
|
||||||
|
)
|
||||||
|
|
||||||
|
type FetchOptions struct {
|
||||||
|
// Callbacks to use for this fetch operation
|
||||||
|
RemoteCallbacks RemoteCallbacks
|
||||||
|
// Whether to perform a prune after the fetch
|
||||||
|
Prune FetchPrune
|
||||||
|
// Whether to write the results to FETCH_HEAD. Defaults to
|
||||||
|
// on. Leave this default in order to behave like git.
|
||||||
|
UpdateFetchhead bool
|
||||||
|
|
||||||
|
// Determines how to behave regarding tags on the remote, such
|
||||||
|
// as auto-downloading tags for objects we're downloading or
|
||||||
|
// downloading all of them.
|
||||||
|
//
|
||||||
|
// The default is to auto-follow tags.
|
||||||
|
DownloadTags DownloadTags
|
||||||
|
}
|
||||||
|
|
||||||
type Remote struct {
|
type Remote struct {
|
||||||
ptr *C.git_remote
|
ptr *C.git_remote
|
||||||
callbacks RemoteCallbacks
|
callbacks RemoteCallbacks
|
||||||
|
@ -267,23 +312,6 @@ func RemoteIsValidName(name string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Remote) SetCallbacks(callbacks *RemoteCallbacks) error {
|
|
||||||
r.callbacks = *callbacks
|
|
||||||
|
|
||||||
var ccallbacks C.git_remote_callbacks
|
|
||||||
populateRemoteCallbacks(&ccallbacks, &r.callbacks)
|
|
||||||
|
|
||||||
runtime.LockOSThread()
|
|
||||||
defer runtime.UnlockOSThread()
|
|
||||||
|
|
||||||
ecode := C.git_remote_set_callbacks(r.ptr, &ccallbacks)
|
|
||||||
if ecode < 0 {
|
|
||||||
return MakeGitError(ecode)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Remote) Free() {
|
func (r *Remote) Free() {
|
||||||
runtime.SetFinalizer(r, nil)
|
runtime.SetFinalizer(r, nil)
|
||||||
C.git_remote_free(r.ptr)
|
C.git_remote_free(r.ptr)
|
||||||
|
@ -359,18 +387,16 @@ func (repo *Repository) CreateRemoteWithFetchspec(name string, url string, fetch
|
||||||
return remote, nil
|
return remote, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *Repository) CreateAnonymousRemote(url, fetch string) (*Remote, error) {
|
func (repo *Repository) CreateAnonymousRemote(url string) (*Remote, error) {
|
||||||
remote := &Remote{}
|
remote := &Remote{}
|
||||||
|
|
||||||
curl := C.CString(url)
|
curl := C.CString(url)
|
||||||
defer C.free(unsafe.Pointer(curl))
|
defer C.free(unsafe.Pointer(curl))
|
||||||
cfetch := C.CString(fetch)
|
|
||||||
defer C.free(unsafe.Pointer(cfetch))
|
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ret := C.git_remote_create_anonymous(&remote.ptr, repo.ptr, curl, cfetch)
|
ret := C.git_remote_create_anonymous(&remote.ptr, repo.ptr, curl)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
@ -395,18 +421,6 @@ func (repo *Repository) LookupRemote(name string) (*Remote, error) {
|
||||||
return remote, nil
|
return remote, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Remote) Save() error {
|
|
||||||
|
|
||||||
runtime.LockOSThread()
|
|
||||||
defer runtime.UnlockOSThread()
|
|
||||||
|
|
||||||
ret := C.git_remote_save(o.ptr)
|
|
||||||
if ret < 0 {
|
|
||||||
return MakeGitError(ret)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *Remote) Owner() Repository {
|
func (o *Remote) Owner() Repository {
|
||||||
return Repository{C.git_remote_owner(o.ptr)}
|
return Repository{C.git_remote_owner(o.ptr)}
|
||||||
}
|
}
|
||||||
|
@ -423,42 +437,48 @@ func (o *Remote) PushUrl() string {
|
||||||
return C.GoString(C.git_remote_pushurl(o.ptr))
|
return C.GoString(C.git_remote_pushurl(o.ptr))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Remote) SetUrl(url string) error {
|
func (o *Repository) RemoteSetUrl(remote, url string) error {
|
||||||
curl := C.CString(url)
|
curl := C.CString(url)
|
||||||
defer C.free(unsafe.Pointer(curl))
|
defer C.free(unsafe.Pointer(curl))
|
||||||
|
cremote := C.CString(remote)
|
||||||
|
defer C.free(unsafe.Pointer(cremote))
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ret := C.git_remote_set_url(o.ptr, curl)
|
ret := C.git_remote_set_url(o.ptr, cremote, curl)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return MakeGitError(ret)
|
return MakeGitError(ret)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Remote) SetPushUrl(url string) error {
|
func (o *Repository) RemoteSetPushUrl(remote, url string) error {
|
||||||
curl := C.CString(url)
|
curl := C.CString(url)
|
||||||
defer C.free(unsafe.Pointer(curl))
|
defer C.free(unsafe.Pointer(curl))
|
||||||
|
cremote := C.CString(remote)
|
||||||
|
defer C.free(unsafe.Pointer(cremote))
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ret := C.git_remote_set_pushurl(o.ptr, curl)
|
ret := C.git_remote_set_pushurl(o.ptr, cremote, curl)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return MakeGitError(ret)
|
return MakeGitError(ret)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Remote) AddFetch(refspec string) error {
|
func (o *Repository) RemoteAddFetch(remote, refspec string) error {
|
||||||
crefspec := C.CString(refspec)
|
crefspec := C.CString(refspec)
|
||||||
defer C.free(unsafe.Pointer(crefspec))
|
defer C.free(unsafe.Pointer(crefspec))
|
||||||
|
cremote := C.CString(remote)
|
||||||
|
defer C.free(unsafe.Pointer(cremote))
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ret := C.git_remote_add_fetch(o.ptr, crefspec)
|
ret := C.git_remote_add_fetch(o.ptr, cremote, crefspec)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return MakeGitError(ret)
|
return MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
@ -519,30 +539,16 @@ func (o *Remote) FetchRefspecs() ([]string, error) {
|
||||||
return refspecs, nil
|
return refspecs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Remote) SetFetchRefspecs(refspecs []string) error {
|
func (o *Repository) RemoteAddPush(remote, refspec string) error {
|
||||||
crefspecs := C.git_strarray{}
|
|
||||||
crefspecs.count = C.size_t(len(refspecs))
|
|
||||||
crefspecs.strings = makeCStringsFromStrings(refspecs)
|
|
||||||
defer freeStrarray(&crefspecs)
|
|
||||||
|
|
||||||
runtime.LockOSThread()
|
|
||||||
defer runtime.UnlockOSThread()
|
|
||||||
|
|
||||||
ret := C.git_remote_set_fetch_refspecs(o.ptr, &crefspecs)
|
|
||||||
if ret < 0 {
|
|
||||||
return MakeGitError(ret)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *Remote) AddPush(refspec string) error {
|
|
||||||
crefspec := C.CString(refspec)
|
crefspec := C.CString(refspec)
|
||||||
defer C.free(unsafe.Pointer(crefspec))
|
defer C.free(unsafe.Pointer(crefspec))
|
||||||
|
cremote := C.CString(remote)
|
||||||
|
defer C.free(unsafe.Pointer(cremote))
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ret := C.git_remote_add_push(o.ptr, crefspec)
|
ret := C.git_remote_add_push(o.ptr, cremote, crefspec)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return MakeGitError(ret)
|
return MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
@ -564,43 +570,26 @@ func (o *Remote) PushRefspecs() ([]string, error) {
|
||||||
return refspecs, nil
|
return refspecs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Remote) SetPushRefspecs(refspecs []string) error {
|
|
||||||
crefspecs := C.git_strarray{}
|
|
||||||
crefspecs.count = C.size_t(len(refspecs))
|
|
||||||
crefspecs.strings = makeCStringsFromStrings(refspecs)
|
|
||||||
defer freeStrarray(&crefspecs)
|
|
||||||
|
|
||||||
runtime.LockOSThread()
|
|
||||||
defer runtime.UnlockOSThread()
|
|
||||||
|
|
||||||
ret := C.git_remote_set_push_refspecs(o.ptr, &crefspecs)
|
|
||||||
if ret < 0 {
|
|
||||||
return MakeGitError(ret)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *Remote) ClearRefspecs() {
|
|
||||||
C.git_remote_clear_refspecs(o.ptr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *Remote) RefspecCount() uint {
|
func (o *Remote) RefspecCount() uint {
|
||||||
return uint(C.git_remote_refspec_count(o.ptr))
|
return uint(C.git_remote_refspec_count(o.ptr))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Remote) SetUpdateFetchHead(val bool) {
|
func populateFetchOptions(options *C.git_fetch_options, opts *FetchOptions) {
|
||||||
C.git_remote_set_update_fetchhead(o.ptr, cbool(val))
|
C.git_fetch_init_options(options, C.GIT_FETCH_OPTIONS_VERSION)
|
||||||
}
|
if opts == nil {
|
||||||
|
return;
|
||||||
func (o *Remote) UpdateFetchHead() bool {
|
}
|
||||||
return C.git_remote_update_fetchhead(o.ptr) > 0
|
populateRemoteCallbacks(&options.callbacks, &opts.RemoteCallbacks)
|
||||||
|
options.prune = C.git_fetch_prune_t(opts.Prune)
|
||||||
|
options.update_fetchhead = cbool(opts.UpdateFetchhead)
|
||||||
|
options.download_tags = C.git_remote_autotag_option_t(opts.DownloadTags)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch performs a fetch operation. refspecs specifies which refspecs
|
// Fetch performs a fetch operation. refspecs specifies which refspecs
|
||||||
// to use for this fetch, use an empty list to use the refspecs from
|
// to use for this fetch, use an empty list to use the refspecs from
|
||||||
// the configuration; msg specifies what to use for the reflog
|
// the configuration; msg specifies what to use for the reflog
|
||||||
// entries. Leave "" to use defaults.
|
// entries. Leave "" to use defaults.
|
||||||
func (o *Remote) Fetch(refspecs []string, msg string) error {
|
func (o *Remote) Fetch(refspecs []string, opts *FetchOptions, msg string) error {
|
||||||
|
|
||||||
var cmsg *C.char = nil
|
var cmsg *C.char = nil
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
|
@ -613,29 +602,35 @@ func (o *Remote) Fetch(refspecs []string, msg string) error {
|
||||||
crefspecs.strings = makeCStringsFromStrings(refspecs)
|
crefspecs.strings = makeCStringsFromStrings(refspecs)
|
||||||
defer freeStrarray(&crefspecs)
|
defer freeStrarray(&crefspecs)
|
||||||
|
|
||||||
|
var coptions C.git_fetch_options
|
||||||
|
populateFetchOptions(&coptions, opts);
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ret := C.git_remote_fetch(o.ptr, &crefspecs, cmsg)
|
ret := C.git_remote_fetch(o.ptr, &crefspecs, &coptions, cmsg)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return MakeGitError(ret)
|
return MakeGitError(ret)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Remote) ConnectFetch() error {
|
func (o *Remote) ConnectFetch(callbacks *RemoteCallbacks) error {
|
||||||
return o.Connect(ConnectDirectionFetch)
|
return o.Connect(ConnectDirectionFetch, callbacks)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Remote) ConnectPush() error {
|
func (o *Remote) ConnectPush(callbacks *RemoteCallbacks) error {
|
||||||
return o.Connect(ConnectDirectionPush)
|
return o.Connect(ConnectDirectionPush, callbacks)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Remote) Connect(direction ConnectDirection) error {
|
func (o *Remote) Connect(direction ConnectDirection, callbacks *RemoteCallbacks) error {
|
||||||
|
var ccallbacks C.git_remote_callbacks;
|
||||||
|
populateRemoteCallbacks(&ccallbacks, callbacks)
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
if ret := C.git_remote_connect(o.ptr, C.git_direction(direction)); ret != 0 {
|
if ret := C.git_remote_connect(o.ptr, C.git_direction(direction), &ccallbacks); ret != 0 {
|
||||||
return MakeGitError(ret)
|
return MakeGitError(ret)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -713,11 +708,14 @@ func (o *Remote) PruneRefs() bool {
|
||||||
return C.git_remote_prune_refs(o.ptr) > 0
|
return C.git_remote_prune_refs(o.ptr) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Remote) Prune() error {
|
func (o *Remote) Prune(callbacks *RemoteCallbacks) error {
|
||||||
|
var ccallbacks C.git_remote_callbacks;
|
||||||
|
populateRemoteCallbacks(&ccallbacks, callbacks)
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ret := C.git_remote_prune(o.ptr)
|
ret := C.git_remote_prune(o.ptr, &ccallbacks)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return MakeGitError(ret)
|
return MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,27 +5,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRefspecs(t *testing.T) {
|
|
||||||
repo := createTestRepo(t)
|
|
||||||
defer cleanupTestRepo(t, repo)
|
|
||||||
|
|
||||||
remote, err := repo.CreateAnonymousRemote("git://foo/bar", "refs/heads/*:refs/heads/*")
|
|
||||||
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.FetchRefspecs()
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
compareStringList(t, expected, actual)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestListRemotes(t *testing.T) {
|
func TestListRemotes(t *testing.T) {
|
||||||
repo := createTestRepo(t)
|
repo := createTestRepo(t)
|
||||||
defer cleanupTestRepo(t, repo)
|
defer cleanupTestRepo(t, repo)
|
||||||
|
@ -60,15 +39,15 @@ func TestCertificateCheck(t *testing.T) {
|
||||||
remote, err := repo.CreateRemote("origin", "https://github.com/libgit2/TestGitRepository")
|
remote, err := repo.CreateRemote("origin", "https://github.com/libgit2/TestGitRepository")
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
callbacks := RemoteCallbacks{
|
options := FetchOptions {
|
||||||
|
RemoteCallbacks: RemoteCallbacks{
|
||||||
CertificateCheckCallback: func(cert *Certificate, valid bool, hostname string) ErrorCode {
|
CertificateCheckCallback: func(cert *Certificate, valid bool, hostname string) ErrorCode {
|
||||||
return assertHostname(cert, valid, hostname, t)
|
return assertHostname(cert, valid, hostname, t)
|
||||||
},
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
err = remote.SetCallbacks(&callbacks)
|
err = remote.Fetch([]string{}, &options, "")
|
||||||
checkFatal(t, err)
|
|
||||||
err = remote.Fetch([]string{}, "")
|
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +58,7 @@ func TestRemoteConnect(t *testing.T) {
|
||||||
remote, err := repo.CreateRemote("origin", "https://github.com/libgit2/TestGitRepository")
|
remote, err := repo.CreateRemote("origin", "https://github.com/libgit2/TestGitRepository")
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
err = remote.ConnectFetch()
|
err = remote.ConnectFetch(nil)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +69,7 @@ func TestRemoteLs(t *testing.T) {
|
||||||
remote, err := repo.CreateRemote("origin", "https://github.com/libgit2/TestGitRepository")
|
remote, err := repo.CreateRemote("origin", "https://github.com/libgit2/TestGitRepository")
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
err = remote.ConnectFetch()
|
err = remote.ConnectFetch(nil)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
heads, err := remote.Ls()
|
heads, err := remote.Ls()
|
||||||
|
@ -108,7 +87,7 @@ func TestRemoteLsFiltering(t *testing.T) {
|
||||||
remote, err := repo.CreateRemote("origin", "https://github.com/libgit2/TestGitRepository")
|
remote, err := repo.CreateRemote("origin", "https://github.com/libgit2/TestGitRepository")
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
err = remote.ConnectFetch()
|
err = remote.ConnectFetch(nil)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
heads, err := remote.Ls("master")
|
heads, err := remote.Ls("master")
|
||||||
|
@ -172,7 +151,7 @@ func TestRemotePrune(t *testing.T) {
|
||||||
remote, err := repo.CreateRemote("origin", remoteUrl)
|
remote, err := repo.CreateRemote("origin", remoteUrl)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
err = remote.Fetch([]string{"test-prune"}, "")
|
err = remote.Fetch([]string{"test-prune"}, nil, "")
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
_, err = repo.CreateReference("refs/remotes/origin/test-prune", head, true, "remote reference")
|
_, err = repo.CreateReference("refs/remotes/origin/test-prune", head, true, "remote reference")
|
||||||
|
@ -187,10 +166,10 @@ func TestRemotePrune(t *testing.T) {
|
||||||
rr, err := repo.LookupRemote("origin")
|
rr, err := repo.LookupRemote("origin")
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
err = rr.ConnectFetch()
|
err = rr.ConnectFetch(nil)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
err = rr.Prune()
|
err = rr.Prune(nil)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
_, err = repo.LookupReference("refs/remotes/origin/test-prune")
|
_, err = repo.LookupReference("refs/remotes/origin/test-prune")
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
// SubmoduleUpdateOptions
|
// SubmoduleUpdateOptions
|
||||||
type SubmoduleUpdateOptions struct {
|
type SubmoduleUpdateOptions struct {
|
||||||
*CheckoutOpts
|
*CheckoutOpts
|
||||||
*RemoteCallbacks
|
*FetchOptions
|
||||||
CloneCheckoutStrategy CheckoutStrategy
|
CloneCheckoutStrategy CheckoutStrategy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,7 +348,7 @@ func populateSubmoduleUpdateOptions(ptr *C.git_submodule_update_options, opts *S
|
||||||
}
|
}
|
||||||
|
|
||||||
populateCheckoutOpts(&ptr.checkout_opts, opts.CheckoutOpts)
|
populateCheckoutOpts(&ptr.checkout_opts, opts.CheckoutOpts)
|
||||||
populateRemoteCallbacks(&ptr.remote_callbacks, opts.RemoteCallbacks)
|
populateFetchOptions(&ptr.fetch_opts, opts.FetchOptions)
|
||||||
ptr.clone_checkout_strategy = C.uint(opts.CloneCheckoutStrategy)
|
ptr.clone_checkout_strategy = C.uint(opts.CloneCheckoutStrategy)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4c02d393748d0db382450871ad9ef6898a2ce360
|
Subproject commit b6011e296e4db6942d71f5a8548d1308353927ee
|
Loading…
Reference in New Issue