2013-03-05 13:53:04 -06:00
|
|
|
package git
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include <git2.h>
|
2014-04-26 13:27:54 -05:00
|
|
|
#include <git2/sys/repository.h>
|
2018-08-17 19:46:30 -05:00
|
|
|
#include <git2/sys/commit.h>
|
|
|
|
#include <string.h>
|
2013-03-05 13:53:04 -06:00
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
import (
|
|
|
|
"runtime"
|
2013-11-14 05:08:34 -06:00
|
|
|
"unsafe"
|
2013-03-05 13:53:04 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// Repository
|
|
|
|
type Repository struct {
|
2021-09-05 15:59:36 -05:00
|
|
|
doNotCompare
|
2015-08-31 13:22:17 -05:00
|
|
|
ptr *C.git_repository
|
2015-06-27 17:51:17 -05:00
|
|
|
// Remotes represents the collection of remotes and can be
|
|
|
|
// used to add, remove and configure remotes for this
|
|
|
|
// repository.
|
2015-08-31 13:22:17 -05:00
|
|
|
Remotes RemoteCollection
|
2015-06-27 18:12:32 -05:00
|
|
|
// Submodules represents the collection of submodules and can
|
2015-06-27 17:58:31 -05:00
|
|
|
// be used to add, remove and configure submodules in this
|
2017-07-11 22:52:13 -05:00
|
|
|
// repository.
|
2015-06-27 17:58:31 -05:00
|
|
|
Submodules SubmoduleCollection
|
2015-06-27 18:12:32 -05:00
|
|
|
// References represents the collection of references and can
|
2017-07-11 22:52:13 -05:00
|
|
|
// be used to create, remove or update references for this repository.
|
2015-06-27 18:12:32 -05:00
|
|
|
References ReferenceCollection
|
2015-06-27 18:19:22 -05:00
|
|
|
// Notes represents the collection of notes and can be used to
|
|
|
|
// read, write and delete notes from this repository.
|
2015-08-31 13:22:17 -05:00
|
|
|
Notes NoteCollection
|
2015-07-31 02:51:19 -05:00
|
|
|
// Tags represents the collection of tags and can be used to create,
|
2016-05-29 07:46:55 -05:00
|
|
|
// list, iterate and remove tags in this repository.
|
2015-07-31 02:51:19 -05:00
|
|
|
Tags TagsCollection
|
2015-09-21 06:50:57 -05:00
|
|
|
// Stashes represents the collection of stashes and can be used to
|
|
|
|
// save, apply and iterate over stash states in this repository.
|
|
|
|
Stashes StashCollection
|
2020-12-10 07:35:40 -06:00
|
|
|
|
|
|
|
// weak indicates that a repository is a weak pointer and should not be
|
|
|
|
// freed.
|
|
|
|
weak bool
|
2015-06-27 17:51:17 -05:00
|
|
|
}
|
|
|
|
|
2015-06-30 12:03:52 -05:00
|
|
|
func newRepositoryFromC(ptr *C.git_repository) *Repository {
|
|
|
|
repo := &Repository{ptr: ptr}
|
|
|
|
|
2015-08-31 13:22:17 -05:00
|
|
|
repo.Remotes.repo = repo
|
2021-09-05 17:44:18 -05:00
|
|
|
repo.Remotes.remotes = make(map[*C.git_remote]*Remote)
|
2015-06-27 17:58:31 -05:00
|
|
|
repo.Submodules.repo = repo
|
2015-06-27 18:12:32 -05:00
|
|
|
repo.References.repo = repo
|
2015-08-31 13:22:17 -05:00
|
|
|
repo.Notes.repo = repo
|
2015-07-31 02:51:19 -05:00
|
|
|
repo.Tags.repo = repo
|
2015-09-21 06:50:57 -05:00
|
|
|
repo.Stashes.repo = repo
|
2015-06-30 12:03:52 -05:00
|
|
|
|
2015-06-27 17:51:17 -05:00
|
|
|
runtime.SetFinalizer(repo, (*Repository).Free)
|
2015-06-30 12:03:52 -05:00
|
|
|
|
|
|
|
return repo
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2013-03-06 10:18:25 -06:00
|
|
|
func OpenRepository(path string) (*Repository, error) {
|
2013-03-05 13:53:04 -06:00
|
|
|
cpath := C.CString(path)
|
|
|
|
defer C.free(unsafe.Pointer(cpath))
|
|
|
|
|
2013-09-18 02:23:47 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2015-06-30 12:03:52 -05:00
|
|
|
var ptr *C.git_repository
|
|
|
|
ret := C.git_repository_open(&ptr, cpath)
|
2013-03-05 13:53:04 -06:00
|
|
|
if ret < 0 {
|
2013-07-07 09:43:44 -05:00
|
|
|
return nil, MakeGitError(ret)
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2015-06-30 12:03:52 -05:00
|
|
|
return newRepositoryFromC(ptr), nil
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2016-01-04 07:47:02 -06:00
|
|
|
type RepositoryOpenFlag int
|
|
|
|
|
|
|
|
const (
|
|
|
|
RepositoryOpenNoSearch RepositoryOpenFlag = C.GIT_REPOSITORY_OPEN_NO_SEARCH
|
|
|
|
RepositoryOpenCrossFs RepositoryOpenFlag = C.GIT_REPOSITORY_OPEN_CROSS_FS
|
|
|
|
RepositoryOpenBare RepositoryOpenFlag = C.GIT_REPOSITORY_OPEN_BARE
|
2017-03-07 22:23:24 -06:00
|
|
|
RepositoryOpenFromEnv RepositoryOpenFlag = C.GIT_REPOSITORY_OPEN_FROM_ENV
|
|
|
|
RepositoryOpenNoDotGit RepositoryOpenFlag = C.GIT_REPOSITORY_OPEN_NO_DOTGIT
|
2016-01-04 07:47:02 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func OpenRepositoryExtended(path string, flags RepositoryOpenFlag, ceiling string) (*Repository, error) {
|
2014-04-26 18:35:22 -05:00
|
|
|
cpath := C.CString(path)
|
|
|
|
defer C.free(unsafe.Pointer(cpath))
|
|
|
|
|
2016-01-04 07:47:02 -06:00
|
|
|
var cceiling *C.char = nil
|
|
|
|
if len(ceiling) > 0 {
|
|
|
|
cceiling = C.CString(ceiling)
|
|
|
|
defer C.free(unsafe.Pointer(cceiling))
|
|
|
|
}
|
|
|
|
|
2014-04-26 18:35:22 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2015-06-30 12:03:52 -05:00
|
|
|
var ptr *C.git_repository
|
2016-01-04 07:47:02 -06:00
|
|
|
ret := C.git_repository_open_ext(&ptr, cpath, C.uint(flags), cceiling)
|
2013-03-05 13:53:04 -06:00
|
|
|
if ret < 0 {
|
2013-07-07 09:43:44 -05:00
|
|
|
return nil, MakeGitError(ret)
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2015-06-30 12:03:52 -05:00
|
|
|
return newRepositoryFromC(ptr), nil
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2013-03-06 10:18:25 -06:00
|
|
|
func InitRepository(path string, isbare bool) (*Repository, error) {
|
2013-03-05 13:53:04 -06:00
|
|
|
cpath := C.CString(path)
|
|
|
|
defer C.free(unsafe.Pointer(cpath))
|
|
|
|
|
2013-09-18 02:23:47 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2015-06-30 12:03:52 -05:00
|
|
|
var ptr *C.git_repository
|
|
|
|
ret := C.git_repository_init(&ptr, cpath, ucbool(isbare))
|
2013-03-05 13:53:04 -06:00
|
|
|
if ret < 0 {
|
2013-07-07 09:43:44 -05:00
|
|
|
return nil, MakeGitError(ret)
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2015-06-30 12:03:52 -05:00
|
|
|
return newRepositoryFromC(ptr), nil
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2013-12-19 16:24:44 -06:00
|
|
|
func NewRepositoryWrapOdb(odb *Odb) (repo *Repository, err error) {
|
2014-12-05 19:44:57 -06:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2015-06-30 12:03:52 -05:00
|
|
|
var ptr *C.git_repository
|
|
|
|
ret := C.git_repository_wrap_odb(&ptr, odb.ptr)
|
2017-07-08 09:07:51 -05:00
|
|
|
runtime.KeepAlive(odb)
|
2014-02-24 02:01:47 -06:00
|
|
|
if ret < 0 {
|
2014-04-03 15:49:22 -05:00
|
|
|
return nil, MakeGitError(ret)
|
2013-12-18 16:25:54 -06:00
|
|
|
}
|
|
|
|
|
2015-06-30 12:03:52 -05:00
|
|
|
return newRepositoryFromC(ptr), nil
|
2014-02-24 02:01:47 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Repository) SetRefdb(refdb *Refdb) {
|
|
|
|
C.git_repository_set_refdb(v.ptr, refdb.ptr)
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(v)
|
2013-12-17 17:46:25 -06:00
|
|
|
}
|
|
|
|
|
2013-03-05 18:43:48 -06:00
|
|
|
func (v *Repository) Free() {
|
2020-12-10 07:35:40 -06:00
|
|
|
ptr := v.ptr
|
|
|
|
v.ptr = nil
|
2013-03-05 18:43:48 -06:00
|
|
|
runtime.SetFinalizer(v, nil)
|
2021-09-05 17:44:18 -05:00
|
|
|
v.Remotes.Free()
|
2020-12-10 07:35:40 -06:00
|
|
|
if v.weak {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
C.git_repository_free(ptr)
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Repository) Config() (*Config, error) {
|
|
|
|
config := new(Config)
|
|
|
|
|
2013-09-18 02:23:47 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2013-03-05 13:53:04 -06:00
|
|
|
ret := C.git_repository_config(&config.ptr, v.ptr)
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(v)
|
2013-03-05 13:53:04 -06:00
|
|
|
if ret < 0 {
|
2013-07-07 09:43:44 -05:00
|
|
|
return nil, MakeGitError(ret)
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2013-11-14 07:24:43 -06:00
|
|
|
runtime.SetFinalizer(config, (*Config).Free)
|
2013-03-05 13:53:04 -06:00
|
|
|
return config, nil
|
|
|
|
}
|
|
|
|
|
2021-02-03 21:33:03 -06:00
|
|
|
// SetConfig sets the configuration file for this repository.
|
|
|
|
//
|
|
|
|
// This configuration file will be used for all configuration queries involving
|
|
|
|
// this repository.
|
|
|
|
func (v *Repository) SetConfig(c *Config) error {
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
ret := C.git_repository_set_config(v.ptr, c.ptr)
|
|
|
|
runtime.KeepAlive(v)
|
|
|
|
runtime.KeepAlive(c)
|
|
|
|
if ret < 0 {
|
|
|
|
return MakeGitError(ret)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-03-06 06:10:53 -06:00
|
|
|
func (v *Repository) Index() (*Index, error) {
|
|
|
|
var ptr *C.git_index
|
2013-09-18 02:23:47 -05:00
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2013-03-06 06:10:53 -06:00
|
|
|
ret := C.git_repository_index(&ptr, v.ptr)
|
|
|
|
if ret < 0 {
|
2013-07-07 09:43:44 -05:00
|
|
|
return nil, MakeGitError(ret)
|
2013-03-06 06:10:53 -06:00
|
|
|
}
|
|
|
|
|
2017-07-08 04:38:19 -05:00
|
|
|
return newIndexFromC(ptr, v), nil
|
2013-03-06 06:10:53 -06:00
|
|
|
}
|
|
|
|
|
2015-08-04 07:47:10 -05:00
|
|
|
func (v *Repository) lookupType(id *Oid, t ObjectType) (*Object, error) {
|
2013-04-16 16:04:35 -05:00
|
|
|
var ptr *C.git_object
|
2013-09-18 02:23:47 -05:00
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2019-01-05 04:45:30 -06:00
|
|
|
ret := C.git_object_lookup(&ptr, v.ptr, id.toC(), C.git_object_t(t))
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(id)
|
2013-03-05 13:53:04 -06:00
|
|
|
if ret < 0 {
|
2013-07-07 09:43:44 -05:00
|
|
|
return nil, MakeGitError(ret)
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2014-05-26 02:28:07 -05:00
|
|
|
return allocObject(ptr, v), nil
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2020-10-22 07:21:25 -05:00
|
|
|
func (v *Repository) lookupPrefixType(id *Oid, prefix uint, t ObjectType) (*Object, error) {
|
|
|
|
var ptr *C.git_object
|
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
ret := C.git_object_lookup_prefix(&ptr, v.ptr, id.toC(), C.size_t(prefix), C.git_object_t(t))
|
|
|
|
runtime.KeepAlive(id)
|
|
|
|
if ret < 0 {
|
|
|
|
return nil, MakeGitError(ret)
|
|
|
|
}
|
|
|
|
|
|
|
|
return allocObject(ptr, v), nil
|
|
|
|
}
|
|
|
|
|
2015-08-04 07:47:10 -05:00
|
|
|
func (v *Repository) Lookup(id *Oid) (*Object, error) {
|
2014-02-26 08:30:16 -06:00
|
|
|
return v.lookupType(id, ObjectAny)
|
2013-04-16 16:18:35 -05:00
|
|
|
}
|
|
|
|
|
2020-10-22 07:21:25 -05:00
|
|
|
// LookupPrefix looks up an object by its OID given a prefix of its identifier.
|
|
|
|
func (v *Repository) LookupPrefix(id *Oid, prefix uint) (*Object, error) {
|
|
|
|
return v.lookupPrefixType(id, prefix, ObjectAny)
|
|
|
|
}
|
|
|
|
|
2014-02-26 08:30:16 -06:00
|
|
|
func (v *Repository) LookupTree(id *Oid) (*Tree, error) {
|
|
|
|
obj, err := v.lookupType(id, ObjectTree)
|
2013-04-16 16:04:35 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
2019-02-16 11:14:39 -06:00
|
|
|
defer obj.Free()
|
2013-03-05 13:53:04 -06:00
|
|
|
|
2015-08-04 07:47:10 -05:00
|
|
|
return obj.AsTree()
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2020-10-22 07:21:25 -05:00
|
|
|
// LookupPrefixTree looks up a tree by its OID given a prefix of its identifier.
|
|
|
|
func (v *Repository) LookupPrefixTree(id *Oid, prefix uint) (*Tree, error) {
|
|
|
|
obj, err := v.lookupPrefixType(id, prefix, ObjectTree)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer obj.Free()
|
|
|
|
|
|
|
|
return obj.AsTree()
|
|
|
|
}
|
|
|
|
|
2014-02-26 08:30:16 -06:00
|
|
|
func (v *Repository) LookupCommit(id *Oid) (*Commit, error) {
|
|
|
|
obj, err := v.lookupType(id, ObjectCommit)
|
2013-04-16 16:04:35 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-02-16 11:14:39 -06:00
|
|
|
defer obj.Free()
|
2013-04-16 16:04:35 -05:00
|
|
|
|
2015-08-04 07:47:10 -05:00
|
|
|
return obj.AsCommit()
|
2013-04-16 16:04:35 -05:00
|
|
|
}
|
|
|
|
|
2020-10-22 07:21:25 -05:00
|
|
|
// LookupPrefixCommit looks up a commit by its OID given a prefix of its identifier.
|
|
|
|
func (v *Repository) LookupPrefixCommit(id *Oid, prefix uint) (*Commit, error) {
|
|
|
|
obj, err := v.lookupPrefixType(id, prefix, ObjectCommit)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer obj.Free()
|
|
|
|
|
|
|
|
return obj.AsCommit()
|
|
|
|
}
|
|
|
|
|
2014-02-26 08:30:16 -06:00
|
|
|
func (v *Repository) LookupBlob(id *Oid) (*Blob, error) {
|
|
|
|
obj, err := v.lookupType(id, ObjectBlob)
|
2013-04-16 16:04:35 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2013-03-06 16:59:33 -06:00
|
|
|
}
|
2019-02-16 11:14:39 -06:00
|
|
|
defer obj.Free()
|
2013-03-06 16:59:33 -06:00
|
|
|
|
2015-08-04 07:47:10 -05:00
|
|
|
return obj.AsBlob()
|
2013-03-06 16:59:33 -06:00
|
|
|
}
|
|
|
|
|
2020-10-22 07:21:25 -05:00
|
|
|
// LookupPrefixBlob looks up a blob by its OID given a prefix of its identifier.
|
|
|
|
func (v *Repository) LookupPrefixBlob(id *Oid, prefix uint) (*Blob, error) {
|
|
|
|
obj, err := v.lookupPrefixType(id, prefix, ObjectBlob)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer obj.Free()
|
|
|
|
|
|
|
|
return obj.AsBlob()
|
|
|
|
}
|
|
|
|
|
2014-06-09 16:19:17 -05:00
|
|
|
func (v *Repository) LookupTag(id *Oid) (*Tag, error) {
|
|
|
|
obj, err := v.lookupType(id, ObjectTag)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-02-16 11:14:39 -06:00
|
|
|
defer obj.Free()
|
2014-06-09 16:19:17 -05:00
|
|
|
|
2015-08-04 07:47:10 -05:00
|
|
|
return obj.AsTag()
|
2014-06-09 16:19:17 -05:00
|
|
|
}
|
|
|
|
|
2020-10-22 07:21:25 -05:00
|
|
|
// LookupPrefixTag looks up a tag by its OID given a prefix of its identifier.
|
|
|
|
func (v *Repository) LookupPrefixTag(id *Oid, prefix uint) (*Tag, error) {
|
|
|
|
obj, err := v.lookupPrefixType(id, prefix, ObjectTag)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer obj.Free()
|
|
|
|
|
|
|
|
return obj.AsTag()
|
|
|
|
}
|
|
|
|
|
2014-02-20 00:25:30 -06:00
|
|
|
func (v *Repository) Head() (*Reference, error) {
|
|
|
|
var ptr *C.git_reference
|
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
ecode := C.git_repository_head(&ptr, v.ptr)
|
|
|
|
if ecode < 0 {
|
2014-03-21 00:54:18 -05:00
|
|
|
return nil, MakeGitError(ecode)
|
2014-02-20 00:25:30 -06:00
|
|
|
}
|
|
|
|
|
2014-05-26 02:28:07 -05:00
|
|
|
return newReferenceFromC(ptr, v), nil
|
2014-02-20 00:25:30 -06:00
|
|
|
}
|
|
|
|
|
2015-03-14 19:49:32 -05:00
|
|
|
func (v *Repository) SetHead(refname string) error {
|
2014-05-02 03:44:42 -05:00
|
|
|
cname := C.CString(refname)
|
|
|
|
defer C.free(unsafe.Pointer(cname))
|
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2015-03-14 19:49:32 -05:00
|
|
|
ecode := C.git_repository_set_head(v.ptr, cname)
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(v)
|
2014-05-02 03:44:42 -05:00
|
|
|
if ecode != 0 {
|
|
|
|
return MakeGitError(ecode)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-03-14 19:49:32 -05:00
|
|
|
func (v *Repository) SetHeadDetached(id *Oid) error {
|
2014-05-02 03:44:42 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2015-03-14 19:49:32 -05:00
|
|
|
ecode := C.git_repository_set_head_detached(v.ptr, id.toC())
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(v)
|
|
|
|
runtime.KeepAlive(id)
|
2014-05-02 03:44:42 -05:00
|
|
|
if ecode != 0 {
|
|
|
|
return MakeGitError(ecode)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-04-30 21:16:12 -05:00
|
|
|
func (v *Repository) IsHeadDetached() (bool, error) {
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
ret := C.git_repository_head_detached(v.ptr)
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(v)
|
2015-07-01 09:00:17 -05:00
|
|
|
if ret < 0 {
|
|
|
|
return false, MakeGitError(ret)
|
2015-04-30 21:16:12 -05:00
|
|
|
}
|
2015-07-01 09:00:17 -05:00
|
|
|
|
|
|
|
return ret != 0, nil
|
2015-04-30 21:16:12 -05:00
|
|
|
}
|
|
|
|
|
2016-03-29 13:42:19 -05:00
|
|
|
func (v *Repository) IsHeadUnborn() (bool, error) {
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
ret := C.git_repository_head_unborn(v.ptr)
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(v)
|
2016-03-29 13:42:19 -05:00
|
|
|
if ret < 0 {
|
|
|
|
return false, MakeGitError(ret)
|
|
|
|
}
|
|
|
|
return ret != 0, nil
|
|
|
|
}
|
|
|
|
|
2016-03-29 13:42:30 -05:00
|
|
|
func (v *Repository) IsEmpty() (bool, error) {
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
ret := C.git_repository_is_empty(v.ptr)
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(v)
|
2016-03-29 13:42:30 -05:00
|
|
|
if ret < 0 {
|
|
|
|
return false, MakeGitError(ret)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret != 0, nil
|
|
|
|
}
|
|
|
|
|
2016-03-29 13:42:41 -05:00
|
|
|
func (v *Repository) IsShallow() (bool, error) {
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
ret := C.git_repository_is_shallow(v.ptr)
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(v)
|
2016-03-29 13:42:41 -05:00
|
|
|
if ret < 0 {
|
|
|
|
return false, MakeGitError(ret)
|
|
|
|
}
|
|
|
|
return ret != 0, nil
|
|
|
|
}
|
|
|
|
|
2013-03-05 14:47:55 -06:00
|
|
|
func (v *Repository) Walk() (*RevWalk, error) {
|
2014-03-07 18:43:20 -06:00
|
|
|
|
|
|
|
var walkPtr *C.git_revwalk
|
2013-09-18 02:23:47 -05:00
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2014-03-07 18:43:20 -06:00
|
|
|
ecode := C.git_revwalk_new(&walkPtr, v.ptr)
|
2013-03-05 14:47:55 -06:00
|
|
|
if ecode < 0 {
|
2013-07-07 09:43:44 -05:00
|
|
|
return nil, MakeGitError(ecode)
|
2013-03-05 14:47:55 -06:00
|
|
|
}
|
|
|
|
|
2014-03-07 18:43:20 -06:00
|
|
|
return revWalkFromC(v, walkPtr), nil
|
2013-03-05 14:47:55 -06:00
|
|
|
}
|
|
|
|
|
2013-03-06 09:59:45 -06:00
|
|
|
func (v *Repository) CreateCommit(
|
2013-03-05 13:53:04 -06:00
|
|
|
refname string, author, committer *Signature,
|
|
|
|
message string, tree *Tree, parents ...*Commit) (*Oid, error) {
|
|
|
|
|
|
|
|
oid := new(Oid)
|
2013-03-06 09:59:45 -06:00
|
|
|
|
2014-09-04 02:57:54 -05:00
|
|
|
var cref *C.char
|
2014-09-01 12:27:44 -05:00
|
|
|
if refname == "" {
|
|
|
|
cref = nil
|
2014-09-04 02:57:54 -05:00
|
|
|
} else {
|
|
|
|
cref = C.CString(refname)
|
|
|
|
defer C.free(unsafe.Pointer(cref))
|
2014-09-01 12:27:44 -05:00
|
|
|
}
|
2013-03-06 09:59:45 -06:00
|
|
|
|
2013-03-05 13:53:04 -06:00
|
|
|
cmsg := C.CString(message)
|
|
|
|
defer C.free(unsafe.Pointer(cmsg))
|
2013-03-06 09:59:45 -06:00
|
|
|
|
2013-03-05 13:53:04 -06:00
|
|
|
var cparents []*C.git_commit = nil
|
|
|
|
var parentsarg **C.git_commit = nil
|
2013-03-06 09:59:45 -06:00
|
|
|
|
2013-11-14 05:08:34 -06:00
|
|
|
nparents := len(parents)
|
2013-03-05 13:53:04 -06:00
|
|
|
if nparents > 0 {
|
|
|
|
cparents = make([]*C.git_commit, nparents)
|
|
|
|
for i, v := range parents {
|
2014-04-01 05:13:37 -05:00
|
|
|
cparents[i] = v.cast_ptr
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
parentsarg = &cparents[0]
|
|
|
|
}
|
|
|
|
|
2015-03-04 13:39:35 -06:00
|
|
|
authorSig, err := author.toC()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2013-03-06 09:59:45 -06:00
|
|
|
defer C.git_signature_free(authorSig)
|
|
|
|
|
2015-03-04 13:39:35 -06:00
|
|
|
committerSig, err := committer.toC()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2013-03-06 09:59:45 -06:00
|
|
|
defer C.git_signature_free(committerSig)
|
|
|
|
|
2013-09-18 02:23:47 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2013-03-05 13:53:04 -06:00
|
|
|
ret := C.git_commit_create(
|
|
|
|
oid.toC(), v.ptr, cref,
|
2013-03-06 09:59:45 -06:00
|
|
|
authorSig, committerSig,
|
2014-04-01 05:13:37 -05:00
|
|
|
nil, cmsg, tree.cast_ptr, C.size_t(nparents), parentsarg)
|
2013-03-05 13:53:04 -06:00
|
|
|
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(v)
|
|
|
|
runtime.KeepAlive(oid)
|
|
|
|
runtime.KeepAlive(parents)
|
2013-03-06 09:59:45 -06:00
|
|
|
if ret < 0 {
|
2013-07-07 09:43:44 -05:00
|
|
|
return nil, MakeGitError(ret)
|
2014-06-09 16:19:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return oid, nil
|
|
|
|
}
|
|
|
|
|
2021-09-04 15:49:01 -05:00
|
|
|
// CreateCommitWithSignature creates a commit object from the given contents and
|
|
|
|
// signature.
|
|
|
|
func (v *Repository) CreateCommitWithSignature(
|
|
|
|
commitContent, signature, signatureField string,
|
|
|
|
) (*Oid, error) {
|
|
|
|
cCommitContent := C.CString(commitContent)
|
|
|
|
defer C.free(unsafe.Pointer(cCommitContent))
|
|
|
|
var cSignature *C.char
|
|
|
|
if signature != "" {
|
|
|
|
cSignature = C.CString(string(signature))
|
|
|
|
defer C.free(unsafe.Pointer(cSignature))
|
|
|
|
}
|
|
|
|
var cSignatureField *C.char
|
|
|
|
if signatureField != "" {
|
|
|
|
cSignatureField = C.CString(string(signatureField))
|
|
|
|
defer C.free(unsafe.Pointer(cSignatureField))
|
|
|
|
}
|
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
oid := new(Oid)
|
|
|
|
ret := C.git_commit_create_with_signature(oid.toC(), v.ptr, cCommitContent, cSignature, cSignatureField)
|
|
|
|
|
|
|
|
runtime.KeepAlive(v)
|
|
|
|
runtime.KeepAlive(oid)
|
|
|
|
if ret < 0 {
|
|
|
|
return nil, MakeGitError(ret)
|
|
|
|
}
|
|
|
|
|
|
|
|
return oid, nil
|
|
|
|
}
|
|
|
|
|
2021-09-04 15:04:58 -05:00
|
|
|
// CreateCommitBuffer creates a commit and write it into a buffer.
|
|
|
|
func (v *Repository) CreateCommitBuffer(
|
|
|
|
author, committer *Signature,
|
|
|
|
messageEncoding MessageEncoding,
|
|
|
|
message string,
|
|
|
|
tree *Tree,
|
|
|
|
parents ...*Commit,
|
|
|
|
) ([]byte, error) {
|
|
|
|
cmsg := C.CString(message)
|
|
|
|
defer C.free(unsafe.Pointer(cmsg))
|
|
|
|
var cencoding *C.char
|
|
|
|
// Since the UTF-8 encoding is the default, pass in nil whenever UTF-8 is
|
|
|
|
// provided. That will cause the commit to not have an explicit header for
|
|
|
|
// it.
|
|
|
|
if messageEncoding != MessageEncodingUTF8 && messageEncoding != MessageEncoding("") {
|
|
|
|
cencoding = C.CString(string(messageEncoding))
|
|
|
|
defer C.free(unsafe.Pointer(cencoding))
|
|
|
|
}
|
|
|
|
|
|
|
|
var cparents []*C.git_commit = nil
|
|
|
|
var parentsarg **C.git_commit = nil
|
|
|
|
|
|
|
|
nparents := len(parents)
|
|
|
|
if nparents > 0 {
|
|
|
|
cparents = make([]*C.git_commit, nparents)
|
|
|
|
for i, v := range parents {
|
|
|
|
cparents[i] = v.cast_ptr
|
|
|
|
}
|
|
|
|
parentsarg = &cparents[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
authorSig, err := author.toC()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer C.git_signature_free(authorSig)
|
|
|
|
|
|
|
|
committerSig, err := committer.toC()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer C.git_signature_free(committerSig)
|
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
var buf C.git_buf
|
|
|
|
defer C.git_buf_dispose(&buf)
|
|
|
|
ret := C.git_commit_create_buffer(
|
|
|
|
&buf, v.ptr,
|
|
|
|
authorSig, committerSig,
|
|
|
|
cencoding, cmsg, tree.cast_ptr, C.size_t(nparents), parentsarg)
|
|
|
|
|
|
|
|
runtime.KeepAlive(v)
|
|
|
|
runtime.KeepAlive(buf)
|
|
|
|
runtime.KeepAlive(parents)
|
|
|
|
if ret < 0 {
|
|
|
|
return nil, MakeGitError(ret)
|
|
|
|
}
|
|
|
|
|
|
|
|
return C.GoBytes(unsafe.Pointer(buf.ptr), C.int(buf.size)), nil
|
|
|
|
}
|
|
|
|
|
2018-08-17 19:46:30 -05:00
|
|
|
func (v *Repository) CreateCommitFromIds(
|
|
|
|
refname string, author, committer *Signature,
|
|
|
|
message string, tree *Oid, parents ...*Oid) (*Oid, error) {
|
|
|
|
|
|
|
|
oid := new(Oid)
|
|
|
|
|
|
|
|
var cref *C.char
|
|
|
|
if refname == "" {
|
|
|
|
cref = nil
|
|
|
|
} else {
|
|
|
|
cref = C.CString(refname)
|
|
|
|
defer C.free(unsafe.Pointer(cref))
|
|
|
|
}
|
|
|
|
|
|
|
|
cmsg := C.CString(message)
|
|
|
|
defer C.free(unsafe.Pointer(cmsg))
|
|
|
|
|
|
|
|
var parentsarg **C.git_oid = nil
|
|
|
|
|
|
|
|
nparents := len(parents)
|
|
|
|
if nparents > 0 {
|
2019-01-05 14:13:01 -06:00
|
|
|
// All this awful pointer arithmetic is needed to avoid passing a Go
|
|
|
|
// pointer to Go pointer into C. Other methods (like CreateCommits) are
|
|
|
|
// fine without this workaround because they are just passing Go pointers
|
|
|
|
// to C pointers, but arrays-of-pointers-to-git_oid are a bit special since
|
|
|
|
// both the array and the objects are allocated from Go.
|
|
|
|
var emptyOidPtr *C.git_oid
|
|
|
|
sizeofOidPtr := unsafe.Sizeof(emptyOidPtr)
|
|
|
|
parentsarg = (**C.git_oid)(C.calloc(C.size_t(uintptr(nparents)), C.size_t(sizeofOidPtr)))
|
2018-08-17 19:46:30 -05:00
|
|
|
defer C.free(unsafe.Pointer(parentsarg))
|
|
|
|
parentsptr := uintptr(unsafe.Pointer(parentsarg))
|
|
|
|
for _, v := range parents {
|
|
|
|
*(**C.git_oid)(unsafe.Pointer(parentsptr)) = v.toC()
|
2019-01-05 14:13:01 -06:00
|
|
|
parentsptr += sizeofOidPtr
|
2018-08-17 19:46:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
authorSig, err := author.toC()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer C.git_signature_free(authorSig)
|
|
|
|
|
|
|
|
committerSig, err := committer.toC()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer C.git_signature_free(committerSig)
|
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
ret := C.git_commit_create_from_ids(
|
|
|
|
oid.toC(), v.ptr, cref,
|
|
|
|
authorSig, committerSig,
|
|
|
|
nil, cmsg, tree.toC(), C.size_t(nparents), parentsarg)
|
|
|
|
|
|
|
|
runtime.KeepAlive(v)
|
|
|
|
runtime.KeepAlive(oid)
|
2019-01-07 20:50:42 -06:00
|
|
|
runtime.KeepAlive(tree)
|
2018-08-17 19:46:30 -05:00
|
|
|
runtime.KeepAlive(parents)
|
|
|
|
if ret < 0 {
|
|
|
|
return nil, MakeGitError(ret)
|
|
|
|
}
|
|
|
|
|
|
|
|
return oid, nil
|
|
|
|
}
|
|
|
|
|
2013-03-05 18:43:48 -06:00
|
|
|
func (v *Odb) Free() {
|
|
|
|
runtime.SetFinalizer(v, nil)
|
|
|
|
C.git_odb_free(v.ptr)
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2014-02-24 02:01:47 -06:00
|
|
|
func (v *Refdb) Free() {
|
|
|
|
runtime.SetFinalizer(v, nil)
|
|
|
|
C.git_refdb_free(v.ptr)
|
|
|
|
}
|
|
|
|
|
2013-03-05 13:53:04 -06:00
|
|
|
func (v *Repository) Odb() (odb *Odb, err error) {
|
|
|
|
odb = new(Odb)
|
2013-09-18 02:23:47 -05:00
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2017-07-07 16:45:09 -05:00
|
|
|
ret := C.git_repository_odb(&odb.ptr, v.ptr)
|
|
|
|
runtime.KeepAlive(v)
|
|
|
|
if ret < 0 {
|
2013-07-07 09:43:44 -05:00
|
|
|
return nil, MakeGitError(ret)
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2013-03-05 18:43:48 -06:00
|
|
|
runtime.SetFinalizer(odb, (*Odb).Free)
|
2014-04-03 15:39:21 -05:00
|
|
|
return odb, nil
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2013-03-06 10:16:32 -06:00
|
|
|
func (repo *Repository) Path() string {
|
2017-07-07 16:45:09 -05:00
|
|
|
s := C.GoString(C.git_repository_path(repo.ptr))
|
|
|
|
runtime.KeepAlive(repo)
|
|
|
|
return s
|
2013-03-06 10:16:32 -06:00
|
|
|
}
|
|
|
|
|
2013-11-14 05:08:34 -06:00
|
|
|
func (repo *Repository) IsBare() bool {
|
2017-07-07 16:45:09 -05:00
|
|
|
ret := C.git_repository_is_bare(repo.ptr) != 0
|
|
|
|
runtime.KeepAlive(repo)
|
|
|
|
return ret
|
2013-04-25 17:10:28 -05:00
|
|
|
}
|
|
|
|
|
2013-03-06 13:10:48 -06:00
|
|
|
func (repo *Repository) Workdir() string {
|
2017-07-07 16:45:09 -05:00
|
|
|
s := C.GoString(C.git_repository_workdir(repo.ptr))
|
|
|
|
runtime.KeepAlive(repo)
|
|
|
|
return s
|
2013-03-06 13:10:48 -06:00
|
|
|
}
|
|
|
|
|
2013-03-19 16:54:08 -05:00
|
|
|
func (repo *Repository) SetWorkdir(workdir string, updateGitlink bool) error {
|
|
|
|
cstr := C.CString(workdir)
|
|
|
|
defer C.free(unsafe.Pointer(cstr))
|
|
|
|
|
2013-09-18 02:23:47 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2013-07-07 09:43:44 -05:00
|
|
|
if ret := C.git_repository_set_workdir(repo.ptr, cstr, cbool(updateGitlink)); ret < 0 {
|
|
|
|
return MakeGitError(ret)
|
2013-03-19 16:54:08 -05:00
|
|
|
}
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(repo)
|
2013-07-07 09:43:44 -05:00
|
|
|
|
2013-03-19 16:54:08 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-03-05 13:53:04 -06:00
|
|
|
func (v *Repository) TreeBuilder() (*TreeBuilder, error) {
|
|
|
|
bld := new(TreeBuilder)
|
2013-09-18 02:23:47 -05:00
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2015-01-04 11:05:11 -06:00
|
|
|
if ret := C.git_treebuilder_new(&bld.ptr, v.ptr, nil); ret < 0 {
|
2013-07-07 09:43:44 -05:00
|
|
|
return nil, MakeGitError(ret)
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
2017-07-07 16:45:09 -05:00
|
|
|
|
2013-11-14 05:08:34 -06:00
|
|
|
runtime.SetFinalizer(bld, (*TreeBuilder).Free)
|
2013-03-05 13:53:04 -06:00
|
|
|
|
|
|
|
bld.repo = v
|
|
|
|
return bld, nil
|
|
|
|
}
|
|
|
|
|
2014-03-07 18:43:20 -06:00
|
|
|
func (v *Repository) TreeBuilderFromTree(tree *Tree) (*TreeBuilder, error) {
|
|
|
|
bld := new(TreeBuilder)
|
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2015-01-04 11:05:11 -06:00
|
|
|
if ret := C.git_treebuilder_new(&bld.ptr, v.ptr, tree.cast_ptr); ret < 0 {
|
2014-03-07 18:43:20 -06:00
|
|
|
return nil, MakeGitError(ret)
|
|
|
|
}
|
|
|
|
runtime.SetFinalizer(bld, (*TreeBuilder).Free)
|
|
|
|
|
|
|
|
bld.repo = v
|
|
|
|
return bld, nil
|
|
|
|
}
|
|
|
|
|
2015-03-04 13:32:56 -06:00
|
|
|
type RepositoryState int
|
|
|
|
|
|
|
|
const (
|
|
|
|
RepositoryStateNone RepositoryState = C.GIT_REPOSITORY_STATE_NONE
|
|
|
|
RepositoryStateMerge RepositoryState = C.GIT_REPOSITORY_STATE_MERGE
|
|
|
|
RepositoryStateRevert RepositoryState = C.GIT_REPOSITORY_STATE_REVERT
|
|
|
|
RepositoryStateCherrypick RepositoryState = C.GIT_REPOSITORY_STATE_CHERRYPICK
|
|
|
|
RepositoryStateBisect RepositoryState = C.GIT_REPOSITORY_STATE_BISECT
|
|
|
|
RepositoryStateRebase RepositoryState = C.GIT_REPOSITORY_STATE_REBASE
|
|
|
|
RepositoryStateRebaseInteractive RepositoryState = C.GIT_REPOSITORY_STATE_REBASE_INTERACTIVE
|
|
|
|
RepositoryStateRebaseMerge RepositoryState = C.GIT_REPOSITORY_STATE_REBASE_MERGE
|
|
|
|
RepositoryStateApplyMailbox RepositoryState = C.GIT_REPOSITORY_STATE_APPLY_MAILBOX
|
|
|
|
RepositoryStateApplyMailboxOrRebase RepositoryState = C.GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE
|
|
|
|
)
|
|
|
|
|
|
|
|
func (r *Repository) State() RepositoryState {
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2017-07-07 16:45:09 -05:00
|
|
|
ret := RepositoryState(C.git_repository_state(r.ptr))
|
|
|
|
runtime.KeepAlive(r)
|
|
|
|
|
|
|
|
return ret
|
2015-03-04 13:32:56 -06:00
|
|
|
}
|
2015-03-04 13:38:39 -06:00
|
|
|
|
|
|
|
func (r *Repository) StateCleanup() error {
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
cErr := C.git_repository_state_cleanup(r.ptr)
|
2017-07-07 16:45:09 -05:00
|
|
|
runtime.KeepAlive(r)
|
2015-03-04 13:38:39 -06:00
|
|
|
if cErr < 0 {
|
|
|
|
return MakeGitError(cErr)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2017-07-07 16:45:09 -05:00
|
|
|
|
2015-10-13 10:31:00 -05:00
|
|
|
func (r *Repository) AddGitIgnoreRules(rules string) error {
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
crules := C.CString(rules)
|
|
|
|
defer C.free(unsafe.Pointer(crules))
|
2017-07-07 16:45:09 -05:00
|
|
|
ret := C.git_ignore_add_rule(r.ptr, crules)
|
|
|
|
runtime.KeepAlive(r)
|
|
|
|
if ret < 0 {
|
2015-10-13 10:31:00 -05:00
|
|
|
return MakeGitError(ret)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Repository) ClearGitIgnoreRules() error {
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2017-07-07 16:45:09 -05:00
|
|
|
ret := C.git_ignore_clear_internal_rules(r.ptr)
|
|
|
|
runtime.KeepAlive(r)
|
|
|
|
if ret < 0 {
|
2015-10-13 10:31:00 -05:00
|
|
|
return MakeGitError(ret)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2021-02-02 21:42:21 -06:00
|
|
|
|
|
|
|
// Message retrieves git's prepared message.
|
|
|
|
// Operations such as git revert/cherry-pick/merge with the -n option stop just
|
|
|
|
// short of creating a commit with the changes and save their prepared message
|
|
|
|
// in .git/MERGE_MSG so the next git-commit execution can present it to the
|
|
|
|
// user for them to amend if they wish.
|
|
|
|
//
|
|
|
|
// Use this function to get the contents of this file. Don't forget to remove
|
|
|
|
// the file after you create the commit.
|
|
|
|
func (r *Repository) Message() (string, error) {
|
|
|
|
buf := C.git_buf{}
|
|
|
|
defer C.git_buf_dispose(&buf)
|
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
cErr := C.git_repository_message(&buf, r.ptr)
|
|
|
|
runtime.KeepAlive(r)
|
|
|
|
if cErr < 0 {
|
|
|
|
return "", MakeGitError(cErr)
|
|
|
|
}
|
|
|
|
return C.GoString(buf.ptr), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveMessage removes git's prepared message.
|
|
|
|
func (r *Repository) RemoveMessage() error {
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
cErr := C.git_repository_message_remove(r.ptr)
|
|
|
|
runtime.KeepAlive(r)
|
|
|
|
if cErr < 0 {
|
|
|
|
return MakeGitError(cErr)
|
|
|
|
}
|
2021-04-03 18:52:34 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type RepositoryItem int
|
|
|
|
|
|
|
|
const (
|
|
|
|
RepositoryItemGitDir RepositoryItem = C.GIT_REPOSITORY_ITEM_GITDIR
|
|
|
|
RepositoryItemWorkDir RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKDIR
|
|
|
|
RepositoryItemCommonDir RepositoryItem = C.GIT_REPOSITORY_ITEM_COMMONDIR
|
|
|
|
RepositoryItemIndex RepositoryItem = C.GIT_REPOSITORY_ITEM_INDEX
|
|
|
|
RepositoryItemObjects RepositoryItem = C.GIT_REPOSITORY_ITEM_OBJECTS
|
|
|
|
RepositoryItemRefs RepositoryItem = C.GIT_REPOSITORY_ITEM_REFS
|
|
|
|
RepositoryItemPackedRefs RepositoryItem = C.GIT_REPOSITORY_ITEM_PACKED_REFS
|
|
|
|
RepositoryItemRemotes RepositoryItem = C.GIT_REPOSITORY_ITEM_REMOTES
|
|
|
|
RepositoryItemConfig RepositoryItem = C.GIT_REPOSITORY_ITEM_CONFIG
|
|
|
|
RepositoryItemInfo RepositoryItem = C.GIT_REPOSITORY_ITEM_INFO
|
|
|
|
RepositoryItemHooks RepositoryItem = C.GIT_REPOSITORY_ITEM_HOOKS
|
|
|
|
RepositoryItemLogs RepositoryItem = C.GIT_REPOSITORY_ITEM_LOGS
|
|
|
|
RepositoryItemModules RepositoryItem = C.GIT_REPOSITORY_ITEM_MODULES
|
|
|
|
RepositoryItemWorkTrees RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKTREES
|
|
|
|
)
|
|
|
|
|
|
|
|
func (r *Repository) ItemPath(item RepositoryItem) (string, error) {
|
|
|
|
var c_buf C.git_buf
|
|
|
|
defer C.git_buf_dispose(&c_buf)
|
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
ret := C.git_repository_item_path(&c_buf, r.ptr, C.git_repository_item_t(item))
|
|
|
|
runtime.KeepAlive(r)
|
|
|
|
if ret < 0 {
|
|
|
|
return "", MakeGitError(ret)
|
|
|
|
}
|
|
|
|
return C.GoString(c_buf.ptr), nil
|
2021-02-02 21:42:21 -06:00
|
|
|
}
|