summaryrefslogtreecommitdiff
path: root/checkout.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2015-01-29 15:17:54 +0100
committerCarlos Martín Nieto <[email protected]>2015-01-29 15:17:54 +0100
commit2bcbe6bd2dc230539b8a909606107d65a706bd66 (patch)
treeca2678a781eeab69e95b9c433e70472e4242b4be /checkout.go
parent2b17dffc07f5bc0c79ef4eff805ac3ab1cd4d004 (diff)
parent92a1f92d912cdb5f68da8c1e5e3a4d1ebfd282db (diff)
Merge commit '92a1f92d912cdb5f68da8c1e5e3a4d1ebfd282db'
Diffstat (limited to 'checkout.go')
-rw-r--r--checkout.go38
1 files changed, 29 insertions, 9 deletions
diff --git a/checkout.go b/checkout.go
index 9c7188e..06d010c 100644
--- a/checkout.go
+++ b/checkout.go
@@ -7,6 +7,7 @@ import "C"
import (
"os"
"runtime"
+ "unsafe"
)
type CheckoutStrategy uint
@@ -31,11 +32,12 @@ const (
)
type CheckoutOpts struct {
- Strategy CheckoutStrategy // Default will be a dry run
- DisableFilters bool // Don't apply filters like CRLF conversion
- DirMode os.FileMode // Default is 0755
- FileMode os.FileMode // Default is 0644 or 0755 as dictated by blob
- FileOpenFlags int // Default is O_CREAT | O_TRUNC | O_WRONLY
+ Strategy CheckoutStrategy // Default will be a dry run
+ DisableFilters bool // Don't apply filters like CRLF conversion
+ DirMode os.FileMode // Default is 0755
+ FileMode os.FileMode // Default is 0644 or 0755 as dictated by blob
+ FileOpenFlags int // Default is O_CREAT | O_TRUNC | O_WRONLY
+ TargetDirectory string // Alternative checkout path to workdir
}
func (opts *CheckoutOpts) toC() *C.git_checkout_options {
@@ -60,17 +62,29 @@ func populateCheckoutOpts(ptr *C.git_checkout_options, opts *CheckoutOpts) *C.gi
ptr.disable_filters = cbool(opts.DisableFilters)
ptr.dir_mode = C.uint(opts.DirMode.Perm())
ptr.file_mode = C.uint(opts.FileMode.Perm())
-
+ if opts.TargetDirectory != "" {
+ ptr.target_directory = C.CString(opts.TargetDirectory)
+ }
return ptr
}
+func freeCheckoutOpts(ptr *C.git_checkout_options) {
+ if ptr == nil {
+ return
+ }
+ C.free(unsafe.Pointer(ptr.target_directory))
+}
+
// 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 {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
- ret := C.git_checkout_head(v.ptr, opts.toC())
+ cOpts := opts.toC()
+ defer freeCheckoutOpts(cOpts)
+
+ ret := C.git_checkout_head(v.ptr, cOpts)
if ret < 0 {
return MakeGitError(ret)
}
@@ -90,7 +104,10 @@ func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOpts) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
- ret := C.git_checkout_index(v.ptr, iptr, opts.toC())
+ cOpts := opts.toC()
+ defer freeCheckoutOpts(cOpts)
+
+ ret := C.git_checkout_index(v.ptr, iptr, cOpts)
if ret < 0 {
return MakeGitError(ret)
}
@@ -102,7 +119,10 @@ 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())
+ cOpts := opts.toC()
+ defer freeCheckoutOpts(cOpts)
+
+ ret := C.git_checkout_tree(v.ptr, tree.ptr, cOpts)
if ret < 0 {
return MakeGitError(ret)
}