summaryrefslogtreecommitdiff
path: root/checkout.go
diff options
context:
space:
mode:
authorJesse Ezell <[email protected]>2014-03-20 22:02:19 -0700
committerJesse Ezell <[email protected]>2014-03-20 22:02:19 -0700
commit37964e878f70229171f94668cb96f347b798e2b2 (patch)
tree5781761e13e57edb3589844b6faa799c1158b93a /checkout.go
parentd0b334b24409ddc190a7010be0072d87df6b6bfe (diff)
parent2811845a1287d949a74b8ed80a5791fd8875002a (diff)
merge with latest
Diffstat (limited to 'checkout.go')
-rw-r--r--checkout.go47
1 files changed, 28 insertions, 19 deletions
diff --git a/checkout.go b/checkout.go
index f4c1d4e..5b72b9a 100644
--- a/checkout.go
+++ b/checkout.go
@@ -2,10 +2,6 @@ package git
/*
#include <git2.h>
-git_checkout_opts git_checkout_opts_init() {
- git_checkout_opts ret = GIT_CHECKOUT_OPTS_INIT;
- return ret;
-}
*/
import "C"
import (
@@ -42,46 +38,59 @@ type CheckoutOpts struct {
FileOpenFlags int // Default is O_CREAT | O_TRUNC | O_WRONLY
}
-// Convert the CheckoutOpts struct to the corresponding C-struct
-func populateCheckoutOpts(ptr *C.git_checkout_opts, opts *CheckoutOpts) {
- *ptr = C.git_checkout_opts_init()
+// Convert the CheckoutOpts struct to the corresponding
+// C-struct. Returns a pointer to ptr, or nil if opts is nil, in order
+// to help with what to pass.
+func populateCheckoutOpts(ptr *C.git_checkout_options, opts *CheckoutOpts) *C.git_checkout_options {
if opts == nil {
- return
+ return nil
}
+
+ C.git_checkout_init_opts(ptr, 1)
ptr.checkout_strategy = C.uint(opts.Strategy)
ptr.disable_filters = cbool(opts.DisableFilters)
ptr.dir_mode = C.uint(opts.DirMode.Perm())
ptr.file_mode = C.uint(opts.FileMode.Perm())
+
+ return ptr
}
// Updates files in the index and the working tree to match the content of
-// the commit pointed at by HEAD.
-func (v *Repository) Checkout(opts *CheckoutOpts) error {
- var copts C.git_checkout_opts
- populateCheckoutOpts(&copts, opts)
+// the commit pointed at by HEAD. opts may be nil.
+func (v *Repository) CheckoutHead(opts *CheckoutOpts) error {
+ var copts C.git_checkout_options
+
+ ptr := populateCheckoutOpts(&copts, opts)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
- ret := C.git_checkout_head(v.ptr, &copts)
+ ret := C.git_checkout_head(v.ptr, ptr)
if ret < 0 {
- return LastError()
+ return MakeGitError(ret)
}
return nil
}
-// Updates files in the working tree to match the content of the index.
+// Updates files in the working tree to match the content of the given
+// index. If index is nil, the repository's index will be used. opts
+// may be nil.
func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOpts) error {
- var copts C.git_checkout_opts
- populateCheckoutOpts(&copts, opts)
+ var copts C.git_checkout_options
+ ptr := populateCheckoutOpts(&copts, opts)
+
+ var iptr *C.git_index = nil
+ if index != nil {
+ iptr = index.ptr
+ }
runtime.LockOSThread()
defer runtime.UnlockOSThread()
- ret := C.git_checkout_index(v.ptr, index.ptr, &copts)
+ ret := C.git_checkout_index(v.ptr, iptr, ptr)
if ret < 0 {
- return LastError()
+ return MakeGitError(ret)
}
return nil