Mark some symbols to be deprecated #minor (#698)
This change introduces the file deprecated.go, which contains any constants, functions, and types that are slated to be deprecated in the next major release. These symbols are deprecated because they refer to old spellings in pre-1.0 libgit2. This also makes the build be done with the `-DDEPRECATE_HARD` flag to avoid regressions. This, together with [gorelease](https://godoc.org/golang.org/x/exp/cmd/gorelease)[1] should make releases safer going forward. 1: More information about how that works at https://go.googlesource.com/exp/+/refs/heads/master/apidiff/README.md
This commit is contained in:
parent
1fabe95fb7
commit
137c05e802
33
blob.go
33
blob.go
|
@ -9,7 +9,6 @@ void _go_git_writestream_free(git_writestream *stream);
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
@ -68,7 +67,7 @@ func (repo *Repository) CreateBlobFromBuffer(data []byte) (*Oid, error) {
|
||||||
size = C.size_t(0)
|
size = C.size_t(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
ecode := C.git_blob_create_frombuffer(&id, repo.ptr, unsafe.Pointer(&data[0]), size)
|
ecode := C.git_blob_create_from_buffer(&id, repo.ptr, unsafe.Pointer(&data[0]), size)
|
||||||
runtime.KeepAlive(repo)
|
runtime.KeepAlive(repo)
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return nil, MakeGitError(ecode)
|
return nil, MakeGitError(ecode)
|
||||||
|
@ -76,32 +75,6 @@ func (repo *Repository) CreateBlobFromBuffer(data []byte) (*Oid, error) {
|
||||||
return newOidFromC(&id), nil
|
return newOidFromC(&id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type BlobChunkCallback func(maxLen int) ([]byte, error)
|
|
||||||
|
|
||||||
type BlobCallbackData struct {
|
|
||||||
Callback BlobChunkCallback
|
|
||||||
Error error
|
|
||||||
}
|
|
||||||
|
|
||||||
//export blobChunkCb
|
|
||||||
func blobChunkCb(buffer *C.char, maxLen C.size_t, handle unsafe.Pointer) int {
|
|
||||||
payload := pointerHandles.Get(handle)
|
|
||||||
data, ok := payload.(*BlobCallbackData)
|
|
||||||
if !ok {
|
|
||||||
panic("could not retrieve blob callback data")
|
|
||||||
}
|
|
||||||
|
|
||||||
goBuf, err := data.Callback(int(maxLen))
|
|
||||||
if err == io.EOF {
|
|
||||||
return 0
|
|
||||||
} else if err != nil {
|
|
||||||
data.Error = err
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
C.memcpy(unsafe.Pointer(buffer), unsafe.Pointer(&goBuf[0]), C.size_t(len(goBuf)))
|
|
||||||
return len(goBuf)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (repo *Repository) CreateFromStream(hintPath string) (*BlobWriteStream, error) {
|
func (repo *Repository) CreateFromStream(hintPath string) (*BlobWriteStream, error) {
|
||||||
var chintPath *C.char = nil
|
var chintPath *C.char = nil
|
||||||
var stream *C.git_writestream
|
var stream *C.git_writestream
|
||||||
|
@ -114,7 +87,7 @@ func (repo *Repository) CreateFromStream(hintPath string) (*BlobWriteStream, err
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ecode := C.git_blob_create_fromstream(&stream, repo.ptr, chintPath)
|
ecode := C.git_blob_create_from_stream(&stream, repo.ptr, chintPath)
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return nil, MakeGitError(ecode)
|
return nil, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
|
@ -166,7 +139,7 @@ func (stream *BlobWriteStream) Commit() (*Oid, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ecode := C.git_blob_create_fromstream_commit(&oid, stream.ptr)
|
ecode := C.git_blob_create_from_stream_commit(&oid, stream.ptr)
|
||||||
runtime.KeepAlive(stream)
|
runtime.KeepAlive(stream)
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return nil, MakeGitError(ecode)
|
return nil, MakeGitError(ecode)
|
||||||
|
|
|
@ -73,7 +73,7 @@ func (i *BranchIterator) ForEach(f BranchIteratorFunc) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil && IsErrorCode(err, ErrIterOver) {
|
if err != nil && IsErrorCode(err, ErrorCodeIterOver) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ func TestBranchIterator(t *testing.T) {
|
||||||
t.Fatalf("expected BranchLocal, not %v", t)
|
t.Fatalf("expected BranchLocal, not %v", t)
|
||||||
}
|
}
|
||||||
b, bt, err = i.Next()
|
b, bt, err = i.Next()
|
||||||
if !IsErrorCode(err, ErrIterOver) {
|
if !IsErrorCode(err, ErrorCodeIterOver) {
|
||||||
t.Fatal("expected iterover")
|
t.Fatal("expected iterover")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ func TestBranchIteratorEach(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err = i.ForEach(f)
|
err = i.ForEach(f)
|
||||||
if err != nil && !IsErrorCode(err, ErrIterOver) {
|
if err != nil && !IsErrorCode(err, ErrorCodeIterOver) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
49
checkout.go
49
checkout.go
|
@ -51,7 +51,7 @@ const (
|
||||||
type CheckoutNotifyCallback func(why CheckoutNotifyType, path string, baseline, target, workdir DiffFile) ErrorCode
|
type CheckoutNotifyCallback func(why CheckoutNotifyType, path string, baseline, target, workdir DiffFile) ErrorCode
|
||||||
type CheckoutProgressCallback func(path string, completed, total uint) ErrorCode
|
type CheckoutProgressCallback func(path string, completed, total uint) ErrorCode
|
||||||
|
|
||||||
type CheckoutOpts struct {
|
type CheckoutOptions 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
|
||||||
|
@ -65,19 +65,20 @@ type CheckoutOpts struct {
|
||||||
Baseline *Tree
|
Baseline *Tree
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkoutOptionsFromC(c *C.git_checkout_options) CheckoutOpts {
|
func checkoutOptionsFromC(c *C.git_checkout_options) CheckoutOptions {
|
||||||
opts := CheckoutOpts{}
|
opts := CheckoutOptions{
|
||||||
opts.Strategy = CheckoutStrategy(c.checkout_strategy)
|
Strategy: CheckoutStrategy(c.checkout_strategy),
|
||||||
opts.DisableFilters = c.disable_filters != 0
|
DisableFilters: c.disable_filters != 0,
|
||||||
opts.DirMode = os.FileMode(c.dir_mode)
|
DirMode: os.FileMode(c.dir_mode),
|
||||||
opts.FileMode = os.FileMode(c.file_mode)
|
FileMode: os.FileMode(c.file_mode),
|
||||||
opts.FileOpenFlags = int(c.file_open_flags)
|
FileOpenFlags: int(c.file_open_flags),
|
||||||
opts.NotifyFlags = CheckoutNotifyType(c.notify_flags)
|
NotifyFlags: CheckoutNotifyType(c.notify_flags),
|
||||||
|
}
|
||||||
if c.notify_payload != nil {
|
if c.notify_payload != nil {
|
||||||
opts.NotifyCallback = pointerHandles.Get(c.notify_payload).(*CheckoutOpts).NotifyCallback
|
opts.NotifyCallback = pointerHandles.Get(c.notify_payload).(*CheckoutOptions).NotifyCallback
|
||||||
}
|
}
|
||||||
if c.progress_payload != nil {
|
if c.progress_payload != nil {
|
||||||
opts.ProgressCallback = pointerHandles.Get(c.progress_payload).(*CheckoutOpts).ProgressCallback
|
opts.ProgressCallback = pointerHandles.Get(c.progress_payload).(*CheckoutOptions).ProgressCallback
|
||||||
}
|
}
|
||||||
if c.target_directory != nil {
|
if c.target_directory != nil {
|
||||||
opts.TargetDirectory = C.GoString(c.target_directory)
|
opts.TargetDirectory = C.GoString(c.target_directory)
|
||||||
|
@ -85,12 +86,12 @@ func checkoutOptionsFromC(c *C.git_checkout_options) CheckoutOpts {
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts *CheckoutOpts) toC() *C.git_checkout_options {
|
func (opts *CheckoutOptions) toC() *C.git_checkout_options {
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
c := C.git_checkout_options{}
|
c := C.git_checkout_options{}
|
||||||
populateCheckoutOpts(&c, opts)
|
populateCheckoutOptions(&c, opts)
|
||||||
return &c
|
return &c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +111,7 @@ func checkoutNotifyCallback(why C.git_checkout_notify_t, cpath *C.char, cbaselin
|
||||||
if cworkdir != nil {
|
if cworkdir != nil {
|
||||||
workdir = diffFileFromC((*C.git_diff_file)(cworkdir))
|
workdir = diffFileFromC((*C.git_diff_file)(cworkdir))
|
||||||
}
|
}
|
||||||
opts := pointerHandles.Get(data).(*CheckoutOpts)
|
opts := pointerHandles.Get(data).(*CheckoutOptions)
|
||||||
if opts.NotifyCallback == nil {
|
if opts.NotifyCallback == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -119,17 +120,17 @@ func checkoutNotifyCallback(why C.git_checkout_notify_t, cpath *C.char, cbaselin
|
||||||
|
|
||||||
//export checkoutProgressCallback
|
//export checkoutProgressCallback
|
||||||
func checkoutProgressCallback(path *C.char, completed_steps, total_steps C.size_t, data unsafe.Pointer) int {
|
func checkoutProgressCallback(path *C.char, completed_steps, total_steps C.size_t, data unsafe.Pointer) int {
|
||||||
opts := pointerHandles.Get(data).(*CheckoutOpts)
|
opts := pointerHandles.Get(data).(*CheckoutOptions)
|
||||||
if opts.ProgressCallback == nil {
|
if opts.ProgressCallback == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return int(opts.ProgressCallback(C.GoString(path), uint(completed_steps), uint(total_steps)))
|
return int(opts.ProgressCallback(C.GoString(path), uint(completed_steps), uint(total_steps)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the CheckoutOpts struct to the corresponding
|
// Convert the CheckoutOptions struct to the corresponding
|
||||||
// C-struct. Returns a pointer to ptr, or nil if opts is nil, in order
|
// C-struct. Returns a pointer to ptr, or nil if opts is nil, in order
|
||||||
// to help with what to pass.
|
// to help with what to pass.
|
||||||
func populateCheckoutOpts(ptr *C.git_checkout_options, opts *CheckoutOpts) *C.git_checkout_options {
|
func populateCheckoutOptions(ptr *C.git_checkout_options, opts *CheckoutOptions) *C.git_checkout_options {
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -165,7 +166,7 @@ func populateCheckoutOpts(ptr *C.git_checkout_options, opts *CheckoutOpts) *C.gi
|
||||||
return ptr
|
return ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
func freeCheckoutOpts(ptr *C.git_checkout_options) {
|
func freeCheckoutOptions(ptr *C.git_checkout_options) {
|
||||||
if ptr == nil {
|
if ptr == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -180,12 +181,12 @@ func freeCheckoutOpts(ptr *C.git_checkout_options) {
|
||||||
|
|
||||||
// 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 *CheckoutOptions) error {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
cOpts := opts.toC()
|
cOpts := opts.toC()
|
||||||
defer freeCheckoutOpts(cOpts)
|
defer freeCheckoutOptions(cOpts)
|
||||||
|
|
||||||
ret := C.git_checkout_head(v.ptr, cOpts)
|
ret := C.git_checkout_head(v.ptr, cOpts)
|
||||||
runtime.KeepAlive(v)
|
runtime.KeepAlive(v)
|
||||||
|
@ -199,7 +200,7 @@ func (v *Repository) CheckoutHead(opts *CheckoutOpts) error {
|
||||||
// Updates files in the working tree to match the content of the given
|
// 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
|
// index. If index is nil, the repository's index will be used. opts
|
||||||
// may be nil.
|
// may be nil.
|
||||||
func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOpts) error {
|
func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOptions) error {
|
||||||
var iptr *C.git_index = nil
|
var iptr *C.git_index = nil
|
||||||
if index != nil {
|
if index != nil {
|
||||||
iptr = index.ptr
|
iptr = index.ptr
|
||||||
|
@ -209,7 +210,7 @@ func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOpts) error {
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
cOpts := opts.toC()
|
cOpts := opts.toC()
|
||||||
defer freeCheckoutOpts(cOpts)
|
defer freeCheckoutOptions(cOpts)
|
||||||
|
|
||||||
ret := C.git_checkout_index(v.ptr, iptr, cOpts)
|
ret := C.git_checkout_index(v.ptr, iptr, cOpts)
|
||||||
runtime.KeepAlive(v)
|
runtime.KeepAlive(v)
|
||||||
|
@ -220,12 +221,12 @@ func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOpts) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Repository) CheckoutTree(tree *Tree, opts *CheckoutOpts) error {
|
func (v *Repository) CheckoutTree(tree *Tree, opts *CheckoutOptions) error {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
cOpts := opts.toC()
|
cOpts := opts.toC()
|
||||||
defer freeCheckoutOpts(cOpts)
|
defer freeCheckoutOptions(cOpts)
|
||||||
|
|
||||||
ret := C.git_checkout_tree(v.ptr, tree.ptr, cOpts)
|
ret := C.git_checkout_tree(v.ptr, tree.ptr, cOpts)
|
||||||
runtime.KeepAlive(v)
|
runtime.KeepAlive(v)
|
||||||
|
|
|
@ -12,7 +12,7 @@ type CherrypickOptions struct {
|
||||||
Version uint
|
Version uint
|
||||||
Mainline uint
|
Mainline uint
|
||||||
MergeOpts MergeOptions
|
MergeOpts MergeOptions
|
||||||
CheckoutOpts CheckoutOpts
|
CheckoutOpts CheckoutOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
func cherrypickOptionsFromC(c *C.git_cherrypick_options) CherrypickOptions {
|
func cherrypickOptionsFromC(c *C.git_cherrypick_options) CherrypickOptions {
|
||||||
|
@ -41,7 +41,7 @@ func freeCherrypickOpts(ptr *C.git_cherrypick_options) {
|
||||||
if ptr == nil {
|
if ptr == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
freeCheckoutOpts(&ptr.checkout_opts)
|
freeCheckoutOptions(&ptr.checkout_opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultCherrypickOptions() (CherrypickOptions, error) {
|
func DefaultCherrypickOptions() (CherrypickOptions, error) {
|
||||||
|
|
|
@ -11,7 +11,7 @@ func checkout(t *testing.T, repo *Repository, commit *Commit) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = repo.CheckoutTree(tree, &CheckoutOpts{Strategy: CheckoutSafe})
|
err = repo.CheckoutTree(tree, &CheckoutOptions{Strategy: CheckoutSafe})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
12
clone.go
12
clone.go
|
@ -58,19 +58,19 @@ func remoteCreateCallback(cremote unsafe.Pointer, crepo unsafe.Pointer, cname, c
|
||||||
runtime.SetFinalizer(repo, nil)
|
runtime.SetFinalizer(repo, nil)
|
||||||
|
|
||||||
if opts, ok := pointerHandles.Get(payload).(CloneOptions); ok {
|
if opts, ok := pointerHandles.Get(payload).(CloneOptions); ok {
|
||||||
remote, err := opts.RemoteCreateCallback(repo, name, url)
|
remote, errorCode := opts.RemoteCreateCallback(repo, name, url)
|
||||||
// clear finalizer as the calling C function will
|
// clear finalizer as the calling C function will
|
||||||
// free the remote itself
|
// free the remote itself
|
||||||
runtime.SetFinalizer(remote, nil)
|
runtime.SetFinalizer(remote, nil)
|
||||||
|
|
||||||
if err == ErrOk && remote != nil {
|
if errorCode == ErrorCodeOK && remote != nil {
|
||||||
cptr := (**C.git_remote)(cremote)
|
cptr := (**C.git_remote)(cremote)
|
||||||
*cptr = remote.ptr
|
*cptr = remote.ptr
|
||||||
} else if err == ErrOk && remote == nil {
|
} else if errorCode == ErrorCodeOK && remote == nil {
|
||||||
panic("no remote created by callback")
|
panic("no remote created by callback")
|
||||||
}
|
}
|
||||||
|
|
||||||
return C.int(err)
|
return C.int(errorCode)
|
||||||
} else {
|
} else {
|
||||||
panic("invalid remote create callback")
|
panic("invalid remote create callback")
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ func populateCloneOptions(ptr *C.git_clone_options, opts *CloneOptions) {
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
populateCheckoutOpts(&ptr.checkout_opts, opts.CheckoutOpts)
|
populateCheckoutOptions(&ptr.checkout_opts, opts.CheckoutOpts)
|
||||||
populateFetchOptions(&ptr.fetch_opts, opts.FetchOptions)
|
populateFetchOptions(&ptr.fetch_opts, opts.FetchOptions)
|
||||||
ptr.bare = cbool(opts.Bare)
|
ptr.bare = cbool(opts.Bare)
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ func freeCloneOptions(ptr *C.git_clone_options) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
freeCheckoutOpts(&ptr.checkout_opts)
|
freeCheckoutOptions(&ptr.checkout_opts)
|
||||||
|
|
||||||
if ptr.remote_cb_payload != nil {
|
if ptr.remote_cb_payload != nil {
|
||||||
pointerHandles.Untrack(ptr.remote_cb_payload)
|
pointerHandles.Untrack(ptr.remote_cb_payload)
|
||||||
|
|
|
@ -54,10 +54,10 @@ func TestCloneWithCallback(t *testing.T) {
|
||||||
|
|
||||||
remote, err := r.Remotes.Create(REMOTENAME, url)
|
remote, err := r.Remotes.Create(REMOTENAME, url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ErrGeneric
|
return nil, ErrorCodeGeneric
|
||||||
}
|
}
|
||||||
|
|
||||||
return remote, ErrOk
|
return remote, ErrorCodeOK
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
144
credentials.go
144
credentials.go
|
@ -2,62 +2,111 @@ package git
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
#include <git2/sys/cred.h>
|
#include <git2/credential.h>
|
||||||
|
|
||||||
git_credtype_t _go_git_cred_credtype(git_cred *cred);
|
git_credential_t _go_git_credential_credtype(git_credential *cred);
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CredType uint
|
// CredentialType is a bitmask of supported credential types.
|
||||||
|
//
|
||||||
|
// This represents the various types of authentication methods supported by the
|
||||||
|
// library.
|
||||||
|
type CredentialType uint
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CredTypeUserpassPlaintext CredType = C.GIT_CREDTYPE_USERPASS_PLAINTEXT
|
CredentialTypeUserpassPlaintext CredentialType = C.GIT_CREDENTIAL_USERPASS_PLAINTEXT
|
||||||
CredTypeSshKey CredType = C.GIT_CREDTYPE_SSH_KEY
|
CredentialTypeSSHKey CredentialType = C.GIT_CREDENTIAL_SSH_KEY
|
||||||
CredTypeSshCustom CredType = C.GIT_CREDTYPE_SSH_CUSTOM
|
CredentialTypeSSHCustom CredentialType = C.GIT_CREDENTIAL_SSH_CUSTOM
|
||||||
CredTypeDefault CredType = C.GIT_CREDTYPE_DEFAULT
|
CredentialTypeDefault CredentialType = C.GIT_CREDENTIAL_DEFAULT
|
||||||
|
CredentialTypeSSHInteractive CredentialType = C.GIT_CREDENTIAL_SSH_INTERACTIVE
|
||||||
|
CredentialTypeUsername CredentialType = C.GIT_CREDENTIAL_USERNAME
|
||||||
|
CredentialTypeSSHMemory CredentialType = C.GIT_CREDENTIAL_SSH_MEMORY
|
||||||
)
|
)
|
||||||
|
|
||||||
type Cred struct {
|
func (t CredentialType) String() string {
|
||||||
ptr *C.git_cred
|
if t == 0 {
|
||||||
|
return "CredentialType(0)"
|
||||||
|
}
|
||||||
|
|
||||||
|
var parts []string
|
||||||
|
|
||||||
|
if (t & CredentialTypeUserpassPlaintext) != 0 {
|
||||||
|
parts = append(parts, "UserpassPlaintext")
|
||||||
|
t &= ^CredentialTypeUserpassPlaintext
|
||||||
|
}
|
||||||
|
if (t & CredentialTypeSSHKey) != 0 {
|
||||||
|
parts = append(parts, "SSHKey")
|
||||||
|
t &= ^CredentialTypeSSHKey
|
||||||
|
}
|
||||||
|
if (t & CredentialTypeSSHCustom) != 0 {
|
||||||
|
parts = append(parts, "SSHCustom")
|
||||||
|
t &= ^CredentialTypeSSHCustom
|
||||||
|
}
|
||||||
|
if (t & CredentialTypeDefault) != 0 {
|
||||||
|
parts = append(parts, "Default")
|
||||||
|
t &= ^CredentialTypeDefault
|
||||||
|
}
|
||||||
|
if (t & CredentialTypeSSHInteractive) != 0 {
|
||||||
|
parts = append(parts, "SSHInteractive")
|
||||||
|
t &= ^CredentialTypeSSHInteractive
|
||||||
|
}
|
||||||
|
if (t & CredentialTypeUsername) != 0 {
|
||||||
|
parts = append(parts, "Username")
|
||||||
|
t &= ^CredentialTypeUsername
|
||||||
|
}
|
||||||
|
if (t & CredentialTypeSSHMemory) != 0 {
|
||||||
|
parts = append(parts, "SSHMemory")
|
||||||
|
t &= ^CredentialTypeSSHMemory
|
||||||
|
}
|
||||||
|
|
||||||
|
if t != 0 {
|
||||||
|
parts = append(parts, fmt.Sprintf("CredentialType(%#x)", t))
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Join(parts, "|")
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCred() *Cred {
|
type Credential struct {
|
||||||
cred := &Cred{}
|
ptr *C.git_credential
|
||||||
runtime.SetFinalizer(cred, (*Cred).Free)
|
}
|
||||||
|
|
||||||
|
func newCredential() *Credential {
|
||||||
|
cred := &Credential{}
|
||||||
|
runtime.SetFinalizer(cred, (*Credential).Free)
|
||||||
return cred
|
return cred
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Cred) HasUsername() bool {
|
func (o *Credential) HasUsername() bool {
|
||||||
if C.git_cred_has_username(o.ptr) == 1 {
|
if C.git_credential_has_username(o.ptr) == 1 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Cred) Type() CredType {
|
func (o *Credential) Type() CredentialType {
|
||||||
return (CredType)(C._go_git_cred_credtype(o.ptr))
|
return (CredentialType)(C._go_git_credential_credtype(o.ptr))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Cred) Free() {
|
func (o *Credential) Free() {
|
||||||
C.git_cred_free(o.ptr)
|
C.git_credential_free(o.ptr)
|
||||||
runtime.SetFinalizer(o, nil)
|
runtime.SetFinalizer(o, nil)
|
||||||
o.ptr = nil
|
o.ptr = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCredUserpassPlaintext(username string, password string) (*Cred, error) {
|
func NewCredentialUsername(username string) (*Credential, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
cred := newCred()
|
cred := newCredential()
|
||||||
cusername := C.CString(username)
|
cusername := C.CString(username)
|
||||||
defer C.free(unsafe.Pointer(cusername))
|
ret := C.git_credential_username_new(&cred.ptr, cusername)
|
||||||
cpassword := C.CString(password)
|
|
||||||
defer C.free(unsafe.Pointer(cpassword))
|
|
||||||
ret := C.git_cred_userpass_plaintext_new(&cred.ptr, cusername, cpassword)
|
|
||||||
if ret != 0 {
|
if ret != 0 {
|
||||||
cred.Free()
|
cred.Free()
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
|
@ -65,13 +114,30 @@ func NewCredUserpassPlaintext(username string, password string) (*Cred, error) {
|
||||||
return cred, nil
|
return cred, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCredSshKey creates new ssh credentials reading the public and private keys
|
func NewCredentialUserpassPlaintext(username string, password string) (*Credential, error) {
|
||||||
// from the file system.
|
|
||||||
func NewCredSshKey(username string, publicKeyPath string, privateKeyPath string, passphrase string) (*Cred, error) {
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
cred := newCred()
|
cred := newCredential()
|
||||||
|
cusername := C.CString(username)
|
||||||
|
defer C.free(unsafe.Pointer(cusername))
|
||||||
|
cpassword := C.CString(password)
|
||||||
|
defer C.free(unsafe.Pointer(cpassword))
|
||||||
|
ret := C.git_credential_userpass_plaintext_new(&cred.ptr, cusername, cpassword)
|
||||||
|
if ret != 0 {
|
||||||
|
cred.Free()
|
||||||
|
return nil, MakeGitError(ret)
|
||||||
|
}
|
||||||
|
return cred, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCredentialSSHKey creates new ssh credentials reading the public and private keys
|
||||||
|
// from the file system.
|
||||||
|
func NewCredentialSSHKey(username string, publicKeyPath string, privateKeyPath string, passphrase string) (*Credential, error) {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
cred := newCredential()
|
||||||
cusername := C.CString(username)
|
cusername := C.CString(username)
|
||||||
defer C.free(unsafe.Pointer(cusername))
|
defer C.free(unsafe.Pointer(cusername))
|
||||||
cpublickey := C.CString(publicKeyPath)
|
cpublickey := C.CString(publicKeyPath)
|
||||||
|
@ -80,7 +146,7 @@ func NewCredSshKey(username string, publicKeyPath string, privateKeyPath string,
|
||||||
defer C.free(unsafe.Pointer(cprivatekey))
|
defer C.free(unsafe.Pointer(cprivatekey))
|
||||||
cpassphrase := C.CString(passphrase)
|
cpassphrase := C.CString(passphrase)
|
||||||
defer C.free(unsafe.Pointer(cpassphrase))
|
defer C.free(unsafe.Pointer(cpassphrase))
|
||||||
ret := C.git_cred_ssh_key_new(&cred.ptr, cusername, cpublickey, cprivatekey, cpassphrase)
|
ret := C.git_credential_ssh_key_new(&cred.ptr, cusername, cpublickey, cprivatekey, cpassphrase)
|
||||||
if ret != 0 {
|
if ret != 0 {
|
||||||
cred.Free()
|
cred.Free()
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
|
@ -88,13 +154,13 @@ func NewCredSshKey(username string, publicKeyPath string, privateKeyPath string,
|
||||||
return cred, nil
|
return cred, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCredSshKeyFromMemory creates new ssh credentials using the publicKey and privateKey
|
// NewCredentialSSHKeyFromMemory creates new ssh credentials using the publicKey and privateKey
|
||||||
// arguments as the values for the public and private keys.
|
// arguments as the values for the public and private keys.
|
||||||
func NewCredSshKeyFromMemory(username string, publicKey string, privateKey string, passphrase string) (*Cred, error) {
|
func NewCredentialSSHKeyFromMemory(username string, publicKey string, privateKey string, passphrase string) (*Credential, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
cred := newCred()
|
cred := newCredential()
|
||||||
cusername := C.CString(username)
|
cusername := C.CString(username)
|
||||||
defer C.free(unsafe.Pointer(cusername))
|
defer C.free(unsafe.Pointer(cusername))
|
||||||
cpublickey := C.CString(publicKey)
|
cpublickey := C.CString(publicKey)
|
||||||
|
@ -103,7 +169,7 @@ func NewCredSshKeyFromMemory(username string, publicKey string, privateKey strin
|
||||||
defer C.free(unsafe.Pointer(cprivatekey))
|
defer C.free(unsafe.Pointer(cprivatekey))
|
||||||
cpassphrase := C.CString(passphrase)
|
cpassphrase := C.CString(passphrase)
|
||||||
defer C.free(unsafe.Pointer(cpassphrase))
|
defer C.free(unsafe.Pointer(cpassphrase))
|
||||||
ret := C.git_cred_ssh_key_memory_new(&cred.ptr, cusername, cpublickey, cprivatekey, cpassphrase)
|
ret := C.git_credential_ssh_key_memory_new(&cred.ptr, cusername, cpublickey, cprivatekey, cpassphrase)
|
||||||
if ret != 0 {
|
if ret != 0 {
|
||||||
cred.Free()
|
cred.Free()
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
|
@ -111,14 +177,14 @@ func NewCredSshKeyFromMemory(username string, publicKey string, privateKey strin
|
||||||
return cred, nil
|
return cred, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCredSshKeyFromAgent(username string) (*Cred, error) {
|
func NewCredentialSSHKeyFromAgent(username string) (*Credential, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
cred := newCred()
|
cred := newCredential()
|
||||||
cusername := C.CString(username)
|
cusername := C.CString(username)
|
||||||
defer C.free(unsafe.Pointer(cusername))
|
defer C.free(unsafe.Pointer(cusername))
|
||||||
ret := C.git_cred_ssh_key_from_agent(&cred.ptr, cusername)
|
ret := C.git_credential_ssh_key_from_agent(&cred.ptr, cusername)
|
||||||
if ret != 0 {
|
if ret != 0 {
|
||||||
cred.Free()
|
cred.Free()
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
|
@ -126,12 +192,12 @@ func NewCredSshKeyFromAgent(username string) (*Cred, error) {
|
||||||
return cred, nil
|
return cred, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCredDefault() (*Cred, error) {
|
func NewCredentialDefault() (*Credential, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
cred := newCred()
|
cred := newCredential()
|
||||||
ret := C.git_cred_default_new(&cred.ptr)
|
ret := C.git_credential_default_new(&cred.ptr)
|
||||||
if ret != 0 {
|
if ret != 0 {
|
||||||
cred.Free()
|
cred.Free()
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
|
|
|
@ -0,0 +1,184 @@
|
||||||
|
package git
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <git2.h>
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The constants, functions, and types in this files are slated for deprecation
|
||||||
|
// in the next major version.
|
||||||
|
|
||||||
|
// blob.go
|
||||||
|
|
||||||
|
// BlobChunkCallback is not used.
|
||||||
|
type BlobChunkCallback func(maxLen int) ([]byte, error)
|
||||||
|
|
||||||
|
// BlobCallbackData is not used.
|
||||||
|
type BlobCallbackData struct {
|
||||||
|
Callback BlobChunkCallback
|
||||||
|
Error error
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkout.go
|
||||||
|
|
||||||
|
// CheckoutOpts is a deprecated alias of CheckoutOptions.
|
||||||
|
type CheckoutOpts = CheckoutOptions
|
||||||
|
|
||||||
|
// credentials.go
|
||||||
|
|
||||||
|
// CredType is a deprecated alias of CredentialType
|
||||||
|
type CredType = CredentialType
|
||||||
|
|
||||||
|
const (
|
||||||
|
CredTypeUserpassPlaintext = CredentialTypeUserpassPlaintext
|
||||||
|
CredTypeSshKey = CredentialTypeSSHKey
|
||||||
|
CredTypeSshCustom = CredentialTypeSSHCustom
|
||||||
|
CredTypeDefault = CredentialTypeDefault
|
||||||
|
)
|
||||||
|
|
||||||
|
// Cred is a deprecated alias of Credential
|
||||||
|
type Cred = Credential
|
||||||
|
|
||||||
|
// NewCredUsername is a deprecated alias of NewCredentialUsername.
|
||||||
|
func NewCredUsername(username string) (*Cred, error) {
|
||||||
|
return NewCredentialUsername(username)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCredUserpassPlaintext is a deprecated alias of NewCredentialUserpassPlaintext.
|
||||||
|
func NewCredUserpassPlaintext(username string, password string) (*Cred, error) {
|
||||||
|
return NewCredentialUserpassPlaintext(username, password)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCredSshKey is a deprecated alias of NewCredentialSshKey.
|
||||||
|
func NewCredSshKey(username string, publicKeyPath string, privateKeyPath string, passphrase string) (*Cred, error) {
|
||||||
|
return NewCredentialSSHKey(username, publicKeyPath, privateKeyPath, passphrase)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCredSshKeyFromMemory is a deprecated alias of NewCredentialSSHKeyFromMemory.
|
||||||
|
func NewCredSshKeyFromMemory(username string, publicKey string, privateKey string, passphrase string) (*Cred, error) {
|
||||||
|
return NewCredentialSSHKeyFromMemory(username, publicKey, privateKey, passphrase)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCredSshKeyFromAgent is a deprecated alias of NewCredentialSSHFromAgent.
|
||||||
|
func NewCredSshKeyFromAgent(username string) (*Cred, error) {
|
||||||
|
return NewCredentialSSHKeyFromAgent(username)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCredDefault is a deprecated alias fof NewCredentialDefault.
|
||||||
|
func NewCredDefault() (*Cred, error) {
|
||||||
|
return NewCredentialDefault()
|
||||||
|
}
|
||||||
|
|
||||||
|
// features.go
|
||||||
|
|
||||||
|
const (
|
||||||
|
// FeatureHttps is a deprecated alias of FeatureHTTPS.
|
||||||
|
FeatureHttps = FeatureHTTPS
|
||||||
|
|
||||||
|
// FeatureSsh is a deprecated alias of FeatureSSH.
|
||||||
|
FeatureSsh = FeatureSSH
|
||||||
|
)
|
||||||
|
|
||||||
|
// git.go
|
||||||
|
|
||||||
|
const (
|
||||||
|
ErrClassNone = ErrorClassNone
|
||||||
|
ErrClassNoMemory = ErrorClassNoMemory
|
||||||
|
ErrClassOs = ErrorClassOS
|
||||||
|
ErrClassInvalid = ErrorClassInvalid
|
||||||
|
ErrClassReference = ErrorClassReference
|
||||||
|
ErrClassZlib = ErrorClassZlib
|
||||||
|
ErrClassRepository = ErrorClassRepository
|
||||||
|
ErrClassConfig = ErrorClassConfig
|
||||||
|
ErrClassRegex = ErrorClassRegex
|
||||||
|
ErrClassOdb = ErrorClassOdb
|
||||||
|
ErrClassIndex = ErrorClassIndex
|
||||||
|
ErrClassObject = ErrorClassObject
|
||||||
|
ErrClassNet = ErrorClassNet
|
||||||
|
ErrClassTag = ErrorClassTag
|
||||||
|
ErrClassTree = ErrorClassTree
|
||||||
|
ErrClassIndexer = ErrorClassIndexer
|
||||||
|
ErrClassSSL = ErrorClassSSL
|
||||||
|
ErrClassSubmodule = ErrorClassSubmodule
|
||||||
|
ErrClassThread = ErrorClassThread
|
||||||
|
ErrClassStash = ErrorClassStash
|
||||||
|
ErrClassCheckout = ErrorClassCheckout
|
||||||
|
ErrClassFetchHead = ErrorClassFetchHead
|
||||||
|
ErrClassMerge = ErrorClassMerge
|
||||||
|
ErrClassSsh = ErrorClassSSH
|
||||||
|
ErrClassFilter = ErrorClassFilter
|
||||||
|
ErrClassRevert = ErrorClassRevert
|
||||||
|
ErrClassCallback = ErrorClassCallback
|
||||||
|
ErrClassRebase = ErrorClassRebase
|
||||||
|
ErrClassPatch = ErrorClassPatch
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ErrOk = ErrorCodeOK
|
||||||
|
ErrGeneric = ErrorCodeGeneric
|
||||||
|
ErrNotFound = ErrorCodeNotFound
|
||||||
|
ErrExists = ErrorCodeExists
|
||||||
|
ErrAmbiguous = ErrorCodeAmbiguous
|
||||||
|
ErrAmbigious = ErrorCodeAmbiguous
|
||||||
|
ErrBuffs = ErrorCodeBuffs
|
||||||
|
ErrUser = ErrorCodeUser
|
||||||
|
ErrBareRepo = ErrorCodeBareRepo
|
||||||
|
ErrUnbornBranch = ErrorCodeUnbornBranch
|
||||||
|
ErrUnmerged = ErrorCodeUnmerged
|
||||||
|
ErrNonFastForward = ErrorCodeNonFastForward
|
||||||
|
ErrInvalidSpec = ErrorCodeInvalidSpec
|
||||||
|
ErrConflict = ErrorCodeConflict
|
||||||
|
ErrLocked = ErrorCodeLocked
|
||||||
|
ErrModified = ErrorCodeModified
|
||||||
|
ErrAuth = ErrorCodeAuth
|
||||||
|
ErrCertificate = ErrorCodeCertificate
|
||||||
|
ErrApplied = ErrorCodeApplied
|
||||||
|
ErrPeel = ErrorCodePeel
|
||||||
|
ErrEOF = ErrorCodeEOF
|
||||||
|
ErrUncommitted = ErrorCodeUncommitted
|
||||||
|
ErrDirectory = ErrorCodeDirectory
|
||||||
|
ErrMergeConflict = ErrorCodeMergeConflict
|
||||||
|
ErrPassthrough = ErrorCodePassthrough
|
||||||
|
ErrIterOver = ErrorCodeIterOver
|
||||||
|
ErrApplyFail = ErrorCodeApplyFail
|
||||||
|
)
|
||||||
|
|
||||||
|
// index.go
|
||||||
|
|
||||||
|
// IndexAddOpts is a deprecated alias of IndexAddOption.
|
||||||
|
type IndexAddOpts = IndexAddOption
|
||||||
|
|
||||||
|
// IndexStageOpts is a deprecated alias of IndexStageState.
|
||||||
|
type IndexStageOpts = IndexStageState
|
||||||
|
|
||||||
|
// submodule.go
|
||||||
|
|
||||||
|
// SubmoduleCbk is a deprecated alias of SubmoduleCallback.
|
||||||
|
type SubmoduleCbk = SubmoduleCallback
|
||||||
|
|
||||||
|
// SubmoduleVisitor is not used.
|
||||||
|
func SubmoduleVisitor(csub unsafe.Pointer, name *C.char, handle unsafe.Pointer) C.int {
|
||||||
|
sub := &Submodule{(*C.git_submodule)(csub), nil}
|
||||||
|
|
||||||
|
callback, ok := pointerHandles.Get(handle).(SubmoduleCallback)
|
||||||
|
if !ok {
|
||||||
|
panic("invalid submodule visitor callback")
|
||||||
|
}
|
||||||
|
return (C.int)(callback(sub, C.GoString(name)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// tree.go
|
||||||
|
|
||||||
|
// CallbackGitTreeWalk is not used.
|
||||||
|
func CallbackGitTreeWalk(_root *C.char, entry *C.git_tree_entry, ptr unsafe.Pointer) C.int {
|
||||||
|
root := C.GoString(_root)
|
||||||
|
|
||||||
|
if callback, ok := pointerHandles.Get(ptr).(TreeWalkCallback); ok {
|
||||||
|
return C.int(callback(root, newTreeEntry(entry)))
|
||||||
|
} else {
|
||||||
|
panic("invalid treewalk callback")
|
||||||
|
}
|
||||||
|
}
|
2
diff.go
2
diff.go
|
@ -447,7 +447,7 @@ func (diff *Diff) ToBuf(format DiffFormat) ([]byte, error) {
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return nil, MakeGitError(ecode)
|
return nil, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
defer C.git_buf_free(&diffBuf)
|
defer C.git_buf_dispose(&diffBuf)
|
||||||
|
|
||||||
return C.GoBytes(unsafe.Pointer(diffBuf.ptr), C.int(diffBuf.size)), nil
|
return C.GoBytes(unsafe.Pointer(diffBuf.ptr), C.int(diffBuf.size)), nil
|
||||||
}
|
}
|
||||||
|
|
22
diff_test.go
22
diff_test.go
|
@ -259,7 +259,7 @@ func TestApplyDiffAddfile(t *testing.T) {
|
||||||
defer diff.Free()
|
defer diff.Free()
|
||||||
|
|
||||||
t.Run("check does not apply to current tree because file exists", func(t *testing.T) {
|
t.Run("check does not apply to current tree because file exists", func(t *testing.T) {
|
||||||
err = repo.ResetToCommit(addSecondFileCommit, ResetHard, &CheckoutOpts{})
|
err = repo.ResetToCommit(addSecondFileCommit, ResetHard, &CheckoutOptions{})
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
err = repo.ApplyDiff(diff, ApplyLocationBoth, nil)
|
err = repo.ApplyDiff(diff, ApplyLocationBoth, nil)
|
||||||
|
@ -269,7 +269,7 @@ func TestApplyDiffAddfile(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("check apply to correct commit", func(t *testing.T) {
|
t.Run("check apply to correct commit", func(t *testing.T) {
|
||||||
err = repo.ResetToCommit(addFirstFileCommit, ResetHard, &CheckoutOpts{})
|
err = repo.ResetToCommit(addFirstFileCommit, ResetHard, &CheckoutOptions{})
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
err = repo.ApplyDiff(diff, ApplyLocationBoth, nil)
|
err = repo.ApplyDiff(diff, ApplyLocationBoth, nil)
|
||||||
|
@ -324,7 +324,7 @@ func TestApplyDiffAddfile(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("check convert to raw buffer and apply", func(t *testing.T) {
|
t.Run("check convert to raw buffer and apply", func(t *testing.T) {
|
||||||
err = repo.ResetToCommit(addFirstFileCommit, ResetHard, &CheckoutOpts{})
|
err = repo.ResetToCommit(addFirstFileCommit, ResetHard, &CheckoutOptions{})
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
raw, err := diff.ToBuf(DiffFormatPatch)
|
raw, err := diff.ToBuf(DiffFormatPatch)
|
||||||
|
@ -345,7 +345,7 @@ func TestApplyDiffAddfile(t *testing.T) {
|
||||||
t.Run("check apply callbacks work", func(t *testing.T) {
|
t.Run("check apply callbacks work", func(t *testing.T) {
|
||||||
// reset the state and get new default options for test
|
// reset the state and get new default options for test
|
||||||
resetAndGetOpts := func(t *testing.T) *ApplyOptions {
|
resetAndGetOpts := func(t *testing.T) *ApplyOptions {
|
||||||
err = repo.ResetToCommit(addFirstFileCommit, ResetHard, &CheckoutOpts{})
|
err = repo.ResetToCommit(addFirstFileCommit, ResetHard, &CheckoutOptions{})
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
opts, err := DefaultApplyOptions()
|
opts, err := DefaultApplyOptions()
|
||||||
|
@ -507,8 +507,8 @@ func TestApplyToTree(t *testing.T) {
|
||||||
diff: diffAC,
|
diff: diffAC,
|
||||||
error: &GitError{
|
error: &GitError{
|
||||||
Message: "hunk at line 1 did not apply",
|
Message: "hunk at line 1 did not apply",
|
||||||
Code: ErrApplyFail,
|
Code: ErrorCodeApplyFail,
|
||||||
Class: ErrClassPatch,
|
Class: ErrorClassPatch,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -531,8 +531,9 @@ func TestApplyToTree(t *testing.T) {
|
||||||
diff: diffAB,
|
diff: diffAB,
|
||||||
applyHunkCallback: func(*DiffHunk) (bool, error) { return true, errors.New("message dropped") },
|
applyHunkCallback: func(*DiffHunk) (bool, error) { return true, errors.New("message dropped") },
|
||||||
error: &GitError{
|
error: &GitError{
|
||||||
Code: ErrGeneric,
|
Message: "Generic",
|
||||||
Class: ErrClassInvalid,
|
Code: ErrorCodeGeneric,
|
||||||
|
Class: ErrorClassInvalid,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -547,8 +548,9 @@ func TestApplyToTree(t *testing.T) {
|
||||||
diff: diffAB,
|
diff: diffAB,
|
||||||
applyDeltaCallback: func(*DiffDelta) (bool, error) { return true, errors.New("message dropped") },
|
applyDeltaCallback: func(*DiffDelta) (bool, error) { return true, errors.New("message dropped") },
|
||||||
error: &GitError{
|
error: &GitError{
|
||||||
Code: ErrGeneric,
|
Message: "Generic",
|
||||||
Class: ErrClassInvalid,
|
Code: ErrorCodeGeneric,
|
||||||
|
Class: ErrorClassInvalid,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
// Code generated by "stringer -type ErrorClass -trimprefix ErrorClass -tags static"; DO NOT EDIT.
|
||||||
|
|
||||||
|
package git
|
||||||
|
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
|
func _() {
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[ErrorClassNone-0]
|
||||||
|
_ = x[ErrorClassNoMemory-1]
|
||||||
|
_ = x[ErrorClassOS-2]
|
||||||
|
_ = x[ErrorClassInvalid-3]
|
||||||
|
_ = x[ErrorClassReference-4]
|
||||||
|
_ = x[ErrorClassZlib-5]
|
||||||
|
_ = x[ErrorClassRepository-6]
|
||||||
|
_ = x[ErrorClassConfig-7]
|
||||||
|
_ = x[ErrorClassRegex-8]
|
||||||
|
_ = x[ErrorClassOdb-9]
|
||||||
|
_ = x[ErrorClassIndex-10]
|
||||||
|
_ = x[ErrorClassObject-11]
|
||||||
|
_ = x[ErrorClassNet-12]
|
||||||
|
_ = x[ErrorClassTag-13]
|
||||||
|
_ = x[ErrorClassTree-14]
|
||||||
|
_ = x[ErrorClassIndexer-15]
|
||||||
|
_ = x[ErrorClassSSL-16]
|
||||||
|
_ = x[ErrorClassSubmodule-17]
|
||||||
|
_ = x[ErrorClassThread-18]
|
||||||
|
_ = x[ErrorClassStash-19]
|
||||||
|
_ = x[ErrorClassCheckout-20]
|
||||||
|
_ = x[ErrorClassFetchHead-21]
|
||||||
|
_ = x[ErrorClassMerge-22]
|
||||||
|
_ = x[ErrorClassSSH-23]
|
||||||
|
_ = x[ErrorClassFilter-24]
|
||||||
|
_ = x[ErrorClassRevert-25]
|
||||||
|
_ = x[ErrorClassCallback-26]
|
||||||
|
_ = x[ErrorClassRebase-29]
|
||||||
|
_ = x[ErrorClassPatch-31]
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
_ErrorClass_name_0 = "NoneNoMemoryOSInvalidReferenceZlibRepositoryConfigRegexOdbIndexObjectNetTagTreeIndexerSSLSubmoduleThreadStashCheckoutFetchHeadMergeSSHFilterRevertCallback"
|
||||||
|
_ErrorClass_name_1 = "Rebase"
|
||||||
|
_ErrorClass_name_2 = "Patch"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ErrorClass_index_0 = [...]uint8{0, 4, 12, 14, 21, 30, 34, 44, 50, 55, 58, 63, 69, 72, 75, 79, 86, 89, 98, 104, 109, 117, 126, 131, 134, 140, 146, 154}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (i ErrorClass) String() string {
|
||||||
|
switch {
|
||||||
|
case 0 <= i && i <= 26:
|
||||||
|
return _ErrorClass_name_0[_ErrorClass_index_0[i]:_ErrorClass_index_0[i+1]]
|
||||||
|
case i == 29:
|
||||||
|
return _ErrorClass_name_1
|
||||||
|
case i == 31:
|
||||||
|
return _ErrorClass_name_2
|
||||||
|
default:
|
||||||
|
return "ErrorClass(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
// Code generated by "stringer -type ErrorCode -trimprefix ErrorCode -tags static"; DO NOT EDIT.
|
||||||
|
|
||||||
|
package git
|
||||||
|
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
|
func _() {
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[ErrorCodeOK-0]
|
||||||
|
_ = x[ErrorCodeGeneric - -1]
|
||||||
|
_ = x[ErrorCodeNotFound - -3]
|
||||||
|
_ = x[ErrorCodeExists - -4]
|
||||||
|
_ = x[ErrorCodeAmbiguous - -5]
|
||||||
|
_ = x[ErrorCodeBuffs - -6]
|
||||||
|
_ = x[ErrorCodeUser - -7]
|
||||||
|
_ = x[ErrorCodeBareRepo - -8]
|
||||||
|
_ = x[ErrorCodeUnbornBranch - -9]
|
||||||
|
_ = x[ErrorCodeUnmerged - -10]
|
||||||
|
_ = x[ErrorCodeNonFastForward - -11]
|
||||||
|
_ = x[ErrorCodeInvalidSpec - -12]
|
||||||
|
_ = x[ErrorCodeConflict - -13]
|
||||||
|
_ = x[ErrorCodeLocked - -14]
|
||||||
|
_ = x[ErrorCodeModified - -15]
|
||||||
|
_ = x[ErrorCodeAuth - -16]
|
||||||
|
_ = x[ErrorCodeCertificate - -17]
|
||||||
|
_ = x[ErrorCodeApplied - -18]
|
||||||
|
_ = x[ErrorCodePeel - -19]
|
||||||
|
_ = x[ErrorCodeEOF - -20]
|
||||||
|
_ = x[ErrorCodeInvalid - -21]
|
||||||
|
_ = x[ErrorCodeUncommitted - -22]
|
||||||
|
_ = x[ErrorCodeDirectory - -23]
|
||||||
|
_ = x[ErrorCodeMergeConflict - -24]
|
||||||
|
_ = x[ErrorCodePassthrough - -30]
|
||||||
|
_ = x[ErrorCodeIterOver - -31]
|
||||||
|
_ = x[ErrorCodeRetry - -32]
|
||||||
|
_ = x[ErrorCodeMismatch - -33]
|
||||||
|
_ = x[ErrorCodeIndexDirty - -34]
|
||||||
|
_ = x[ErrorCodeApplyFail - -35]
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
_ErrorCode_name_0 = "ApplyFailIndexDirtyMismatchRetryIterOverPassthrough"
|
||||||
|
_ErrorCode_name_1 = "MergeConflictDirectoryUncommittedInvalidEOFPeelAppliedCertificateAuthModifiedLockedConflictInvalidSpecNonFastForwardUnmergedUnbornBranchBareRepoUserBuffsAmbiguousExistsNotFound"
|
||||||
|
_ErrorCode_name_2 = "GenericOK"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ErrorCode_index_0 = [...]uint8{0, 9, 19, 27, 32, 40, 51}
|
||||||
|
_ErrorCode_index_1 = [...]uint8{0, 13, 22, 33, 40, 43, 47, 54, 65, 69, 77, 83, 91, 102, 116, 124, 136, 144, 148, 153, 162, 168, 176}
|
||||||
|
_ErrorCode_index_2 = [...]uint8{0, 7, 9}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (i ErrorCode) String() string {
|
||||||
|
switch {
|
||||||
|
case -35 <= i && i <= -30:
|
||||||
|
i -= -35
|
||||||
|
return _ErrorCode_name_0[_ErrorCode_index_0[i]:_ErrorCode_index_0[i+1]]
|
||||||
|
case -24 <= i && i <= -3:
|
||||||
|
i -= -24
|
||||||
|
return _ErrorCode_name_1[_ErrorCode_index_1[i]:_ErrorCode_index_1[i+1]]
|
||||||
|
case -1 <= i && i <= 0:
|
||||||
|
i -= -1
|
||||||
|
return _ErrorCode_name_2[_ErrorCode_index_2[i]:_ErrorCode_index_2[i+1]]
|
||||||
|
default:
|
||||||
|
return "ErrorCode(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,10 +12,10 @@ const (
|
||||||
FeatureThreads Feature = C.GIT_FEATURE_THREADS
|
FeatureThreads Feature = C.GIT_FEATURE_THREADS
|
||||||
|
|
||||||
// libgit2 was built with HTTPS support built-in
|
// libgit2 was built with HTTPS support built-in
|
||||||
FeatureHttps Feature = C.GIT_FEATURE_HTTPS
|
FeatureHTTPS Feature = C.GIT_FEATURE_HTTPS
|
||||||
|
|
||||||
// libgit2 was build with SSH support built-in
|
// libgit2 was build with SSH support built-in
|
||||||
FeatureSsh Feature = C.GIT_FEATURE_SSH
|
FeatureSSH Feature = C.GIT_FEATURE_SSH
|
||||||
|
|
||||||
// libgit2 was built with nanosecond support for files
|
// libgit2 was built with nanosecond support for files
|
||||||
FeatureNSec Feature = C.GIT_FEATURE_NSEC
|
FeatureNSec Feature = C.GIT_FEATURE_NSEC
|
||||||
|
|
191
git.go
191
git.go
|
@ -17,101 +17,106 @@ import (
|
||||||
type ErrorClass int
|
type ErrorClass int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrClassNone ErrorClass = C.GITERR_NONE
|
ErrorClassNone ErrorClass = C.GIT_ERROR_NONE
|
||||||
ErrClassNoMemory ErrorClass = C.GITERR_NOMEMORY
|
ErrorClassNoMemory ErrorClass = C.GIT_ERROR_NOMEMORY
|
||||||
ErrClassOs ErrorClass = C.GITERR_OS
|
ErrorClassOS ErrorClass = C.GIT_ERROR_OS
|
||||||
ErrClassInvalid ErrorClass = C.GITERR_INVALID
|
ErrorClassInvalid ErrorClass = C.GIT_ERROR_INVALID
|
||||||
ErrClassReference ErrorClass = C.GITERR_REFERENCE
|
ErrorClassReference ErrorClass = C.GIT_ERROR_REFERENCE
|
||||||
ErrClassZlib ErrorClass = C.GITERR_ZLIB
|
ErrorClassZlib ErrorClass = C.GIT_ERROR_ZLIB
|
||||||
ErrClassRepository ErrorClass = C.GITERR_REPOSITORY
|
ErrorClassRepository ErrorClass = C.GIT_ERROR_REPOSITORY
|
||||||
ErrClassConfig ErrorClass = C.GITERR_CONFIG
|
ErrorClassConfig ErrorClass = C.GIT_ERROR_CONFIG
|
||||||
ErrClassRegex ErrorClass = C.GITERR_REGEX
|
ErrorClassRegex ErrorClass = C.GIT_ERROR_REGEX
|
||||||
ErrClassOdb ErrorClass = C.GITERR_ODB
|
ErrorClassOdb ErrorClass = C.GIT_ERROR_ODB
|
||||||
ErrClassIndex ErrorClass = C.GITERR_INDEX
|
ErrorClassIndex ErrorClass = C.GIT_ERROR_INDEX
|
||||||
ErrClassObject ErrorClass = C.GITERR_OBJECT
|
ErrorClassObject ErrorClass = C.GIT_ERROR_OBJECT
|
||||||
ErrClassNet ErrorClass = C.GITERR_NET
|
ErrorClassNet ErrorClass = C.GIT_ERROR_NET
|
||||||
ErrClassTag ErrorClass = C.GITERR_TAG
|
ErrorClassTag ErrorClass = C.GIT_ERROR_TAG
|
||||||
ErrClassTree ErrorClass = C.GITERR_TREE
|
ErrorClassTree ErrorClass = C.GIT_ERROR_TREE
|
||||||
ErrClassIndexer ErrorClass = C.GITERR_INDEXER
|
ErrorClassIndexer ErrorClass = C.GIT_ERROR_INDEXER
|
||||||
ErrClassSSL ErrorClass = C.GITERR_SSL
|
ErrorClassSSL ErrorClass = C.GIT_ERROR_SSL
|
||||||
ErrClassSubmodule ErrorClass = C.GITERR_SUBMODULE
|
ErrorClassSubmodule ErrorClass = C.GIT_ERROR_SUBMODULE
|
||||||
ErrClassThread ErrorClass = C.GITERR_THREAD
|
ErrorClassThread ErrorClass = C.GIT_ERROR_THREAD
|
||||||
ErrClassStash ErrorClass = C.GITERR_STASH
|
ErrorClassStash ErrorClass = C.GIT_ERROR_STASH
|
||||||
ErrClassCheckout ErrorClass = C.GITERR_CHECKOUT
|
ErrorClassCheckout ErrorClass = C.GIT_ERROR_CHECKOUT
|
||||||
ErrClassFetchHead ErrorClass = C.GITERR_FETCHHEAD
|
ErrorClassFetchHead ErrorClass = C.GIT_ERROR_FETCHHEAD
|
||||||
ErrClassMerge ErrorClass = C.GITERR_MERGE
|
ErrorClassMerge ErrorClass = C.GIT_ERROR_MERGE
|
||||||
ErrClassSsh ErrorClass = C.GITERR_SSH
|
ErrorClassSSH ErrorClass = C.GIT_ERROR_SSH
|
||||||
ErrClassFilter ErrorClass = C.GITERR_FILTER
|
ErrorClassFilter ErrorClass = C.GIT_ERROR_FILTER
|
||||||
ErrClassRevert ErrorClass = C.GITERR_REVERT
|
ErrorClassRevert ErrorClass = C.GIT_ERROR_REVERT
|
||||||
ErrClassCallback ErrorClass = C.GITERR_CALLBACK
|
ErrorClassCallback ErrorClass = C.GIT_ERROR_CALLBACK
|
||||||
ErrClassRebase ErrorClass = C.GITERR_REBASE
|
ErrorClassRebase ErrorClass = C.GIT_ERROR_REBASE
|
||||||
ErrClassPatch ErrorClass = C.GITERR_PATCH
|
ErrorClassPatch ErrorClass = C.GIT_ERROR_PATCH
|
||||||
)
|
)
|
||||||
|
|
||||||
type ErrorCode int
|
type ErrorCode int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// ErrorCodeOK indicates that the operation completed successfully.
|
||||||
|
ErrorCodeOK ErrorCode = C.GIT_OK
|
||||||
|
|
||||||
// No error
|
// ErrorCodeGeneric represents a generic error.
|
||||||
ErrOk ErrorCode = C.GIT_OK
|
ErrorCodeGeneric ErrorCode = C.GIT_ERROR
|
||||||
|
// ErrorCodeNotFound represents that the requested object could not be found
|
||||||
|
ErrorCodeNotFound ErrorCode = C.GIT_ENOTFOUND
|
||||||
|
// ErrorCodeExists represents that the object exists preventing operation.
|
||||||
|
ErrorCodeExists ErrorCode = C.GIT_EEXISTS
|
||||||
|
// ErrorCodeAmbiguous represents that more than one object matches.
|
||||||
|
ErrorCodeAmbiguous ErrorCode = C.GIT_EAMBIGUOUS
|
||||||
|
// ErrorCodeBuffs represents that the output buffer is too short to hold data.
|
||||||
|
ErrorCodeBuffs ErrorCode = C.GIT_EBUFS
|
||||||
|
|
||||||
// Generic error
|
// ErrorCodeUser is a special error that is never generated by libgit2
|
||||||
ErrGeneric ErrorCode = C.GIT_ERROR
|
|
||||||
// Requested object could not be found
|
|
||||||
ErrNotFound ErrorCode = C.GIT_ENOTFOUND
|
|
||||||
// Object exists preventing operation
|
|
||||||
ErrExists ErrorCode = C.GIT_EEXISTS
|
|
||||||
// More than one object matches
|
|
||||||
ErrAmbiguous ErrorCode = C.GIT_EAMBIGUOUS
|
|
||||||
// (backwards compatibility misspelling)
|
|
||||||
ErrAmbigious ErrorCode = C.GIT_EAMBIGUOUS
|
|
||||||
// Output buffer too short to hold data
|
|
||||||
ErrBuffs ErrorCode = C.GIT_EBUFS
|
|
||||||
|
|
||||||
// GIT_EUSER is a special error that is never generated by libgit2
|
|
||||||
// code. You can return it from a callback (e.g to stop an iteration)
|
// code. You can return it from a callback (e.g to stop an iteration)
|
||||||
// to know that it was generated by the callback and not by libgit2.
|
// to know that it was generated by the callback and not by libgit2.
|
||||||
ErrUser ErrorCode = C.GIT_EUSER
|
ErrorCodeUser ErrorCode = C.GIT_EUSER
|
||||||
|
|
||||||
// Operation not allowed on bare repository
|
// ErrorCodeBareRepo represents that the operation not allowed on bare repository
|
||||||
ErrBareRepo ErrorCode = C.GIT_EBAREREPO
|
ErrorCodeBareRepo ErrorCode = C.GIT_EBAREREPO
|
||||||
// HEAD refers to branch with no commits
|
// ErrorCodeUnbornBranch represents that HEAD refers to branch with no commits.
|
||||||
ErrUnbornBranch ErrorCode = C.GIT_EUNBORNBRANCH
|
ErrorCodeUnbornBranch ErrorCode = C.GIT_EUNBORNBRANCH
|
||||||
// Merge in progress prevented operation
|
// ErrorCodeUnmerged represents that a merge in progress prevented operation.
|
||||||
ErrUnmerged ErrorCode = C.GIT_EUNMERGED
|
ErrorCodeUnmerged ErrorCode = C.GIT_EUNMERGED
|
||||||
// Reference was not fast-forwardable
|
// ErrorCodeNonFastForward represents that the reference was not fast-forwardable.
|
||||||
ErrNonFastForward ErrorCode = C.GIT_ENONFASTFORWARD
|
ErrorCodeNonFastForward ErrorCode = C.GIT_ENONFASTFORWARD
|
||||||
// Name/ref spec was not in a valid format
|
// ErrorCodeInvalidSpec represents that the name/ref spec was not in a valid format.
|
||||||
ErrInvalidSpec ErrorCode = C.GIT_EINVALIDSPEC
|
ErrorCodeInvalidSpec ErrorCode = C.GIT_EINVALIDSPEC
|
||||||
// Checkout conflicts prevented operation
|
// ErrorCodeConflict represents that checkout conflicts prevented operation.
|
||||||
ErrConflict ErrorCode = C.GIT_ECONFLICT
|
ErrorCodeConflict ErrorCode = C.GIT_ECONFLICT
|
||||||
// Lock file prevented operation
|
// ErrorCodeLocked represents that lock file prevented operation.
|
||||||
ErrLocked ErrorCode = C.GIT_ELOCKED
|
ErrorCodeLocked ErrorCode = C.GIT_ELOCKED
|
||||||
// Reference value does not match expected
|
// ErrorCodeModified represents that the reference value does not match expected.
|
||||||
ErrModified ErrorCode = C.GIT_EMODIFIED
|
ErrorCodeModified ErrorCode = C.GIT_EMODIFIED
|
||||||
// Authentication failed
|
// ErrorCodeAuth represents that the authentication failed.
|
||||||
ErrAuth ErrorCode = C.GIT_EAUTH
|
ErrorCodeAuth ErrorCode = C.GIT_EAUTH
|
||||||
// Server certificate is invalid
|
// ErrorCodeCertificate represents that the server certificate is invalid.
|
||||||
ErrCertificate ErrorCode = C.GIT_ECERTIFICATE
|
ErrorCodeCertificate ErrorCode = C.GIT_ECERTIFICATE
|
||||||
// Patch/merge has already been applied
|
// ErrorCodeApplied represents that the patch/merge has already been applied.
|
||||||
ErrApplied ErrorCode = C.GIT_EAPPLIED
|
ErrorCodeApplied ErrorCode = C.GIT_EAPPLIED
|
||||||
// The requested peel operation is not possible
|
// ErrorCodePeel represents that the requested peel operation is not possible.
|
||||||
ErrPeel ErrorCode = C.GIT_EPEEL
|
ErrorCodePeel ErrorCode = C.GIT_EPEEL
|
||||||
// Unexpected EOF
|
// ErrorCodeEOF represents an unexpected EOF.
|
||||||
ErrEOF ErrorCode = C.GIT_EEOF
|
ErrorCodeEOF ErrorCode = C.GIT_EEOF
|
||||||
// Uncommitted changes in index prevented operation
|
// ErrorCodeInvalid represents an invalid operation or input.
|
||||||
ErrUncommitted ErrorCode = C.GIT_EUNCOMMITTED
|
ErrorCodeInvalid ErrorCode = C.GIT_EINVALID
|
||||||
// The operation is not valid for a directory
|
// ErrorCodeUIncommitted represents that uncommitted changes in index prevented operation.
|
||||||
ErrDirectory ErrorCode = C.GIT_EDIRECTORY
|
ErrorCodeUncommitted ErrorCode = C.GIT_EUNCOMMITTED
|
||||||
// A merge conflict exists and cannot continue
|
// ErrorCodeDirectory represents that the operation is not valid for a directory.
|
||||||
ErrMergeConflict ErrorCode = C.GIT_EMERGECONFLICT
|
ErrorCodeDirectory ErrorCode = C.GIT_EDIRECTORY
|
||||||
|
// ErrorCodeMergeConflict represents that a merge conflict exists and cannot continue.
|
||||||
|
ErrorCodeMergeConflict ErrorCode = C.GIT_EMERGECONFLICT
|
||||||
|
|
||||||
// Internal only
|
// ErrorCodePassthrough represents that a user-configured callback refused to act.
|
||||||
ErrPassthrough ErrorCode = C.GIT_PASSTHROUGH
|
ErrorCodePassthrough ErrorCode = C.GIT_PASSTHROUGH
|
||||||
// Signals end of iteration with iterator
|
// ErrorCodeIterOver signals end of iteration with iterator.
|
||||||
ErrIterOver ErrorCode = C.GIT_ITEROVER
|
ErrorCodeIterOver ErrorCode = C.GIT_ITEROVER
|
||||||
// Patch application failed
|
// ErrorCodeRetry is an internal-only error code.
|
||||||
ErrApplyFail ErrorCode = C.GIT_EAPPLYFAIL
|
ErrorCodeRetry ErrorCode = C.GIT_RETRY
|
||||||
|
// ErrorCodeMismatch represents a hashsum mismatch in object.
|
||||||
|
ErrorCodeMismatch ErrorCode = C.GIT_EMISMATCH
|
||||||
|
// ErrorCodeIndexDirty represents that unsaved changes in the index would be overwritten.
|
||||||
|
ErrorCodeIndexDirty ErrorCode = C.GIT_EINDEXDIRTY
|
||||||
|
// ErrorCodeApplyFail represents that a patch application failed.
|
||||||
|
ErrorCodeApplyFail ErrorCode = C.GIT_EAPPLYFAIL
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -201,7 +206,7 @@ func NewOid(s string) (*Oid, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(slice) != 20 {
|
if len(slice) != 20 {
|
||||||
return nil, &GitError{"Invalid Oid", ErrClassNone, ErrGeneric}
|
return nil, &GitError{"Invalid Oid", ErrorClassNone, ErrGeneric}
|
||||||
}
|
}
|
||||||
|
|
||||||
copy(o[:], slice[:20])
|
copy(o[:], slice[:20])
|
||||||
|
@ -269,7 +274,6 @@ func (e GitError) Error() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsErrorClass(err error, c ErrorClass) bool {
|
func IsErrorClass(err error, c ErrorClass) bool {
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -289,20 +293,23 @@ func IsErrorCode(err error, c ErrorCode) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeGitError(errorCode C.int) error {
|
func MakeGitError(c C.int) error {
|
||||||
|
|
||||||
var errMessage string
|
var errMessage string
|
||||||
var errClass ErrorClass
|
var errClass ErrorClass
|
||||||
if errorCode != C.GIT_ITEROVER {
|
errorCode := ErrorCode(c)
|
||||||
err := C.giterr_last()
|
if errorCode != ErrorCodeIterOver {
|
||||||
|
err := C.git_error_last()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errMessage = C.GoString(err.message)
|
errMessage = C.GoString(err.message)
|
||||||
errClass = ErrorClass(err.klass)
|
errClass = ErrorClass(err.klass)
|
||||||
} else {
|
} else {
|
||||||
errClass = ErrClassInvalid
|
errClass = ErrorClassInvalid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &GitError{errMessage, errClass, ErrorCode(errorCode)}
|
if errMessage == "" {
|
||||||
|
errMessage = errorCode.String()
|
||||||
|
}
|
||||||
|
return &GitError{errMessage, errClass, errorCode}
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeGitError2(err int) error {
|
func MakeGitError2(err int) error {
|
||||||
|
|
10
git_test.go
10
git_test.go
|
@ -45,16 +45,16 @@ func createBareTestRepo(t *testing.T) *Repository {
|
||||||
return repo
|
return repo
|
||||||
}
|
}
|
||||||
|
|
||||||
// commitOpts contains any extra options for creating commits in the seed repo
|
// commitOptions contains any extra options for creating commits in the seed repo
|
||||||
type commitOpts struct {
|
type commitOptions struct {
|
||||||
CommitSigningCallback
|
CommitSigningCallback
|
||||||
}
|
}
|
||||||
|
|
||||||
func seedTestRepo(t *testing.T, repo *Repository) (*Oid, *Oid) {
|
func seedTestRepo(t *testing.T, repo *Repository) (*Oid, *Oid) {
|
||||||
return seedTestRepoOpt(t, repo, commitOpts{})
|
return seedTestRepoOpt(t, repo, commitOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func seedTestRepoOpt(t *testing.T, repo *Repository, opts commitOpts) (*Oid, *Oid) {
|
func seedTestRepoOpt(t *testing.T, repo *Repository, opts commitOptions) (*Oid, *Oid) {
|
||||||
loc, err := time.LoadLocation("Europe/Berlin")
|
loc, err := time.LoadLocation("Europe/Berlin")
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
sig := &Signature{
|
sig := &Signature{
|
||||||
|
@ -155,7 +155,7 @@ func TestOidZero(t *testing.T) {
|
||||||
func TestEmptyOid(t *testing.T) {
|
func TestEmptyOid(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
_, err := NewOid("")
|
_, err := NewOid("")
|
||||||
if err == nil || !IsErrorCode(err, ErrGeneric) {
|
if err == nil || !IsErrorCode(err, ErrorCodeGeneric) {
|
||||||
t.Fatal("Should have returned invalid error")
|
t.Fatal("Should have returned invalid error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
26
index.go
26
index.go
|
@ -17,31 +17,33 @@ import (
|
||||||
|
|
||||||
type IndexMatchedPathCallback func(string, string) int
|
type IndexMatchedPathCallback func(string, string) int
|
||||||
|
|
||||||
type IndexAddOpts uint
|
// IndexAddOption is a set of flags for APIs that add files matching pathspec.
|
||||||
|
type IndexAddOption uint
|
||||||
|
|
||||||
const (
|
const (
|
||||||
IndexAddDefault IndexAddOpts = C.GIT_INDEX_ADD_DEFAULT
|
IndexAddDefault IndexAddOption = C.GIT_INDEX_ADD_DEFAULT
|
||||||
IndexAddForce IndexAddOpts = C.GIT_INDEX_ADD_FORCE
|
IndexAddForce IndexAddOption = C.GIT_INDEX_ADD_FORCE
|
||||||
IndexAddDisablePathspecMatch IndexAddOpts = C.GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH
|
IndexAddDisablePathspecMatch IndexAddOption = C.GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH
|
||||||
IndexAddCheckPathspec IndexAddOpts = C.GIT_INDEX_ADD_CHECK_PATHSPEC
|
IndexAddCheckPathspec IndexAddOption = C.GIT_INDEX_ADD_CHECK_PATHSPEC
|
||||||
)
|
)
|
||||||
|
|
||||||
type IndexStageOpts int
|
// IndexStageState indicates the state of the git index.
|
||||||
|
type IndexStageState int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// IndexStageAny matches any index stage.
|
// IndexStageAny matches any index stage.
|
||||||
//
|
//
|
||||||
// Some index APIs take a stage to match; pass this value to match
|
// Some index APIs take a stage to match; pass this value to match
|
||||||
// any entry matching the path regardless of stage.
|
// any entry matching the path regardless of stage.
|
||||||
IndexStageAny IndexStageOpts = C.GIT_INDEX_STAGE_ANY
|
IndexStageAny IndexStageState = C.GIT_INDEX_STAGE_ANY
|
||||||
// IndexStageNormal is a normal staged file in the index.
|
// IndexStageNormal is a normal staged file in the index.
|
||||||
IndexStageNormal IndexStageOpts = C.GIT_INDEX_STAGE_NORMAL
|
IndexStageNormal IndexStageState = C.GIT_INDEX_STAGE_NORMAL
|
||||||
// IndexStageAncestor is the ancestor side of a conflict.
|
// IndexStageAncestor is the ancestor side of a conflict.
|
||||||
IndexStageAncestor IndexStageOpts = C.GIT_INDEX_STAGE_ANCESTOR
|
IndexStageAncestor IndexStageState = C.GIT_INDEX_STAGE_ANCESTOR
|
||||||
// IndexStageOurs is the "ours" side of a conflict.
|
// IndexStageOurs is the "ours" side of a conflict.
|
||||||
IndexStageOurs IndexStageOpts = C.GIT_INDEX_STAGE_OURS
|
IndexStageOurs IndexStageState = C.GIT_INDEX_STAGE_OURS
|
||||||
// IndexStageTheirs is the "theirs" side of a conflict.
|
// IndexStageTheirs is the "theirs" side of a conflict.
|
||||||
IndexStageTheirs IndexStageOpts = C.GIT_INDEX_STAGE_THEIRS
|
IndexStageTheirs IndexStageState = C.GIT_INDEX_STAGE_THEIRS
|
||||||
)
|
)
|
||||||
|
|
||||||
type Index struct {
|
type Index struct {
|
||||||
|
@ -219,7 +221,7 @@ func (v *Index) AddFromBuffer(entry *IndexEntry, buffer []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Index) AddAll(pathspecs []string, flags IndexAddOpts, callback IndexMatchedPathCallback) error {
|
func (v *Index) AddAll(pathspecs []string, flags IndexAddOption, callback IndexMatchedPathCallback) error {
|
||||||
cpathspecs := C.git_strarray{}
|
cpathspecs := C.git_strarray{}
|
||||||
cpathspecs.count = C.size_t(len(pathspecs))
|
cpathspecs.count = C.size_t(len(pathspecs))
|
||||||
cpathspecs.strings = makeCStringsFromStrings(pathspecs)
|
cpathspecs.strings = makeCStringsFromStrings(pathspecs)
|
||||||
|
|
|
@ -35,7 +35,7 @@ func TestIndexerOutOfOrder(t *testing.T) {
|
||||||
var finalStats TransferProgress
|
var finalStats TransferProgress
|
||||||
idx, err := NewIndexer(tmpPath, nil, func(stats TransferProgress) ErrorCode {
|
idx, err := NewIndexer(tmpPath, nil, func(stats TransferProgress) ErrorCode {
|
||||||
finalStats = stats
|
finalStats = stats
|
||||||
return ErrOk
|
return ErrorCodeOK
|
||||||
})
|
})
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
defer idx.Free()
|
defer idx.Free()
|
||||||
|
|
|
@ -53,7 +53,7 @@ func TestMempack(t *testing.T) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("object %s unexpectedly found", obj.Id().String())
|
t.Errorf("object %s unexpectedly found", obj.Id().String())
|
||||||
obj.Free()
|
obj.Free()
|
||||||
} else if !IsErrorCode(err, ErrNotFound) {
|
} else if !IsErrorCode(err, ErrorCodeNotFound) {
|
||||||
t.Errorf("unexpected error %v", err)
|
t.Errorf("unexpected error %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
8
merge.go
8
merge.go
|
@ -195,20 +195,20 @@ const (
|
||||||
MergeFileFavorUnion MergeFileFavor = C.GIT_MERGE_FILE_FAVOR_UNION
|
MergeFileFavorUnion MergeFileFavor = C.GIT_MERGE_FILE_FAVOR_UNION
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Repository) Merge(theirHeads []*AnnotatedCommit, mergeOptions *MergeOptions, checkoutOptions *CheckoutOpts) error {
|
func (r *Repository) Merge(theirHeads []*AnnotatedCommit, mergeOptions *MergeOptions, checkoutOptions *CheckoutOptions) error {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
cMergeOpts := mergeOptions.toC()
|
cMergeOpts := mergeOptions.toC()
|
||||||
cCheckoutOpts := checkoutOptions.toC()
|
cCheckoutOptions := checkoutOptions.toC()
|
||||||
defer freeCheckoutOpts(cCheckoutOpts)
|
defer freeCheckoutOptions(cCheckoutOptions)
|
||||||
|
|
||||||
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++ {
|
||||||
gmerge_head_array[i] = theirHeads[i].ptr
|
gmerge_head_array[i] = theirHeads[i].ptr
|
||||||
}
|
}
|
||||||
ptr := unsafe.Pointer(&gmerge_head_array[0])
|
ptr := unsafe.Pointer(&gmerge_head_array[0])
|
||||||
err := C.git_merge(r.ptr, (**C.git_annotated_commit)(ptr), C.size_t(len(theirHeads)), cMergeOpts, cCheckoutOpts)
|
err := C.git_merge(r.ptr, (**C.git_annotated_commit)(ptr), C.size_t(len(theirHeads)), cMergeOpts, cCheckoutOptions)
|
||||||
runtime.KeepAlive(theirHeads)
|
runtime.KeepAlive(theirHeads)
|
||||||
if err < 0 {
|
if err < 0 {
|
||||||
return MakeGitError(err)
|
return MakeGitError(err)
|
||||||
|
|
|
@ -49,7 +49,7 @@ func TestNoteIterator(t *testing.T) {
|
||||||
for {
|
for {
|
||||||
noteId, commitId, err := iter.Next()
|
noteId, commitId, err := iter.Next()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !IsErrorCode(err, ErrIterOver) {
|
if !IsErrorCode(err, ErrorCodeIterOver) {
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
|
@ -201,13 +201,13 @@ func (o *Object) Free() {
|
||||||
|
|
||||||
// Peel recursively peels an object until an object of the specified type is met.
|
// Peel recursively peels an object until an object of the specified type is met.
|
||||||
//
|
//
|
||||||
// If the query cannot be satisfied due to the object model, ErrInvalidSpec
|
// If the query cannot be satisfied due to the object model, ErrorCodeInvalidSpec
|
||||||
// will be returned (e.g. trying to peel a blob to a tree).
|
// will be returned (e.g. trying to peel a blob to a tree).
|
||||||
//
|
//
|
||||||
// If you pass ObjectAny as the target type, then the object will be peeled
|
// If you pass ObjectAny as the target type, then the object will be peeled
|
||||||
// until the type changes. A tag will be peeled until the referenced object
|
// until the type changes. A tag will be peeled until the referenced object
|
||||||
// is no longer a tag, and a commit will be peeled to a tree. Any other object
|
// is no longer a tag, and a commit will be peeled to a tree. Any other object
|
||||||
// type will return ErrInvalidSpec.
|
// type will return ErrorCodeInvalidSpec.
|
||||||
//
|
//
|
||||||
// If peeling a tag we discover an object which cannot be peeled to the target
|
// If peeling a tag we discover an object which cannot be peeled to the target
|
||||||
// type due to the object model, an error will be returned.
|
// type due to the object model, an error will be returned.
|
||||||
|
|
|
@ -153,8 +153,8 @@ func TestObjectPeel(t *testing.T) {
|
||||||
|
|
||||||
obj, err = commit.Peel(ObjectTag)
|
obj, err = commit.Peel(ObjectTag)
|
||||||
|
|
||||||
if !IsErrorCode(err, ErrInvalidSpec) {
|
if !IsErrorCode(err, ErrorCodeInvalidSpec) {
|
||||||
t.Fatalf("Wrong error when peeling a commit to a tag, expected ErrInvalidSpec, have %v", err)
|
t.Fatalf("Wrong error when peeling a commit to a tag, expected ErrorCodeInvalidSpec, have %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tree, err := repo.LookupTree(treeID)
|
tree, err := repo.LookupTree(treeID)
|
||||||
|
@ -162,8 +162,8 @@ func TestObjectPeel(t *testing.T) {
|
||||||
|
|
||||||
obj, err = tree.Peel(ObjectAny)
|
obj, err = tree.Peel(ObjectAny)
|
||||||
|
|
||||||
if !IsErrorCode(err, ErrInvalidSpec) {
|
if !IsErrorCode(err, ErrorCodeInvalidSpec) {
|
||||||
t.Fatalf("Wrong error when peeling a tree, expected ErrInvalidSpec, have %v", err)
|
t.Fatalf("Wrong error when peeling a tree, expected ErrorCodeInvalidSpec, have %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
entry := tree.EntryByName("README")
|
entry := tree.EntryByName("README")
|
||||||
|
@ -173,8 +173,8 @@ func TestObjectPeel(t *testing.T) {
|
||||||
|
|
||||||
obj, err = blob.Peel(ObjectAny)
|
obj, err = blob.Peel(ObjectAny)
|
||||||
|
|
||||||
if !IsErrorCode(err, ErrInvalidSpec) {
|
if !IsErrorCode(err, ErrorCodeInvalidSpec) {
|
||||||
t.Fatalf("Wrong error when peeling a blob, expected ErrInvalidSpec, have %v", err)
|
t.Fatalf("Wrong error when peeling a blob, expected ErrorCodeInvalidSpec, have %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tagID := createTestTag(t, repo, commit)
|
tagID := createTestTag(t, repo, commit)
|
||||||
|
|
|
@ -169,7 +169,7 @@ func TestOdbWritepack(t *testing.T) {
|
||||||
var finalStats TransferProgress
|
var finalStats TransferProgress
|
||||||
writepack, err := odb.NewWritePack(func(stats TransferProgress) ErrorCode {
|
writepack, err := odb.NewWritePack(func(stats TransferProgress) ErrorCode {
|
||||||
finalStats = stats
|
finalStats = stats
|
||||||
return ErrOk
|
return ErrorCodeOK
|
||||||
})
|
})
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
defer writepack.Free()
|
defer writepack.Free()
|
||||||
|
|
|
@ -129,7 +129,7 @@ type RebaseOptions struct {
|
||||||
InMemory int
|
InMemory int
|
||||||
RewriteNotesRef string
|
RewriteNotesRef string
|
||||||
MergeOptions MergeOptions
|
MergeOptions MergeOptions
|
||||||
CheckoutOptions CheckoutOpts
|
CheckoutOptions CheckoutOptions
|
||||||
CommitSigningCallback CommitSigningCallback
|
CommitSigningCallback CommitSigningCallback
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,12 +38,12 @@ func TestRebaseAbort(t *testing.T) {
|
||||||
seedTestRepo(t, repo)
|
seedTestRepo(t, repo)
|
||||||
|
|
||||||
// Setup a repo with 2 branches and a different tree
|
// Setup a repo with 2 branches and a different tree
|
||||||
err := setupRepoForRebase(repo, masterCommit, branchName, commitOpts{})
|
err := setupRepoForRebase(repo, masterCommit, branchName, commitOptions{})
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
// Create several commits in emile
|
// Create several commits in emile
|
||||||
for _, commit := range emileCommits {
|
for _, commit := range emileCommits {
|
||||||
_, err = commitSomething(repo, commit, commit, commitOpts{})
|
_, err = commitSomething(repo, commit, commit, commitOptions{})
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,12 +99,12 @@ func TestRebaseNoConflicts(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup a repo with 2 branches and a different tree
|
// Setup a repo with 2 branches and a different tree
|
||||||
err = setupRepoForRebase(repo, masterCommit, branchName, commitOpts{})
|
err = setupRepoForRebase(repo, masterCommit, branchName, commitOptions{})
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
// Create several commits in emile
|
// Create several commits in emile
|
||||||
for _, commit := range emileCommits {
|
for _, commit := range emileCommits {
|
||||||
_, err = commitSomething(repo, commit, commit, commitOpts{})
|
_, err = commitSomething(repo, commit, commit, commitOptions{})
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ func TestRebaseGpgSigned(t *testing.T) {
|
||||||
entity, err := openpgp.NewEntity("Namey mcnameface", "test comment", "test@example.com", nil)
|
entity, err := openpgp.NewEntity("Namey mcnameface", "test comment", "test@example.com", nil)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
opts, err := DefaultRebaseOptions()
|
rebaseOpts, err := DefaultRebaseOptions()
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
signCommitContent := func(commitContent string) (string, string, error) {
|
signCommitContent := func(commitContent string) (string, string, error) {
|
||||||
|
@ -155,9 +155,9 @@ func TestRebaseGpgSigned(t *testing.T) {
|
||||||
|
|
||||||
return cipherText.String(), "", nil
|
return cipherText.String(), "", nil
|
||||||
}
|
}
|
||||||
opts.CommitSigningCallback = signCommitContent
|
rebaseOpts.CommitSigningCallback = signCommitContent
|
||||||
|
|
||||||
commitOpts := commitOpts{
|
commitOpts := commitOptions{
|
||||||
CommitSigningCallback: signCommitContent,
|
CommitSigningCallback: signCommitContent,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ func TestRebaseGpgSigned(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rebase onto master
|
// Rebase onto master
|
||||||
rebase, err := performRebaseOnto(repo, "master", &opts)
|
rebase, err := performRebaseOnto(repo, "master", &rebaseOpts)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
defer rebase.Free()
|
defer rebase.Free()
|
||||||
|
|
||||||
|
@ -255,7 +255,7 @@ func checkCommitSigned(t *testing.T, entity *openpgp.Entity, commit *Commit) err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
func setupRepoForRebase(repo *Repository, masterCommit, branchName string, opts commitOpts) error {
|
func setupRepoForRebase(repo *Repository, masterCommit, branchName string, commitOpts commitOptions) error {
|
||||||
// Create a new branch from master
|
// Create a new branch from master
|
||||||
err := createBranch(repo, branchName)
|
err := createBranch(repo, branchName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -263,7 +263,7 @@ func setupRepoForRebase(repo *Repository, masterCommit, branchName string, opts
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a commit in master
|
// Create a commit in master
|
||||||
_, err = commitSomething(repo, masterCommit, masterCommit, opts)
|
_, err = commitSomething(repo, masterCommit, masterCommit, commitOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -282,7 +282,7 @@ func setupRepoForRebase(repo *Repository, masterCommit, branchName string, opts
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func performRebaseOnto(repo *Repository, branch string, opts *RebaseOptions) (*Rebase, error) {
|
func performRebaseOnto(repo *Repository, branch string, rebaseOpts *RebaseOptions) (*Rebase, error) {
|
||||||
master, err := repo.LookupBranch(branch, BranchLocal)
|
master, err := repo.LookupBranch(branch, BranchLocal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -296,7 +296,7 @@ func performRebaseOnto(repo *Repository, branch string, opts *RebaseOptions) (*R
|
||||||
defer onto.Free()
|
defer onto.Free()
|
||||||
|
|
||||||
// Init rebase
|
// Init rebase
|
||||||
rebase, err := repo.InitRebase(nil, nil, onto, opts)
|
rebase, err := repo.InitRebase(nil, nil, onto, rebaseOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -397,7 +397,7 @@ func headTree(repo *Repository) (*Tree, error) {
|
||||||
return tree, nil
|
return tree, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func commitSomething(repo *Repository, something, content string, commitOpts commitOpts) (*Oid, error) {
|
func commitSomething(repo *Repository, something, content string, commitOpts commitOptions) (*Oid, error) {
|
||||||
headCommit, err := headCommit(repo)
|
headCommit, err := headCommit(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -470,10 +470,10 @@ func commitSomething(repo *Repository, something, content string, commitOpts com
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := &CheckoutOpts{
|
checkoutOpts := &CheckoutOptions{
|
||||||
Strategy: CheckoutRemoveUntracked | CheckoutForce,
|
Strategy: CheckoutRemoveUntracked | CheckoutForce,
|
||||||
}
|
}
|
||||||
err = repo.CheckoutIndex(index, opts)
|
err = repo.CheckoutIndex(index, checkoutOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
12
reference.go
12
reference.go
|
@ -424,7 +424,7 @@ func (i *ReferenceIterator) Names() *ReferenceNameIterator {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NextName retrieves the next reference name. If the iteration is over,
|
// NextName retrieves the next reference name. If the iteration is over,
|
||||||
// the returned error is git.ErrIterOver
|
// the returned error code is git.ErrorCodeIterOver
|
||||||
func (v *ReferenceNameIterator) Next() (string, error) {
|
func (v *ReferenceNameIterator) Next() (string, error) {
|
||||||
var ptr *C.char
|
var ptr *C.char
|
||||||
|
|
||||||
|
@ -440,7 +440,7 @@ func (v *ReferenceNameIterator) Next() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next retrieves the next reference. If the iterationis over, the
|
// Next retrieves the next reference. If the iterationis over, the
|
||||||
// returned error is git.ErrIterOver
|
// returned error code is git.ErrorCodeIterOver
|
||||||
func (v *ReferenceIterator) Next() (*Reference, error) {
|
func (v *ReferenceIterator) Next() (*Reference, error) {
|
||||||
var ptr *C.git_reference
|
var ptr *C.git_reference
|
||||||
|
|
||||||
|
@ -470,7 +470,7 @@ func (v *ReferenceIterator) Free() {
|
||||||
C.git_reference_iterator_free(v.ptr)
|
C.git_reference_iterator_free(v.ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReferenceIsValidName ensures the reference name is well-formed.
|
// ReferenceIsValidName returns whether the reference name is well-formed.
|
||||||
//
|
//
|
||||||
// Valid reference names must follow one of two patterns:
|
// Valid reference names must follow one of two patterns:
|
||||||
//
|
//
|
||||||
|
@ -483,10 +483,8 @@ func (v *ReferenceIterator) Free() {
|
||||||
func ReferenceIsValidName(name string) bool {
|
func ReferenceIsValidName(name string) bool {
|
||||||
cname := C.CString(name)
|
cname := C.CString(name)
|
||||||
defer C.free(unsafe.Pointer(cname))
|
defer C.free(unsafe.Pointer(cname))
|
||||||
if C.git_reference_is_valid_name(cname) == 1 {
|
|
||||||
return true
|
return C.git_reference_is_valid_name(cname) == 1
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -106,7 +106,7 @@ func TestReferenceIterator(t *testing.T) {
|
||||||
list = append(list, name)
|
list = append(list, name)
|
||||||
name, err = nameIter.Next()
|
name, err = nameIter.Next()
|
||||||
}
|
}
|
||||||
if !IsErrorCode(err, ErrIterOver) {
|
if !IsErrorCode(err, ErrorCodeIterOver) {
|
||||||
t.Fatal("Iteration not over")
|
t.Fatal("Iteration not over")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ func TestReferenceIterator(t *testing.T) {
|
||||||
count++
|
count++
|
||||||
_, err = iter.Next()
|
_, err = iter.Next()
|
||||||
}
|
}
|
||||||
if !IsErrorCode(err, ErrIterOver) {
|
if !IsErrorCode(err, ErrorCodeIterOver) {
|
||||||
t.Fatal("Iteration not over")
|
t.Fatal("Iteration not over")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ func TestReferenceNormalizeName(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ref, err = ReferenceNormalizeName("foo^", ReferenceFormatNormal)
|
ref, err = ReferenceNormalizeName("foo^", ReferenceFormatNormal)
|
||||||
if !IsErrorCode(err, ErrInvalidSpec) {
|
if !IsErrorCode(err, ErrorCodeInvalidSpec) {
|
||||||
t.Errorf("foo^ should be invalid")
|
t.Errorf("foo^ should be invalid")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
21
remote.go
21
remote.go
|
@ -51,7 +51,7 @@ const (
|
||||||
|
|
||||||
type TransportMessageCallback func(str string) ErrorCode
|
type TransportMessageCallback func(str string) ErrorCode
|
||||||
type CompletionCallback func(RemoteCompletion) ErrorCode
|
type CompletionCallback func(RemoteCompletion) ErrorCode
|
||||||
type CredentialsCallback func(url string, username_from_url string, allowed_types CredType) (*Cred, error)
|
type CredentialsCallback func(url string, username_from_url string, allowed_types CredentialType) (*Credential, error)
|
||||||
type TransferProgressCallback func(stats TransferProgress) ErrorCode
|
type TransferProgressCallback func(stats TransferProgress) ErrorCode
|
||||||
type UpdateTipsCallback func(refname string, a *Oid, b *Oid) ErrorCode
|
type UpdateTipsCallback func(refname string, a *Oid, b *Oid) ErrorCode
|
||||||
type CertificateCheckCallback func(cert *Certificate, valid bool, hostname string) ErrorCode
|
type CertificateCheckCallback func(cert *Certificate, valid bool, hostname string) ErrorCode
|
||||||
|
@ -243,14 +243,14 @@ func completionCallback(completion_type C.git_remote_completion_type, data unsaf
|
||||||
}
|
}
|
||||||
|
|
||||||
//export credentialsCallback
|
//export credentialsCallback
|
||||||
func credentialsCallback(_cred **C.git_cred, _url *C.char, _username_from_url *C.char, allowed_types uint, data unsafe.Pointer) int {
|
func credentialsCallback(_cred **C.git_credential, _url *C.char, _username_from_url *C.char, allowed_types uint, data unsafe.Pointer) int {
|
||||||
callbacks, _ := pointerHandles.Get(data).(*RemoteCallbacks)
|
callbacks, _ := pointerHandles.Get(data).(*RemoteCallbacks)
|
||||||
if callbacks.CredentialsCallback == nil {
|
if callbacks.CredentialsCallback == nil {
|
||||||
return C.GIT_PASSTHROUGH
|
return C.GIT_PASSTHROUGH
|
||||||
}
|
}
|
||||||
url := C.GoString(_url)
|
url := C.GoString(_url)
|
||||||
username_from_url := C.GoString(_username_from_url)
|
username_from_url := C.GoString(_username_from_url)
|
||||||
cred, err := callbacks.CredentialsCallback(url, username_from_url, (CredType)(allowed_types))
|
cred, err := callbacks.CredentialsCallback(url, username_from_url, (CredentialType)(allowed_types))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gitError, ok := err.(*GitError); ok {
|
if gitError, ok := err.(*GitError); ok {
|
||||||
return int(gitError.Code)
|
return int(gitError.Code)
|
||||||
|
@ -322,7 +322,7 @@ func certificateCheckCallback(_cert *C.git_cert, _valid C.int, _host *C.char, da
|
||||||
C.memcpy(unsafe.Pointer(&cert.Hostkey.HashSHA256[0]), unsafe.Pointer(&ccert.hash_sha256[0]), C.size_t(len(cert.Hostkey.HashSHA256)))
|
C.memcpy(unsafe.Pointer(&cert.Hostkey.HashSHA256[0]), unsafe.Pointer(&ccert.hash_sha256[0]), C.size_t(len(cert.Hostkey.HashSHA256)))
|
||||||
} else {
|
} else {
|
||||||
cstr := C.CString("Unsupported certificate type")
|
cstr := C.CString("Unsupported certificate type")
|
||||||
C.giterr_set_str(C.GITERR_NET, cstr)
|
C.git_error_set_str(C.GITERR_NET, cstr)
|
||||||
C.free(unsafe.Pointer(cstr))
|
C.free(unsafe.Pointer(cstr))
|
||||||
return -1 // we don't support anything else atm
|
return -1 // we don't support anything else atm
|
||||||
}
|
}
|
||||||
|
@ -376,13 +376,12 @@ func freeProxyOptions(ptr *C.git_proxy_options) {
|
||||||
C.free(unsafe.Pointer(ptr.url))
|
C.free(unsafe.Pointer(ptr.url))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoteIsValidName returns whether the remote name is well-formed.
|
||||||
func RemoteIsValidName(name string) bool {
|
func RemoteIsValidName(name string) bool {
|
||||||
cname := C.CString(name)
|
cname := C.CString(name)
|
||||||
defer C.free(unsafe.Pointer(cname))
|
defer C.free(unsafe.Pointer(cname))
|
||||||
if C.git_remote_is_valid_name(cname) == 1 {
|
|
||||||
return true
|
return C.git_remote_is_valid_name(cname) == 1
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Remote) Free() {
|
func (r *Remote) Free() {
|
||||||
|
@ -406,7 +405,7 @@ func (c *RemoteCollection) List() ([]string, error) {
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return nil, MakeGitError(ecode)
|
return nil, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
defer C.git_strarray_free(&r)
|
defer C.git_strarray_dispose(&r)
|
||||||
|
|
||||||
remotes := makeStringsFromCStrings(r.strings, int(r.count))
|
remotes := makeStringsFromCStrings(r.strings, int(r.count))
|
||||||
return remotes, nil
|
return remotes, nil
|
||||||
|
@ -640,7 +639,7 @@ func (o *Remote) FetchRefspecs() ([]string, error) {
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
defer C.git_strarray_free(&crefspecs)
|
defer C.git_strarray_dispose(&crefspecs)
|
||||||
|
|
||||||
refspecs := makeStringsFromCStrings(crefspecs.strings, int(crefspecs.count))
|
refspecs := makeStringsFromCStrings(crefspecs.strings, int(crefspecs.count))
|
||||||
return refspecs, nil
|
return refspecs, nil
|
||||||
|
@ -673,7 +672,7 @@ func (o *Remote) PushRefspecs() ([]string, error) {
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
defer C.git_strarray_free(&crefspecs)
|
defer C.git_strarray_dispose(&crefspecs)
|
||||||
runtime.KeepAlive(o)
|
runtime.KeepAlive(o)
|
||||||
|
|
||||||
refspecs := makeStringsFromCStrings(crefspecs.strings, int(crefspecs.count))
|
refspecs := makeStringsFromCStrings(crefspecs.strings, int(crefspecs.count))
|
||||||
|
|
|
@ -27,7 +27,7 @@ func TestListRemotes(t *testing.T) {
|
||||||
func assertHostname(cert *Certificate, valid bool, hostname string, t *testing.T) ErrorCode {
|
func assertHostname(cert *Certificate, valid bool, hostname string, t *testing.T) ErrorCode {
|
||||||
if hostname != "github.com" {
|
if hostname != "github.com" {
|
||||||
t.Fatal("Hostname does not match")
|
t.Fatal("Hostname does not match")
|
||||||
return ErrUser
|
return ErrorCodeUser
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
2
reset.go
2
reset.go
|
@ -14,7 +14,7 @@ const (
|
||||||
ResetHard ResetType = C.GIT_RESET_HARD
|
ResetHard ResetType = C.GIT_RESET_HARD
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Repository) ResetToCommit(commit *Commit, resetType ResetType, opts *CheckoutOpts) error {
|
func (r *Repository) ResetToCommit(commit *Commit, resetType ResetType, opts *CheckoutOptions) error {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
ret := C.git_reset(r.ptr, commit.ptr, C.git_reset_t(resetType), opts.toC())
|
ret := C.git_reset(r.ptr, commit.ptr, C.git_reset_t(resetType), opts.toC())
|
||||||
|
|
|
@ -37,7 +37,7 @@ func TestResetToCommit(t *testing.T) {
|
||||||
commitToResetTo, err := repo.LookupCommit(commitId)
|
commitToResetTo, err := repo.LookupCommit(commitId)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
repo.ResetToCommit(commitToResetTo, ResetHard, &CheckoutOpts{})
|
repo.ResetToCommit(commitToResetTo, ResetHard, &CheckoutOptions{})
|
||||||
|
|
||||||
// check that the file now reads "testing reset" like it did before
|
// check that the file now reads "testing reset" like it did before
|
||||||
bytes, err := ioutil.ReadFile(pathInRepo(repo, "README"))
|
bytes, err := ioutil.ReadFile(pathInRepo(repo, "README"))
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
type RevertOptions struct {
|
type RevertOptions struct {
|
||||||
Mainline uint
|
Mainline uint
|
||||||
MergeOpts MergeOptions
|
MergeOpts MergeOptions
|
||||||
CheckoutOpts CheckoutOpts
|
CheckoutOpts CheckoutOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts *RevertOptions) toC() *C.git_revert_options {
|
func (opts *RevertOptions) toC() *C.git_revert_options {
|
||||||
|
@ -33,7 +33,7 @@ func revertOptionsFromC(opts *C.git_revert_options) RevertOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
func freeRevertOptions(opts *C.git_revert_options) {
|
func freeRevertOptions(opts *C.git_revert_options) {
|
||||||
freeCheckoutOpts(&opts.checkout_opts)
|
freeCheckoutOptions(&opts.checkout_opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultRevertOptions initialises a RevertOptions struct with default values
|
// DefaultRevertOptions initialises a RevertOptions struct with default values
|
||||||
|
|
|
@ -68,6 +68,7 @@ cmake -DTHREADSAFE=ON \
|
||||||
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
|
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
|
||||||
-DCMAKE_INSTALL_PREFIX="${BUILD_INSTALL_PREFIX}" \
|
-DCMAKE_INSTALL_PREFIX="${BUILD_INSTALL_PREFIX}" \
|
||||||
-DCMAKE_INSTALL_LIBDIR="lib" \
|
-DCMAKE_INSTALL_LIBDIR="lib" \
|
||||||
|
-DDEPRECATE_HARD=ON \
|
||||||
"${VENDORED_PATH}" &&
|
"${VENDORED_PATH}" &&
|
||||||
|
|
||||||
exec cmake --build . --target install
|
exec cmake --build . --target install
|
||||||
|
|
20
stash.go
20
stash.go
|
@ -140,7 +140,7 @@ func stashApplyProgressCb(progress C.git_stash_apply_progress_t, handle unsafe.P
|
||||||
// StashApplyOptions represents options to control the apply operation.
|
// StashApplyOptions represents options to control the apply operation.
|
||||||
type StashApplyOptions struct {
|
type StashApplyOptions struct {
|
||||||
Flags StashApplyFlag
|
Flags StashApplyFlag
|
||||||
CheckoutOptions CheckoutOpts // options to use when writing files to the working directory
|
CheckoutOptions CheckoutOptions // options to use when writing files to the working directory
|
||||||
ProgressCallback StashApplyProgressCallback // optional callback to notify the consumer of application progress
|
ProgressCallback StashApplyProgressCallback // optional callback to notify the consumer of application progress
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ func (opts *StashApplyOptions) toC() (
|
||||||
version: C.GIT_STASH_APPLY_OPTIONS_VERSION,
|
version: C.GIT_STASH_APPLY_OPTIONS_VERSION,
|
||||||
flags: C.uint32_t(opts.Flags),
|
flags: C.uint32_t(opts.Flags),
|
||||||
}
|
}
|
||||||
populateCheckoutOpts(&optsC.checkout_options, &opts.CheckoutOptions)
|
populateCheckoutOptions(&optsC.checkout_options, &opts.CheckoutOptions)
|
||||||
if opts.ProgressCallback != nil {
|
if opts.ProgressCallback != nil {
|
||||||
C._go_git_setup_stash_apply_progress_callbacks(optsC)
|
C._go_git_setup_stash_apply_progress_callbacks(optsC)
|
||||||
optsC.progress_payload = pointerHandles.Track(progressData)
|
optsC.progress_payload = pointerHandles.Track(progressData)
|
||||||
|
@ -191,21 +191,21 @@ func untrackStashApplyOptionsCallback(optsC *C.git_stash_apply_options) {
|
||||||
|
|
||||||
func freeStashApplyOptions(optsC *C.git_stash_apply_options) {
|
func freeStashApplyOptions(optsC *C.git_stash_apply_options) {
|
||||||
if optsC != nil {
|
if optsC != nil {
|
||||||
freeCheckoutOpts(&optsC.checkout_options)
|
freeCheckoutOptions(&optsC.checkout_options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply applies a single stashed state from the stash list.
|
// Apply applies a single stashed state from the stash list.
|
||||||
//
|
//
|
||||||
// If local changes in the working directory conflict with changes in the
|
// If local changes in the working directory conflict with changes in the
|
||||||
// stash then ErrConflict will be returned. In this case, the index
|
// stash then ErrorCodeConflict will be returned. In this case, the index
|
||||||
// will always remain unmodified and all files in the working directory will
|
// will always remain unmodified and all files in the working directory will
|
||||||
// remain unmodified. However, if you are restoring untracked files or
|
// remain unmodified. However, if you are restoring untracked files or
|
||||||
// ignored files and there is a conflict when applying the modified files,
|
// ignored files and there is a conflict when applying the modified files,
|
||||||
// then those files will remain in the working directory.
|
// then those files will remain in the working directory.
|
||||||
//
|
//
|
||||||
// If passing the StashApplyReinstateIndex flag and there would be conflicts
|
// If passing the StashApplyReinstateIndex flag and there would be conflicts
|
||||||
// when reinstating the index, the function will return ErrConflict
|
// when reinstating the index, the function will return ErrorCodeConflict
|
||||||
// and both the working directory and index will be left unmodified.
|
// and both the working directory and index will be left unmodified.
|
||||||
//
|
//
|
||||||
// Note that a minimum checkout strategy of 'CheckoutSafe' is implied.
|
// Note that a minimum checkout strategy of 'CheckoutSafe' is implied.
|
||||||
|
@ -213,12 +213,12 @@ func freeStashApplyOptions(optsC *C.git_stash_apply_options) {
|
||||||
// 'index' is the position within the stash list. 0 points to the most
|
// 'index' is the position within the stash list. 0 points to the most
|
||||||
// recent stashed state.
|
// recent stashed state.
|
||||||
//
|
//
|
||||||
// Returns error code ErrNotFound if there's no stashed state for the given
|
// Returns error code ErrorCodeNotFound if there's no stashed state for the given
|
||||||
// index, error code ErrConflict if local changes in the working directory
|
// index, error code ErrorCodeConflict if local changes in the working directory
|
||||||
// conflict with changes in the stash, the user returned error from the
|
// conflict with changes in the stash, the user returned error from the
|
||||||
// StashApplyProgressCallback, if any, or other error code.
|
// StashApplyProgressCallback, if any, or other error code.
|
||||||
//
|
//
|
||||||
// Error codes can be interogated with IsErrorCode(err, ErrNotFound).
|
// Error codes can be interogated with IsErrorCode(err, ErrorCodeNotFound).
|
||||||
func (c *StashCollection) Apply(index int, opts StashApplyOptions) error {
|
func (c *StashCollection) Apply(index int, opts StashApplyOptions) error {
|
||||||
optsC, progressData := opts.toC()
|
optsC, progressData := opts.toC()
|
||||||
defer untrackStashApplyOptionsCallback(optsC)
|
defer untrackStashApplyOptionsCallback(optsC)
|
||||||
|
@ -298,7 +298,7 @@ func (c *StashCollection) Foreach(callback StashCallback) error {
|
||||||
// 'index' is the position within the stash list. 0 points
|
// 'index' is the position within the stash list. 0 points
|
||||||
// to the most recent stashed state.
|
// to the most recent stashed state.
|
||||||
//
|
//
|
||||||
// Returns error code ErrNotFound if there's no stashed
|
// Returns error code ErrorCodeNotFound if there's no stashed
|
||||||
// state for the given index.
|
// state for the given index.
|
||||||
func (c *StashCollection) Drop(index int) error {
|
func (c *StashCollection) Drop(index int) error {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
|
@ -320,7 +320,7 @@ func (c *StashCollection) Drop(index int) error {
|
||||||
//
|
//
|
||||||
// 'opts' controls how stashes are applied.
|
// 'opts' controls how stashes are applied.
|
||||||
//
|
//
|
||||||
// Returns error code ErrNotFound if there's no stashed
|
// Returns error code ErrorCodeNotFound if there's no stashed
|
||||||
// state for the given index.
|
// state for the given index.
|
||||||
func (c *StashCollection) Pop(index int, opts StashApplyOptions) error {
|
func (c *StashCollection) Pop(index int, opts StashApplyOptions) error {
|
||||||
optsC, progressData := opts.toC()
|
optsC, progressData := opts.toC()
|
||||||
|
|
|
@ -56,8 +56,8 @@ func TestStash(t *testing.T) {
|
||||||
// Apply: no stash for the given index
|
// Apply: no stash for the given index
|
||||||
|
|
||||||
err = repo.Stashes.Apply(1, opts)
|
err = repo.Stashes.Apply(1, opts)
|
||||||
if !IsErrorCode(err, ErrNotFound) {
|
if !IsErrorCode(err, ErrorCodeNotFound) {
|
||||||
t.Errorf("expecting GIT_ENOTFOUND error code %d, got %v", ErrNotFound, err)
|
t.Errorf("expecting GIT_ENOTFOUND error code %d, got %v", ErrorCodeNotFound, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply: callback stopped
|
// Apply: callback stopped
|
||||||
|
|
13
submodule.go
13
submodule.go
|
@ -106,20 +106,21 @@ func (c *SubmoduleCollection) Lookup(name string) (*Submodule, error) {
|
||||||
return newSubmoduleFromC(ptr, c.repo), nil
|
return newSubmoduleFromC(ptr, c.repo), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type SubmoduleCbk func(sub *Submodule, name string) int
|
// SubmoduleCallback is a function that is called for every submodule found in SubmoduleCollection.Foreach.
|
||||||
|
type SubmoduleCallback func(sub *Submodule, name string) int
|
||||||
|
|
||||||
//export SubmoduleVisitor
|
//export submoduleCallback
|
||||||
func SubmoduleVisitor(csub unsafe.Pointer, name *C.char, handle unsafe.Pointer) C.int {
|
func submoduleCallback(csub unsafe.Pointer, name *C.char, handle unsafe.Pointer) C.int {
|
||||||
sub := &Submodule{(*C.git_submodule)(csub), nil}
|
sub := &Submodule{(*C.git_submodule)(csub), nil}
|
||||||
|
|
||||||
if callback, ok := pointerHandles.Get(handle).(SubmoduleCbk); ok {
|
if callback, ok := pointerHandles.Get(handle).(SubmoduleCallback); ok {
|
||||||
return (C.int)(callback(sub, C.GoString(name)))
|
return (C.int)(callback(sub, C.GoString(name)))
|
||||||
} else {
|
} else {
|
||||||
panic("invalid submodule visitor callback")
|
panic("invalid submodule visitor callback")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *SubmoduleCollection) Foreach(cbk SubmoduleCbk) error {
|
func (c *SubmoduleCollection) Foreach(cbk SubmoduleCallback) error {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
@ -366,7 +367,7 @@ func populateSubmoduleUpdateOptions(ptr *C.git_submodule_update_options, opts *S
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
populateCheckoutOpts(&ptr.checkout_opts, opts.CheckoutOpts)
|
populateCheckoutOptions(&ptr.checkout_opts, opts.CheckoutOpts)
|
||||||
populateFetchOptions(&ptr.fetch_opts, opts.FetchOptions)
|
populateFetchOptions(&ptr.fetch_opts, opts.FetchOptions)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
4
tag.go
4
tag.go
|
@ -159,7 +159,7 @@ func (c *TagsCollection) List() ([]string, error) {
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return nil, MakeGitError(ecode)
|
return nil, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
defer C.git_strarray_free(&strC)
|
defer C.git_strarray_dispose(&strC)
|
||||||
|
|
||||||
tags := makeStringsFromCStrings(strC.strings, int(strC.count))
|
tags := makeStringsFromCStrings(strC.strings, int(strC.count))
|
||||||
return tags, nil
|
return tags, nil
|
||||||
|
@ -183,7 +183,7 @@ func (c *TagsCollection) ListWithMatch(pattern string) ([]string, error) {
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return nil, MakeGitError(ecode)
|
return nil, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
defer C.git_strarray_free(&strC)
|
defer C.git_strarray_dispose(&strC)
|
||||||
|
|
||||||
tags := makeStringsFromCStrings(strC.strings, int(strC.count))
|
tags := makeStringsFromCStrings(strC.strings, int(strC.count))
|
||||||
return tags, nil
|
return tags, nil
|
||||||
|
|
4
tree.go
4
tree.go
|
@ -121,8 +121,8 @@ func (t *Tree) EntryCount() uint64 {
|
||||||
|
|
||||||
type TreeWalkCallback func(string, *TreeEntry) int
|
type TreeWalkCallback func(string, *TreeEntry) int
|
||||||
|
|
||||||
//export CallbackGitTreeWalk
|
//export treeWalkCallback
|
||||||
func CallbackGitTreeWalk(_root *C.char, entry *C.git_tree_entry, ptr unsafe.Pointer) C.int {
|
func treeWalkCallback(_root *C.char, entry *C.git_tree_entry, ptr unsafe.Pointer) C.int {
|
||||||
root := C.GoString(_root)
|
root := C.GoString(_root)
|
||||||
|
|
||||||
if callback, ok := pointerHandles.Get(ptr).(TreeWalkCallback); ok {
|
if callback, ok := pointerHandles.Get(ptr).(TreeWalkCallback); ok {
|
||||||
|
|
2
walk.go
2
walk.go
|
@ -182,7 +182,7 @@ func (v *RevWalk) Iterate(fun RevWalkIterator) (err error) {
|
||||||
oid := new(Oid)
|
oid := new(Oid)
|
||||||
for {
|
for {
|
||||||
err = v.Next(oid)
|
err = v.Next(oid)
|
||||||
if IsErrorCode(err, ErrIterOver) {
|
if IsErrorCode(err, ErrorCodeIterOver) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -30,12 +30,12 @@ void _go_git_populate_checkout_cb(git_checkout_options *opts)
|
||||||
|
|
||||||
int _go_git_visit_submodule(git_repository *repo, void *fct)
|
int _go_git_visit_submodule(git_repository *repo, void *fct)
|
||||||
{
|
{
|
||||||
return git_submodule_foreach(repo, (gogit_submodule_cbk)&SubmoduleVisitor, fct);
|
return git_submodule_foreach(repo, (gogit_submodule_cbk)&submoduleCallback, fct);
|
||||||
}
|
}
|
||||||
|
|
||||||
int _go_git_treewalk(git_tree *tree, git_treewalk_mode mode, void *ptr)
|
int _go_git_treewalk(git_tree *tree, git_treewalk_mode mode, void *ptr)
|
||||||
{
|
{
|
||||||
return git_tree_walk(tree, mode, (git_treewalk_cb)&CallbackGitTreeWalk, ptr);
|
return git_tree_walk(tree, mode, (git_treewalk_cb)&treeWalkCallback, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int _go_git_packbuilder_foreach(git_packbuilder *pb, void *payload)
|
int _go_git_packbuilder_foreach(git_packbuilder *pb, void *payload)
|
||||||
|
@ -117,7 +117,7 @@ void _go_git_setup_callbacks(git_remote_callbacks *callbacks) {
|
||||||
|
|
||||||
callbacks->sideband_progress = (git_transport_message_cb)sidebandProgressCallback;
|
callbacks->sideband_progress = (git_transport_message_cb)sidebandProgressCallback;
|
||||||
callbacks->completion = (completion_cb)completionCallback;
|
callbacks->completion = (completion_cb)completionCallback;
|
||||||
callbacks->credentials = (git_cred_acquire_cb)credentialsCallback;
|
callbacks->credentials = (git_credential_acquire_cb)credentialsCallback;
|
||||||
callbacks->transfer_progress = (git_transfer_progress_cb)transferProgressCallback;
|
callbacks->transfer_progress = (git_transfer_progress_cb)transferProgressCallback;
|
||||||
callbacks->update_tips = (update_tips_cb)updateTipsCallback;
|
callbacks->update_tips = (update_tips_cb)updateTipsCallback;
|
||||||
callbacks->certificate_check = (git_transport_certificate_check_cb) certificateCheckCallback;
|
callbacks->certificate_check = (git_transport_certificate_check_cb) certificateCheckCallback;
|
||||||
|
@ -192,7 +192,7 @@ void _go_git_writestream_free(git_writestream *stream)
|
||||||
stream->free(stream);
|
stream->free(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_credtype_t _go_git_cred_credtype(git_cred *cred) {
|
git_credential_t _go_git_credential_credtype(git_credential *cred) {
|
||||||
return cred->credtype;
|
return cred->credtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue