Update libgit2 to 821131f
The API changes are: - `*Remote.Connect` ```go // from: func (o *Remote) Connect(direction ConnectDirection, callbacks *RemoteCallbacks) error // to: func (o *Remote) Connect(direction ConnectDirection, callbacks *RemoteCallbacks, headers []string) error ``` - `*Remote.ConnectFetch` - `headers` was added as above - `*Remote.ConnectPush` - `headers` was added as above
This commit is contained in:
parent
c4868aef6c
commit
367cd8eb9b
21
config.go
21
config.go
|
@ -12,6 +12,9 @@ import (
|
||||||
type ConfigLevel int
|
type ConfigLevel int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// System-wide on Windows, for compatibility with portable git
|
||||||
|
ConfigLevelProgramdata ConfigLevel = C.GIT_CONFIG_LEVEL_PROGRAMDATA
|
||||||
|
|
||||||
// System-wide configuration file; /etc/gitconfig on Linux systems
|
// System-wide configuration file; /etc/gitconfig on Linux systems
|
||||||
ConfigLevelSystem ConfigLevel = C.GIT_CONFIG_LEVEL_SYSTEM
|
ConfigLevelSystem ConfigLevel = C.GIT_CONFIG_LEVEL_SYSTEM
|
||||||
|
|
||||||
|
@ -410,3 +413,21 @@ func ConfigFindXDG() (string, error) {
|
||||||
|
|
||||||
return C.GoString(buf.ptr), nil
|
return C.GoString(buf.ptr), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConfigFindProgramdata locate the path to the configuration file in ProgramData.
|
||||||
|
//
|
||||||
|
// Look for the file in %PROGRAMDATA%\Git\config used by portable git.
|
||||||
|
func ConfigFindProgramdata() (string, error) {
|
||||||
|
var buf C.git_buf
|
||||||
|
defer C.git_buf_free(&buf)
|
||||||
|
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
ret := C.git_config_find_programdata(&buf)
|
||||||
|
if ret < 0 {
|
||||||
|
return "", MakeGitError(ret)
|
||||||
|
}
|
||||||
|
|
||||||
|
return C.GoString(buf.ptr), nil
|
||||||
|
}
|
||||||
|
|
22
git.go
22
git.go
|
@ -52,6 +52,7 @@ const (
|
||||||
|
|
||||||
// No error
|
// No error
|
||||||
ErrOk ErrorCode = C.GIT_OK
|
ErrOk ErrorCode = C.GIT_OK
|
||||||
|
|
||||||
// Generic error
|
// Generic error
|
||||||
ErrGeneric ErrorCode = C.GIT_ERROR
|
ErrGeneric ErrorCode = C.GIT_ERROR
|
||||||
// Requested object could not be found
|
// Requested object could not be found
|
||||||
|
@ -62,10 +63,12 @@ const (
|
||||||
ErrAmbigious ErrorCode = C.GIT_EAMBIGUOUS
|
ErrAmbigious ErrorCode = C.GIT_EAMBIGUOUS
|
||||||
// Output buffer too short to hold data
|
// Output buffer too short to hold data
|
||||||
ErrBuffs ErrorCode = C.GIT_EBUFS
|
ErrBuffs ErrorCode = C.GIT_EBUFS
|
||||||
|
|
||||||
// GIT_EUSER is a special error that is never generated by libgit2
|
// 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
|
ErrUser ErrorCode = C.GIT_EUSER
|
||||||
|
|
||||||
// Operation not allowed on bare repository
|
// Operation not allowed on bare repository
|
||||||
ErrBareRepo ErrorCode = C.GIT_EBAREREPO
|
ErrBareRepo ErrorCode = C.GIT_EBAREREPO
|
||||||
// HEAD refers to branch with no commits
|
// HEAD refers to branch with no commits
|
||||||
|
@ -82,12 +85,27 @@ const (
|
||||||
ErrLocked ErrorCode = C.GIT_ELOCKED
|
ErrLocked ErrorCode = C.GIT_ELOCKED
|
||||||
// Reference value does not match expected
|
// Reference value does not match expected
|
||||||
ErrModified ErrorCode = C.GIT_EMODIFIED
|
ErrModified ErrorCode = C.GIT_EMODIFIED
|
||||||
|
// Authentication failed
|
||||||
|
ErrAuth ErrorCode = C.GIT_EAUTH
|
||||||
|
// Server certificate is invalid
|
||||||
|
ErrCertificate ErrorCode = C.GIT_ECERTIFICATE
|
||||||
|
// Patch/merge has already been applied
|
||||||
|
ErrApplied ErrorCode = C.GIT_EAPPLIED
|
||||||
|
// The requested peel operation is not possible
|
||||||
|
ErrPeel ErrorCode = C.GIT_EPEEL
|
||||||
|
// Unexpected EOF
|
||||||
|
ErrEOF ErrorCode = C.GIT_EEOF
|
||||||
|
// Uncommitted changes in index prevented operation
|
||||||
|
ErrUncommitted ErrorCode = C.GIT_EUNCOMMITTED
|
||||||
|
// The operation is not valid for a directory
|
||||||
|
ErrDirectory ErrorCode = C.GIT_EDIRECTORY
|
||||||
|
// A merge conflict exists and cannot continue
|
||||||
|
ErrMergeConflict ErrorCode = C.GIT_EMERGECONFLICT
|
||||||
|
|
||||||
// Internal only
|
// Internal only
|
||||||
ErrPassthrough ErrorCode = C.GIT_PASSTHROUGH
|
ErrPassthrough ErrorCode = C.GIT_PASSTHROUGH
|
||||||
// Signals end of iteration with iterator
|
// Signals end of iteration with iterator
|
||||||
ErrIterOver ErrorCode = C.GIT_ITEROVER
|
ErrIterOver ErrorCode = C.GIT_ITEROVER
|
||||||
// Authentication failed
|
|
||||||
ErrAuth ErrorCode = C.GIT_EAUTH
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
18
index.go
18
index.go
|
@ -26,6 +26,24 @@ const (
|
||||||
IndexAddCheckPathspec IndexAddOpts = C.GIT_INDEX_ADD_CHECK_PATHSPEC
|
IndexAddCheckPathspec IndexAddOpts = C.GIT_INDEX_ADD_CHECK_PATHSPEC
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type IndexStageOpts int
|
||||||
|
|
||||||
|
const (
|
||||||
|
// IndexStageAny matches any index stage.
|
||||||
|
//
|
||||||
|
// Some index APIs take a stage to match; pass this value to match
|
||||||
|
// any entry matching the path regardless of stage.
|
||||||
|
IndexStageAny IndexStageOpts = C.GIT_INDEX_STAGE_ANY
|
||||||
|
// IndexStageNormal is a normal staged file in the index.
|
||||||
|
IndexStageNormal IndexStageOpts = C.GIT_INDEX_STAGE_NORMAL
|
||||||
|
// IndexStageAncestor is the ancestor side of a conflict.
|
||||||
|
IndexStageAncestor IndexStageOpts = C.GIT_INDEX_STAGE_ANCESTOR
|
||||||
|
// IndexStageOurs is the "ours" side of a conflict.
|
||||||
|
IndexStageOurs IndexStageOpts = C.GIT_INDEX_STAGE_OURS
|
||||||
|
// IndexStageTheirs is the "theirs" side of a conflict.
|
||||||
|
IndexStageTheirs IndexStageOpts = C.GIT_INDEX_STAGE_THEIRS
|
||||||
|
)
|
||||||
|
|
||||||
type Index struct {
|
type Index struct {
|
||||||
ptr *C.git_index
|
ptr *C.git_index
|
||||||
}
|
}
|
||||||
|
|
7
merge.go
7
merge.go
|
@ -81,7 +81,14 @@ func (r *Repository) AnnotatedCommitFromRef(ref *Reference) (*AnnotatedCommit, e
|
||||||
type MergeTreeFlag int
|
type MergeTreeFlag int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// Detect renames that occur between the common ancestor and the "ours"
|
||||||
|
// side or the common ancestor and the "theirs" side. This will enable
|
||||||
|
// the ability to merge between a modified and renamed file.
|
||||||
MergeTreeFindRenames MergeTreeFlag = C.GIT_MERGE_TREE_FIND_RENAMES
|
MergeTreeFindRenames MergeTreeFlag = C.GIT_MERGE_TREE_FIND_RENAMES
|
||||||
|
// If a conflict occurs, exit immediately instead of attempting to
|
||||||
|
// continue resolving conflicts. The merge operation will fail with
|
||||||
|
// GIT_EMERGECONFLICT and no index will be returned.
|
||||||
|
MergeTreeFailOnConflict MergeTreeFlag = C.GIT_MERGE_TREE_FAIL_ON_CONFLICT
|
||||||
)
|
)
|
||||||
|
|
||||||
type MergeOptions struct {
|
type MergeOptions struct {
|
||||||
|
|
40
remote.go
40
remote.go
|
@ -112,6 +112,9 @@ type FetchOptions struct {
|
||||||
//
|
//
|
||||||
// The default is to auto-follow tags.
|
// The default is to auto-follow tags.
|
||||||
DownloadTags DownloadTags
|
DownloadTags DownloadTags
|
||||||
|
|
||||||
|
// Headers are extra headers for the fetch operation.
|
||||||
|
Headers []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Remote struct {
|
type Remote struct {
|
||||||
|
@ -157,6 +160,9 @@ type PushOptions struct {
|
||||||
RemoteCallbacks RemoteCallbacks
|
RemoteCallbacks RemoteCallbacks
|
||||||
|
|
||||||
PbParallelism uint
|
PbParallelism uint
|
||||||
|
|
||||||
|
// Headers are extra headers for the push operation.
|
||||||
|
Headers []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type RemoteHead struct {
|
type RemoteHead struct {
|
||||||
|
@ -594,6 +600,10 @@ func populateFetchOptions(options *C.git_fetch_options, opts *FetchOptions) {
|
||||||
options.prune = C.git_fetch_prune_t(opts.Prune)
|
options.prune = C.git_fetch_prune_t(opts.Prune)
|
||||||
options.update_fetchhead = cbool(opts.UpdateFetchhead)
|
options.update_fetchhead = cbool(opts.UpdateFetchhead)
|
||||||
options.download_tags = C.git_remote_autotag_option_t(opts.DownloadTags)
|
options.download_tags = C.git_remote_autotag_option_t(opts.DownloadTags)
|
||||||
|
|
||||||
|
options.custom_headers = C.git_strarray{}
|
||||||
|
options.custom_headers.count = C.size_t(len(opts.Headers))
|
||||||
|
options.custom_headers.strings = makeCStringsFromStrings(opts.Headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
func populatePushOptions(options *C.git_push_options, opts *PushOptions) {
|
func populatePushOptions(options *C.git_push_options, opts *PushOptions) {
|
||||||
|
@ -604,6 +614,10 @@ func populatePushOptions(options *C.git_push_options, opts *PushOptions) {
|
||||||
|
|
||||||
options.pb_parallelism = C.uint(opts.PbParallelism)
|
options.pb_parallelism = C.uint(opts.PbParallelism)
|
||||||
|
|
||||||
|
options.custom_headers = C.git_strarray{}
|
||||||
|
options.custom_headers.count = C.size_t(len(opts.Headers))
|
||||||
|
options.custom_headers.strings = makeCStringsFromStrings(opts.Headers)
|
||||||
|
|
||||||
populateRemoteCallbacks(&options.callbacks, &opts.RemoteCallbacks)
|
populateRemoteCallbacks(&options.callbacks, &opts.RemoteCallbacks)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -626,6 +640,7 @@ func (o *Remote) Fetch(refspecs []string, opts *FetchOptions, msg string) error
|
||||||
var coptions C.git_fetch_options
|
var coptions C.git_fetch_options
|
||||||
populateFetchOptions(&coptions, opts)
|
populateFetchOptions(&coptions, opts)
|
||||||
defer untrackCalbacksPayload(&coptions.callbacks)
|
defer untrackCalbacksPayload(&coptions.callbacks)
|
||||||
|
defer freeStrarray(&coptions.custom_headers)
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
@ -637,22 +652,34 @@ func (o *Remote) Fetch(refspecs []string, opts *FetchOptions, msg string) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Remote) ConnectFetch(callbacks *RemoteCallbacks) error {
|
func (o *Remote) ConnectFetch(callbacks *RemoteCallbacks, headers []string) error {
|
||||||
return o.Connect(ConnectDirectionFetch, callbacks)
|
return o.Connect(ConnectDirectionFetch, callbacks, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Remote) ConnectPush(callbacks *RemoteCallbacks) error {
|
func (o *Remote) ConnectPush(callbacks *RemoteCallbacks, headers []string) error {
|
||||||
return o.Connect(ConnectDirectionPush, callbacks)
|
return o.Connect(ConnectDirectionPush, callbacks, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Remote) Connect(direction ConnectDirection, callbacks *RemoteCallbacks) error {
|
// Connect opens a connection to a remote.
|
||||||
|
//
|
||||||
|
// The transport is selected based on the URL. The direction argument
|
||||||
|
// is due to a limitation of the git protocol (over TCP or SSH) which
|
||||||
|
// starts up a specific binary which can only do the one or the other.
|
||||||
|
//
|
||||||
|
// 'headers' are extra HTTP headers to use in this connection.
|
||||||
|
func (o *Remote) Connect(direction ConnectDirection, callbacks *RemoteCallbacks, headers []string) error {
|
||||||
var ccallbacks C.git_remote_callbacks
|
var ccallbacks C.git_remote_callbacks
|
||||||
populateRemoteCallbacks(&ccallbacks, callbacks)
|
populateRemoteCallbacks(&ccallbacks, callbacks)
|
||||||
|
|
||||||
|
cheaders := C.git_strarray{}
|
||||||
|
cheaders.count = C.size_t(len(headers))
|
||||||
|
cheaders.strings = makeCStringsFromStrings(headers)
|
||||||
|
defer freeStrarray(&cheaders)
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
if ret := C.git_remote_connect(o.ptr, C.git_direction(direction), &ccallbacks); ret != 0 {
|
if ret := C.git_remote_connect(o.ptr, C.git_direction(direction), &ccallbacks, &cheaders); ret != 0 {
|
||||||
return MakeGitError(ret)
|
return MakeGitError(ret)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -713,6 +740,7 @@ func (o *Remote) Push(refspecs []string, opts *PushOptions) error {
|
||||||
var coptions C.git_push_options
|
var coptions C.git_push_options
|
||||||
populatePushOptions(&coptions, opts)
|
populatePushOptions(&coptions, opts)
|
||||||
defer untrackCalbacksPayload(&coptions.callbacks)
|
defer untrackCalbacksPayload(&coptions.callbacks)
|
||||||
|
defer freeStrarray(&coptions.custom_headers)
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
|
@ -58,7 +58,7 @@ func TestRemoteConnect(t *testing.T) {
|
||||||
remote, err := repo.Remotes.Create("origin", "https://github.com/libgit2/TestGitRepository")
|
remote, err := repo.Remotes.Create("origin", "https://github.com/libgit2/TestGitRepository")
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
err = remote.ConnectFetch(nil)
|
err = remote.ConnectFetch(nil, nil)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ func TestRemoteLs(t *testing.T) {
|
||||||
remote, err := repo.Remotes.Create("origin", "https://github.com/libgit2/TestGitRepository")
|
remote, err := repo.Remotes.Create("origin", "https://github.com/libgit2/TestGitRepository")
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
err = remote.ConnectFetch(nil)
|
err = remote.ConnectFetch(nil, nil)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
heads, err := remote.Ls()
|
heads, err := remote.Ls()
|
||||||
|
@ -87,7 +87,7 @@ func TestRemoteLsFiltering(t *testing.T) {
|
||||||
remote, err := repo.Remotes.Create("origin", "https://github.com/libgit2/TestGitRepository")
|
remote, err := repo.Remotes.Create("origin", "https://github.com/libgit2/TestGitRepository")
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
err = remote.ConnectFetch(nil)
|
err = remote.ConnectFetch(nil, nil)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
heads, err := remote.Ls("master")
|
heads, err := remote.Ls("master")
|
||||||
|
@ -166,7 +166,7 @@ func TestRemotePrune(t *testing.T) {
|
||||||
rr, err := repo.Remotes.Lookup("origin")
|
rr, err := repo.Remotes.Lookup("origin")
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
err = rr.ConnectFetch(nil)
|
err = rr.ConnectFetch(nil, nil)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
err = rr.Prune(nil)
|
err = rr.Prune(nil)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit ed38e26db5435b519d8b796e4b6c2c660fe982b5
|
Subproject commit 821131fdaee74526d84aaf1c6ceddc2139c551df
|
Loading…
Reference in New Issue