diff options
Diffstat (limited to 'git.go')
| -rw-r--r-- | git.go | 191 |
1 files changed, 99 insertions, 92 deletions
@@ -17,101 +17,106 @@ import ( type ErrorClass int const ( - ErrClassNone ErrorClass = C.GITERR_NONE - ErrClassNoMemory ErrorClass = C.GITERR_NOMEMORY - ErrClassOs ErrorClass = C.GITERR_OS - ErrClassInvalid ErrorClass = C.GITERR_INVALID - ErrClassReference ErrorClass = C.GITERR_REFERENCE - ErrClassZlib ErrorClass = C.GITERR_ZLIB - ErrClassRepository ErrorClass = C.GITERR_REPOSITORY - ErrClassConfig ErrorClass = C.GITERR_CONFIG - ErrClassRegex ErrorClass = C.GITERR_REGEX - ErrClassOdb ErrorClass = C.GITERR_ODB - ErrClassIndex ErrorClass = C.GITERR_INDEX - ErrClassObject ErrorClass = C.GITERR_OBJECT - ErrClassNet ErrorClass = C.GITERR_NET - ErrClassTag ErrorClass = C.GITERR_TAG - ErrClassTree ErrorClass = C.GITERR_TREE - ErrClassIndexer ErrorClass = C.GITERR_INDEXER - ErrClassSSL ErrorClass = C.GITERR_SSL - ErrClassSubmodule ErrorClass = C.GITERR_SUBMODULE - ErrClassThread ErrorClass = C.GITERR_THREAD - ErrClassStash ErrorClass = C.GITERR_STASH - ErrClassCheckout ErrorClass = C.GITERR_CHECKOUT - ErrClassFetchHead ErrorClass = C.GITERR_FETCHHEAD - ErrClassMerge ErrorClass = C.GITERR_MERGE - ErrClassSsh ErrorClass = C.GITERR_SSH - ErrClassFilter ErrorClass = C.GITERR_FILTER - ErrClassRevert ErrorClass = C.GITERR_REVERT - ErrClassCallback ErrorClass = C.GITERR_CALLBACK - ErrClassRebase ErrorClass = C.GITERR_REBASE - ErrClassPatch ErrorClass = C.GITERR_PATCH + ErrorClassNone ErrorClass = C.GIT_ERROR_NONE + ErrorClassNoMemory ErrorClass = C.GIT_ERROR_NOMEMORY + ErrorClassOS ErrorClass = C.GIT_ERROR_OS + ErrorClassInvalid ErrorClass = C.GIT_ERROR_INVALID + ErrorClassReference ErrorClass = C.GIT_ERROR_REFERENCE + ErrorClassZlib ErrorClass = C.GIT_ERROR_ZLIB + ErrorClassRepository ErrorClass = C.GIT_ERROR_REPOSITORY + ErrorClassConfig ErrorClass = C.GIT_ERROR_CONFIG + ErrorClassRegex ErrorClass = C.GIT_ERROR_REGEX + ErrorClassOdb ErrorClass = C.GIT_ERROR_ODB + ErrorClassIndex ErrorClass = C.GIT_ERROR_INDEX + ErrorClassObject ErrorClass = C.GIT_ERROR_OBJECT + ErrorClassNet ErrorClass = C.GIT_ERROR_NET + ErrorClassTag ErrorClass = C.GIT_ERROR_TAG + ErrorClassTree ErrorClass = C.GIT_ERROR_TREE + ErrorClassIndexer ErrorClass = C.GIT_ERROR_INDEXER + ErrorClassSSL ErrorClass = C.GIT_ERROR_SSL + ErrorClassSubmodule ErrorClass = C.GIT_ERROR_SUBMODULE + ErrorClassThread ErrorClass = C.GIT_ERROR_THREAD + ErrorClassStash ErrorClass = C.GIT_ERROR_STASH + ErrorClassCheckout ErrorClass = C.GIT_ERROR_CHECKOUT + ErrorClassFetchHead ErrorClass = C.GIT_ERROR_FETCHHEAD + ErrorClassMerge ErrorClass = C.GIT_ERROR_MERGE + ErrorClassSSH ErrorClass = C.GIT_ERROR_SSH + ErrorClassFilter ErrorClass = C.GIT_ERROR_FILTER + ErrorClassRevert ErrorClass = C.GIT_ERROR_REVERT + ErrorClassCallback ErrorClass = C.GIT_ERROR_CALLBACK + ErrorClassRebase ErrorClass = C.GIT_ERROR_REBASE + ErrorClassPatch ErrorClass = C.GIT_ERROR_PATCH ) type ErrorCode int const ( + // ErrorCodeOK indicates that the operation completed successfully. + ErrorCodeOK ErrorCode = C.GIT_OK - // No error - ErrOk ErrorCode = C.GIT_OK + // ErrorCodeGeneric represents a generic error. + 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 - 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 + // ErrorCodeUser is a special error that is never generated by libgit2 // 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. - ErrUser ErrorCode = C.GIT_EUSER + ErrorCodeUser ErrorCode = C.GIT_EUSER - // Operation not allowed on bare repository - ErrBareRepo ErrorCode = C.GIT_EBAREREPO - // HEAD refers to branch with no commits - ErrUnbornBranch ErrorCode = C.GIT_EUNBORNBRANCH - // Merge in progress prevented operation - ErrUnmerged ErrorCode = C.GIT_EUNMERGED - // Reference was not fast-forwardable - ErrNonFastForward ErrorCode = C.GIT_ENONFASTFORWARD - // Name/ref spec was not in a valid format - ErrInvalidSpec ErrorCode = C.GIT_EINVALIDSPEC - // Checkout conflicts prevented operation - ErrConflict ErrorCode = C.GIT_ECONFLICT - // Lock file prevented operation - ErrLocked ErrorCode = C.GIT_ELOCKED - // Reference value does not match expected - 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 + // ErrorCodeBareRepo represents that the operation not allowed on bare repository + ErrorCodeBareRepo ErrorCode = C.GIT_EBAREREPO + // ErrorCodeUnbornBranch represents that HEAD refers to branch with no commits. + ErrorCodeUnbornBranch ErrorCode = C.GIT_EUNBORNBRANCH + // ErrorCodeUnmerged represents that a merge in progress prevented operation. + ErrorCodeUnmerged ErrorCode = C.GIT_EUNMERGED + // ErrorCodeNonFastForward represents that the reference was not fast-forwardable. + ErrorCodeNonFastForward ErrorCode = C.GIT_ENONFASTFORWARD + // ErrorCodeInvalidSpec represents that the name/ref spec was not in a valid format. + ErrorCodeInvalidSpec ErrorCode = C.GIT_EINVALIDSPEC + // ErrorCodeConflict represents that checkout conflicts prevented operation. + ErrorCodeConflict ErrorCode = C.GIT_ECONFLICT + // ErrorCodeLocked represents that lock file prevented operation. + ErrorCodeLocked ErrorCode = C.GIT_ELOCKED + // ErrorCodeModified represents that the reference value does not match expected. + ErrorCodeModified ErrorCode = C.GIT_EMODIFIED + // ErrorCodeAuth represents that the authentication failed. + ErrorCodeAuth ErrorCode = C.GIT_EAUTH + // ErrorCodeCertificate represents that the server certificate is invalid. + ErrorCodeCertificate ErrorCode = C.GIT_ECERTIFICATE + // ErrorCodeApplied represents that the patch/merge has already been applied. + ErrorCodeApplied ErrorCode = C.GIT_EAPPLIED + // ErrorCodePeel represents that the requested peel operation is not possible. + ErrorCodePeel ErrorCode = C.GIT_EPEEL + // ErrorCodeEOF represents an unexpected EOF. + ErrorCodeEOF ErrorCode = C.GIT_EEOF + // ErrorCodeInvalid represents an invalid operation or input. + ErrorCodeInvalid ErrorCode = C.GIT_EINVALID + // ErrorCodeUIncommitted represents that uncommitted changes in index prevented operation. + ErrorCodeUncommitted ErrorCode = C.GIT_EUNCOMMITTED + // ErrorCodeDirectory represents that the operation is not valid for a directory. + ErrorCodeDirectory ErrorCode = C.GIT_EDIRECTORY + // ErrorCodeMergeConflict represents that a merge conflict exists and cannot continue. + ErrorCodeMergeConflict ErrorCode = C.GIT_EMERGECONFLICT - // Internal only - ErrPassthrough ErrorCode = C.GIT_PASSTHROUGH - // Signals end of iteration with iterator - ErrIterOver ErrorCode = C.GIT_ITEROVER - // Patch application failed - ErrApplyFail ErrorCode = C.GIT_EAPPLYFAIL + // ErrorCodePassthrough represents that a user-configured callback refused to act. + ErrorCodePassthrough ErrorCode = C.GIT_PASSTHROUGH + // ErrorCodeIterOver signals end of iteration with iterator. + ErrorCodeIterOver ErrorCode = C.GIT_ITEROVER + // ErrorCodeRetry is an internal-only error code. + 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 ( @@ -201,7 +206,7 @@ func NewOid(s string) (*Oid, error) { } if len(slice) != 20 { - return nil, &GitError{"Invalid Oid", ErrClassNone, ErrGeneric} + return nil, &GitError{"Invalid Oid", ErrorClassNone, ErrGeneric} } copy(o[:], slice[:20]) @@ -269,7 +274,6 @@ func (e GitError) Error() string { } func IsErrorClass(err error, c ErrorClass) bool { - if err == nil { return false } @@ -289,20 +293,23 @@ func IsErrorCode(err error, c ErrorCode) bool { return false } -func MakeGitError(errorCode C.int) error { - +func MakeGitError(c C.int) error { var errMessage string var errClass ErrorClass - if errorCode != C.GIT_ITEROVER { - err := C.giterr_last() + errorCode := ErrorCode(c) + if errorCode != ErrorCodeIterOver { + err := C.git_error_last() if err != nil { errMessage = C.GoString(err.message) errClass = ErrorClass(err.klass) } 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 { |
