summaryrefslogtreecommitdiff
path: root/checkout.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2015-03-15 01:09:11 +0100
committerCarlos Martín Nieto <[email protected]>2015-03-15 01:09:11 +0100
commit137c4fc3c838a803dddeb2855e726fc30713fdea (patch)
treecc2bbc371b93ed92d4b2f3a1abc2a62d6d578277 /checkout.go
parent063bed33a90e7d5b1ece1b6bd1aba04a69a78a28 (diff)
parent76d600f7b3633f78e5f1433c16eba4eddfdad3e0 (diff)
Merge branch 'master' into v22
Diffstat (limited to 'checkout.go')
-rw-r--r--checkout.go55
1 files changed, 44 insertions, 11 deletions
diff --git a/checkout.go b/checkout.go
index 9c7188e..6eb6098 100644
--- a/checkout.go
+++ b/checkout.go
@@ -7,6 +7,7 @@ import "C"
import (
"os"
"runtime"
+ "unsafe"
)
type CheckoutStrategy uint
@@ -19,10 +20,10 @@ const (
CheckoutAllowConflicts CheckoutStrategy = C.GIT_CHECKOUT_ALLOW_CONFLICTS // Allow checkout to make safe updates even if conflicts are found
CheckoutRemoveUntracked CheckoutStrategy = C.GIT_CHECKOUT_REMOVE_UNTRACKED // Remove untracked files not in index (that are not ignored)
CheckoutRemoveIgnored CheckoutStrategy = C.GIT_CHECKOUT_REMOVE_IGNORED // Remove ignored files not in index
- CheckotUpdateOnly CheckoutStrategy = C.GIT_CHECKOUT_UPDATE_ONLY // Only update existing files, don't create new ones
+ CheckoutUpdateOnly CheckoutStrategy = C.GIT_CHECKOUT_UPDATE_ONLY // Only update existing files, don't create new ones
CheckoutDontUpdateIndex CheckoutStrategy = C.GIT_CHECKOUT_DONT_UPDATE_INDEX // Normally checkout updates index entries as it goes; this stops that
CheckoutNoRefresh CheckoutStrategy = C.GIT_CHECKOUT_NO_REFRESH // Don't refresh index/config/etc before doing checkout
- CheckooutDisablePathspecMatch CheckoutStrategy = C.GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH // Treat pathspec as simple list of exact match file paths
+ CheckoutDisablePathspecMatch CheckoutStrategy = C.GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH // Treat pathspec as simple list of exact match file paths
CheckoutSkipUnmerged CheckoutStrategy = C.GIT_CHECKOUT_SKIP_UNMERGED // Allow checkout to skip unmerged files (NOT IMPLEMENTED)
CheckoutUserOurs CheckoutStrategy = C.GIT_CHECKOUT_USE_OURS // For unmerged files, checkout stage 2 from index (NOT IMPLEMENTED)
CheckoutUseTheirs CheckoutStrategy = C.GIT_CHECKOUT_USE_THEIRS // For unmerged files, checkout stage 3 from index (NOT IMPLEMENTED)
@@ -31,11 +32,25 @@ 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 checkoutOptionsFromC(c *C.git_checkout_options) CheckoutOpts {
+ opts := CheckoutOpts{}
+ opts.Strategy = CheckoutStrategy(c.checkout_strategy)
+ opts.DisableFilters = c.disable_filters != 0
+ opts.DirMode = os.FileMode(c.dir_mode)
+ opts.FileMode = os.FileMode(c.file_mode)
+ opts.FileOpenFlags = int(c.file_open_flags)
+ if c.target_directory != nil {
+ opts.TargetDirectory = C.GoString(c.target_directory)
+ }
+ return opts
}
func (opts *CheckoutOpts) toC() *C.git_checkout_options {
@@ -60,17 +75,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 +117,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 +132,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)
}