Add TargetDirectory field to Checkout options.
TargetDirectory field indicates a alternative checkout path to workdir.
This commit is contained in:
parent
a9d993f3d1
commit
92a1f92d91
38
checkout.go
38
checkout.go
|
@ -7,6 +7,7 @@ import "C"
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CheckoutStrategy uint
|
type CheckoutStrategy uint
|
||||||
|
@ -31,11 +32,12 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type CheckoutOpts struct {
|
type CheckoutOpts struct {
|
||||||
Strategy CheckoutStrategy // Default will be a dry run
|
Strategy CheckoutStrategy // Default will be a dry run
|
||||||
DisableFilters bool // Don't apply filters like CRLF conversion
|
DisableFilters bool // Don't apply filters like CRLF conversion
|
||||||
DirMode os.FileMode // Default is 0755
|
DirMode os.FileMode // Default is 0755
|
||||||
FileMode os.FileMode // Default is 0644 or 0755 as dictated by blob
|
FileMode os.FileMode // Default is 0644 or 0755 as dictated by blob
|
||||||
FileOpenFlags int // Default is O_CREAT | O_TRUNC | O_WRONLY
|
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 {
|
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.disable_filters = cbool(opts.DisableFilters)
|
||||||
ptr.dir_mode = C.uint(opts.DirMode.Perm())
|
ptr.dir_mode = C.uint(opts.DirMode.Perm())
|
||||||
ptr.file_mode = C.uint(opts.FileMode.Perm())
|
ptr.file_mode = C.uint(opts.FileMode.Perm())
|
||||||
|
if opts.TargetDirectory != "" {
|
||||||
|
ptr.target_directory = C.CString(opts.TargetDirectory)
|
||||||
|
}
|
||||||
return ptr
|
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
|
// Updates files in the index and the working tree to match the content of
|
||||||
// the commit pointed at by HEAD. opts may be nil.
|
// the commit pointed at by HEAD. opts may be nil.
|
||||||
func (v *Repository) CheckoutHead(opts *CheckoutOpts) error {
|
func (v *Repository) CheckoutHead(opts *CheckoutOpts) error {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
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 {
|
if ret < 0 {
|
||||||
return MakeGitError(ret)
|
return MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
@ -90,7 +104,10 @@ func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOpts) error {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
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 {
|
if ret < 0 {
|
||||||
return MakeGitError(ret)
|
return MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
@ -102,7 +119,10 @@ func (v *Repository) CheckoutTree(tree *Tree, opts *CheckoutOpts) error {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
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 {
|
if ret < 0 {
|
||||||
return MakeGitError(ret)
|
return MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
|
1
clone.go
1
clone.go
|
@ -30,6 +30,7 @@ func Clone(url string, path string, options *CloneOptions) (*Repository, error)
|
||||||
|
|
||||||
var copts C.git_clone_options
|
var copts C.git_clone_options
|
||||||
populateCloneOptions(&copts, options)
|
populateCloneOptions(&copts, options)
|
||||||
|
defer freeCheckoutOpts(&copts.checkout_opts)
|
||||||
|
|
||||||
if len(options.CheckoutBranch) != 0 {
|
if len(options.CheckoutBranch) != 0 {
|
||||||
copts.checkout_branch = C.CString(options.CheckoutBranch)
|
copts.checkout_branch = C.CString(options.CheckoutBranch)
|
||||||
|
|
1
merge.go
1
merge.go
|
@ -145,6 +145,7 @@ func (r *Repository) Merge(theirHeads []*AnnotatedCommit, mergeOptions *MergeOpt
|
||||||
|
|
||||||
cMergeOpts := mergeOptions.toC()
|
cMergeOpts := mergeOptions.toC()
|
||||||
cCheckoutOpts := checkoutOptions.toC()
|
cCheckoutOpts := checkoutOptions.toC()
|
||||||
|
defer freeCheckoutOpts(cCheckoutOpts)
|
||||||
|
|
||||||
gmerge_head_array := make([]*C.git_annotated_commit, len(theirHeads))
|
gmerge_head_array := make([]*C.git_annotated_commit, len(theirHeads))
|
||||||
for i := 0; i < len(theirHeads); i++ {
|
for i := 0; i < len(theirHeads); i++ {
|
||||||
|
|
Loading…
Reference in New Issue