From 9b914e07cc314daa42e61807b23350b2571f643f Mon Sep 17 00:00:00 2001 From: David Calavera Date: Thu, 8 Jan 2015 13:44:58 -0800 Subject: Add Submodule.Update method. Update libgit2 to a version that includes https://github.com/libgit2/libgit2/pull/2804. --- submodule.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'submodule.go') diff --git a/submodule.go b/submodule.go index bb86a0a..67e4fab 100644 --- a/submodule.go +++ b/submodule.go @@ -316,3 +316,33 @@ func (repo *Repository) ReloadAllSubmodules(force bool) error { } return nil } + +func (sub *Submodule) Update(init bool, opts *SubmoduleUpdateOptions) error { + var copts C.git_submodule_update_options + populateSubmoduleUpdateOptions(&copts, opts) + + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + ret := C.git_submodule_update(sub.ptr, cbool(init), &copts) + if ret < 0 { + return MakeGitError(ret) + } + + return nil +} + +func populateSubmoduleUpdateOptions(ptr *C.git_submodule_update_options, opts *SubmoduleUpdateOptions) { + C.git_submodule_update_init_options(ptr, C.GIT_SUBMODULE_UPDATE_OPTIONS_VERSION) + + if opts == nil { + return + } + + populateCheckoutOpts(&ptr.checkout_opts, opts.CheckoutOpts) + populateRemoteCallbacks(&ptr.remote_callbacks, opts.RemoteCallbacks) + ptr.clone_checkout_strategy = C.uint(opts.CloneCheckoutStrategy) + if opts.Signature != nil { + ptr.signature = opts.Signature.toC() + } +} -- cgit v1.2.3