summaryrefslogtreecommitdiff
path: root/checkout.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2014-09-04 16:02:21 +0200
committerCarlos Martín Nieto <[email protected]>2014-09-04 16:02:21 +0200
commitdb113288b356835821a751e645b87def6b03fc4a (patch)
tree37ca727b655ce66362d8c5e8e7b0711002184f16 /checkout.go
parentcea203d01c62819beb9fab8ea8c4cd4aad152cc5 (diff)
parent2f93ce39cc245ab77555ba5206003816fc6aa37a (diff)
Merge pull request #113 from CMGS/master
enhance checkout, add CheckoutTree method
Diffstat (limited to 'checkout.go')
-rw-r--r--checkout.go23
1 files changed, 14 insertions, 9 deletions
diff --git a/checkout.go b/checkout.go
index 8974a8c..633303d 100644
--- a/checkout.go
+++ b/checkout.go
@@ -67,14 +67,10 @@ func populateCheckoutOpts(ptr *C.git_checkout_options, opts *CheckoutOpts) *C.gi
// Updates files in the index and the working tree to match the content of
// 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, ptr)
+ ret := C.git_checkout_head(v.ptr, opts.toC())
if ret < 0 {
return MakeGitError(ret)
}
@@ -86,9 +82,6 @@ func (v *Repository) CheckoutHead(opts *CheckoutOpts) error {
// 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_options
- ptr := populateCheckoutOpts(&copts, opts)
-
var iptr *C.git_index = nil
if index != nil {
iptr = index.ptr
@@ -97,7 +90,19 @@ func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOpts) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
- ret := C.git_checkout_index(v.ptr, iptr, ptr)
+ ret := C.git_checkout_index(v.ptr, iptr, opts.toC())
+ if ret < 0 {
+ return MakeGitError(ret)
+ }
+
+ return nil
+}
+
+func (v *Repository) CheckoutTree(tree *Tree, opts *CheckoutOpts) error {
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ ret := C.git_checkout_tree(v.ptr, tree.ptr, opts.toC())
if ret < 0 {
return MakeGitError(ret)
}