libgit2 / git2go Goto Github PK
View Code? Open in Web Editor NEWGit to Go; bindings for libgit2. Like McDonald's but tastier.
License: MIT License
Git to Go; bindings for libgit2. Like McDonald's but tastier.
License: MIT License
Hi,
I have noticed that the API has changed and I needed to update the code. I would be grateful if you create a "release" or folder every time you change the API.
Thanks
I'm trying to use git2go on Windows 7 x64. I was able to build libgit2 (through mingw) and install git2go package to usual pkg location (pkg\windows_amd64\github.com\libgit2\git2go.a
). But when I try to import github.com/libgit2/git2go
package and build an app I get the following errors:
github.com/libgit2/git2go(.text): git_blame_file: not defined
github.com/libgit2/git2go(.text): git_blame_free: not defined
github.com/libgit2/git2go(.text): git_blame_get_hunk_byindex: not defined
github.com/libgit2/git2go(.text): git_blame_get_hunk_byline: not defined
github.com/libgit2/git2go(.text): git_blame_get_hunk_count: not defined
github.com/libgit2/git2go(.text): git_blame_init_options: not defined
github.com/libgit2/git2go(.text): git_blob_create_frombuffer: not defined
github.com/libgit2/git2go(.text): git_blob_rawcontent: not defined
github.com/libgit2/git2go(.text): git_blob_rawsize: not defined
github.com/libgit2/git2go(.text): git_branch_create: not defined
github.com/libgit2/git2go(.text): git_branch_delete: not defined
github.com/libgit2/git2go(.text): git_branch_is_head: not defined
github.com/libgit2/git2go(.text): git_branch_iterator_free: not defined
github.com/libgit2/git2go(.text): git_branch_iterator_new: not defined
github.com/libgit2/git2go(.text): git_branch_lookup: not defined
github.com/libgit2/git2go(.text): git_branch_move: not defined
github.com/libgit2/git2go(.text): git_branch_name: not defined
github.com/libgit2/git2go(.text): git_branch_next: not defined
github.com/libgit2/git2go(.text): git_branch_remote_name: not defined
github.com/libgit2/git2go(.text): git_branch_set_upstream: not defined
github.com/libgit2/git2go(.text): git_branch_upstream: not defined
Any ideas on how to make it work on Windows?
I'am using : bussiere@kusanagi:~/git2go$ go version
go version go1.2.1 linux/amd64
bussiere@kusanagi:/git2go$ ls/git2go$ go build
blob.go git_test.go patch.go settings.go
branch.go index.go patch_test.go settings_test.go
branch_test.go index_test.go push.go submodule.go
checkout.go LICENSE push_test.go tag.go
clone.go Makefile README.md tag_test.go
clone_test.go merge.go refdb.go tree.go
commit.go merge_test.go reference.go vendor
config.go object.go reference_test.go walk.go
credentials.go object_test.go remote.go wrapper.c
diff.go odb.go remote_test.go
diff_test.go odb_test.go repository.go
git.go packbuilder.go script
bussiere@kusanagi:
37: error: 'git_branch_iterator' undeclared (first use in this function)
37: error: 'git_branch_next' undeclared (first use in this function)
38: error: 'git_buf_free' undeclared (first use in this function)
38: error: 'git_buf' undeclared (first use in this function)
38: error: 'git_branch_iterator_free' undeclared (first use in this function)
38: error: 'git_branch_iterator_new' undeclared (first use in this function)
Hi,
This function is git_repository_head_detached in libgit2's API
https://libgit2.github.com/libgit2/#HEAD/group/repository/git_repository_head_detached
Would be cool to implement git_repository_head_detached
in git2go since I haven't really found any equivalent yet.
Regards,
Hi,
it seems that support for annotated tag objects is missing in git2go. Is this intentional? Shall I try to add it myself?
Regards,
Frank.
ian@debian: go get github.com/libgit2/git2go
# github.com/libgit2/git2go
git.go:14: imported and not used: "fmt"
packbuilder.go:126: no new variables on left side of :=
packbuilder.go:127: no new variables on left side of :=
packbuilder.go:127: cannot use stop (type chan<- bool) as type <-chan bool in field value
packbuilder.go:128: cannot use &data (type *<-chan []byte) as type *packbuilderCbData in function argument
reference.go:154: cannot use &ptr (type **_Ctype_char) as type **[0]byte in function argument
I've fixed the first three of the errors, but I'm not well versed enough in Go to tackle the last few.
Hello,
Is there a way to make a git status, and check if there is any modification on?
I've tried to find a way but until now I have no clue.
Thank you very much.
Hi,
I am intrested in writting a code that creates a local branch and applies a set of changes in that branch. Hence, I need to apply checkout once I have created a branch. I am pretty lost with this API and I haven't found examples in the test files to do that. I will appreciate any help :-)
This is my code and the call LookupTree crashes with the error message "The requested type does not match the type in ODB".
branch, _ := repo.CreateBranch("mybranch", currentTip, true, sig, message)
checkOutOpts := &git.CheckoutOpts{
Strategy: git.CheckoutForce,
FileOpenFlags : os.O_WRONLY,
}
tree, _ := repo.LookupTree(branch.Target())
if err != nil {
fmt.Print(err)
}
repo.CheckoutTree(tree, checkOutOpts)
I haven't found such a go wrapper for git_commit_lookup_prefix
API
While trying to use @carlosmn's go.gitfs I ran into the following error:
.../github.com/carlosmn/go.gitfs# go build
# github.com/carlosmn/go.gitfs
./gitfs.go:94: invalid case git.FilemodeBlob in switch on v.entry.Filemode (mismatched types git.Filemode and int)
./gitfs.go:96: invalid case git.FilemodeTree in switch on v.entry.Filemode (mismatched types git.Filemode and int)
./gitfs.go:174: cannot use git.FilemodeTree (type git.Filemode) as type int in field value
It seems this problem was introduced in change 9bec36a
The following patch fixes it, but I'm not sure if this is how you want to do it: https://gist.github.com/ry/21587c5d66e20ab0d123
Thank you for git2go. Very handy.
While building a Docker container image suitable for building Go apps that could leverage git2go, I ran across something interesting.
The container Dockerfile also happens to include building the Go cross compilers for darwin and windows. If I build the container with this ordering of statements with respect to the cross compilers and git2go
# Environment
ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin:/go/bin
ENV GOPATH /go
# Cross compilers
RUN cd /usr/local/go/src && GOOS=darwin GOARCH=amd64 ./make.bash --no-clean
RUN cd /usr/local/go/src && GOOS=windows GOARCH=amd64 ./make.bash --no-clean
# libgit2/git2go C binding
RUN go get -d -u -v github.com/libgit2/git2go && cd /go/src/github.com/libgit2/git2go && git submodule update --init && make test install
the resulting Go environment can successfully build a sample Go app that uses the git2go library.
However, if I reverse the order of building the cross compilers with the building of git2go, I cannot build the sample app. The sample app build in this case fails with
root@e98ffd5673af:/go/src/t# go build
# github.com/libgit2/git2go
../github.com/libgit2/git2go/blame.go:4:18: fatal error: git2.h: No such file or directory
#include <git2.h>
^
compilation terminated.
I don't know the reason for this, but wanted to make the observation here.
I followed the Readme and this is the error I got after running make install.
Undefined symbols for architecture x86_64:
"_deflateEnd", referenced from:
_git_filebuf_cleanup in libgit2.a(filebuf.c.o)
_git_zstream_free in libgit2.a(zstream.c.o)
_git_zstream_deflatebuf in libgit2.a(zstream.c.o)
"_deflate", referenced from:
_write_deflate in libgit2.a(filebuf.c.o)
_git_zstream_get_output in libgit2.a(zstream.c.o)
(maybe you meant: _git_zstream_deflatebuf)
"_deflateInit_", referenced from:
_git_filebuf_open in libgit2.a(filebuf.c.o)
_git_zstream_init in libgit2.a(zstream.c.o)
_git_zstream_deflatebuf in libgit2.a(zstream.c.o)
"_SSL_load_error_strings", referenced from:
_init_once in libgit2.a(global.c.o)
"_SSL_library_init", referenced from:
_init_once in libgit2.a(global.c.o)
"_SSLv23_method", referenced from:
_init_once in libgit2.a(global.c.o)
"_SSL_CTX_new", referenced from:
_init_once in libgit2.a(global.c.o)
"_SSL_CTX_ctrl", referenced from:
_init_once in libgit2.a(global.c.o)
"_SSL_CTX_set_verify", referenced from:
_init_once in libgit2.a(global.c.o)
"_SSL_CTX_set_default_verify_paths", referenced from:
_init_once in libgit2.a(global.c.o)
"_SSL_CTX_free", referenced from:
_init_once in libgit2.a(global.c.o)
"_CRYPTO_num_locks", referenced from:
_init_once in libgit2.a(global.c.o)
"_CRYPTO_set_locking_callback", referenced from:
_init_once in libgit2.a(global.c.o)
"_crc32", referenced from:
_crc_object in libgit2.a(indexer.c.o)
_git_indexer_commit in libgit2.a(indexer.c.o)
"_SSL_get_error", referenced from:
_ssl_set_error in libgit2.a(netops.c.o)
_gitno__recv_ssl in libgit2.a(netops.c.o)
"_ERR_get_error", referenced from:
_ssl_set_error in libgit2.a(netops.c.o)
"_ERR_error_string", referenced from:
_ssl_set_error in libgit2.a(netops.c.o)
"_SSL_shutdown", referenced from:
_gitno_close in libgit2.a(netops.c.o)
"_SSL_free", referenced from:
_gitno_close in libgit2.a(netops.c.o)
"_SSL_write", referenced from:
_gitno_send in libgit2.a(netops.c.o)
"_SSL_read", referenced from:
_gitno__recv_ssl in libgit2.a(netops.c.o)
"_SSL_new", referenced from:
_gitno_connect in libgit2.a(netops.c.o)
"_SSL_set_fd", referenced from:
_gitno_connect in libgit2.a(netops.c.o)
"_SSL_connect", referenced from:
_gitno_connect in libgit2.a(netops.c.o)
"_SSL_get_verify_result", referenced from:
_gitno_connect in libgit2.a(netops.c.o)
"_SSL_get_peer_certificate", referenced from:
_gitno_connect in libgit2.a(netops.c.o)
"_X509_get_ext_d2i", referenced from:
_gitno_connect in libgit2.a(netops.c.o)
"_GENERAL_NAMES_free", referenced from:
_gitno_connect in libgit2.a(netops.c.o)
"_sk_num", referenced from:
_gitno_connect in libgit2.a(netops.c.o)
"_sk_value", referenced from:
_gitno_connect in libgit2.a(netops.c.o)
"_ASN1_STRING_data", referenced from:
_gitno_connect in libgit2.a(netops.c.o)
"_ASN1_STRING_length", referenced from:
_gitno_connect in libgit2.a(netops.c.o)
"_X509_get_subject_name", referenced from:
_gitno_connect in libgit2.a(netops.c.o)
"_X509_NAME_get_index_by_NID", referenced from:
_gitno_connect in libgit2.a(netops.c.o)
"_X509_NAME_get_entry", referenced from:
_gitno_connect in libgit2.a(netops.c.o)
"_X509_NAME_ENTRY_get_data", referenced from:
_gitno_connect in libgit2.a(netops.c.o)
"_ASN1_STRING_type", referenced from:
_gitno_connect in libgit2.a(netops.c.o)
"_CRYPTO_malloc", referenced from:
_gitno_connect in libgit2.a(netops.c.o)
"_ASN1_STRING_to_UTF8", referenced from:
_gitno_connect in libgit2.a(netops.c.o)
"_CRYPTO_free", referenced from:
_gitno_connect in libgit2.a(netops.c.o)
"_SHA1_Update", referenced from:
_git_odb_stream_write in libgit2.a(odb.c.o)
_git_odb_open_wstream in libgit2.a(odb.c.o)
_git_odb__hashfd in libgit2.a(odb.c.o)
_write_one in libgit2.a(pack-objects.c.o)
_write_pack in libgit2.a(pack-objects.c.o)
_write_normal in libgit2.a(filebuf.c.o)
_write_deflate in libgit2.a(filebuf.c.o)
...
"_SHA1_Final", referenced from:
_git_odb_stream_finalize_write in libgit2.a(odb.c.o)
_git_odb__hashfd in libgit2.a(odb.c.o)
_write_pack in libgit2.a(pack-objects.c.o)
_git_filebuf_hash in libgit2.a(filebuf.c.o)
_git_hash_buf in libgit2.a(hash.c.o)
_git_hash_vec in libgit2.a(hash.c.o)
_git_indexer_commit in libgit2.a(indexer.c.o)
...
"_SHA1_Init", referenced from:
_git_odb_open_wstream in libgit2.a(odb.c.o)
_git_odb__hashfd in libgit2.a(odb.c.o)
_git_packbuilder_new in libgit2.a(pack-objects.c.o)
_git_filebuf_open in libgit2.a(filebuf.c.o)
_git_hash_buf in libgit2.a(hash.c.o)
_git_hash_vec in libgit2.a(hash.c.o)
_git_indexer_commit in libgit2.a(indexer.c.o)
...
"_inflateInit_", referenced from:
_loose_backend__read_header in libgit2.a(odb_loose.c.o)
_read_loose in libgit2.a(odb_loose.c.o)
_packfile_unpack_compressed in libgit2.a(pack.c.o)
_git_packfile_stream_open in libgit2.a(pack.c.o)
"_inflate", referenced from:
_loose_backend__read_header in libgit2.a(odb_loose.c.o)
_read_loose in libgit2.a(odb_loose.c.o)
_git_packfile_stream_read in libgit2.a(pack.c.o)
_packfile_unpack_compressed in libgit2.a(pack.c.o)
"_inflateEnd", referenced from:
_loose_backend__read_header in libgit2.a(odb_loose.c.o)
_read_loose in libgit2.a(odb_loose.c.o)
_packfile_unpack_compressed in libgit2.a(pack.c.o)
_git_packfile_stream_free in libgit2.a(pack.c.o)
"_iconv", referenced from:
_git_path_iconv in libgit2.a(path.c.o)
(maybe you meant: _git_path_iconv_init_precompose, _git_path_iconv_clear , _git_path_iconv )
"_iconv_close", referenced from:
_git_path_iconv_clear in libgit2.a(path.c.o)
_git_path_dirload in libgit2.a(path.c.o)
_git_path_direach in libgit2.a(path.c.o)
"_iconv_open", referenced from:
_git_path_iconv_init_precompose in libgit2.a(path.c.o)
_git_path_dirload in libgit2.a(path.c.o)
_git_path_direach in libgit2.a(path.c.o)
"_deflateReset", referenced from:
_git_zstream_reset in libgit2.a(zstream.c.o)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [install] Error 2
I am following the readme and everything worked fine till make install
. However, when running make test
I run into the following errors :
# testmain
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
github.com/libgit2/git2go(__TEXT/__text): adddynsym: missed symbol git_buf__oom (git_buf__oom)
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
github.com/libgit2/git2go(__TEXT/__text): unexpected GOT reloc for non-dynamic symbol git_buf__oom
too many errors
FAIL github.com/libgit2/git2go [build failed]
Some of the logs from running make build
and make test
-- The C compiler identification is GNU 4.9.1
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Check for working C compiler: /usr/local/bin/cc
-- Check for working C compiler: /usr/local/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Found OpenSSL: /usr/lib/libssl.dylib;/usr/lib/libcrypto.dylib (found version "0.9.8y")
-- Could NOT find HTTP_Parser (missing: HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY)
-- http-parser was not found or is too old; using bundled 3rd-party sources.
-- Found ZLIB: /usr/lib/libz.dylib (found version "1.2.5")
-- Found Iconv: -L/usr/lib -liconv
-- Performing Test IS_WNO-MISSING-FIELD-INITIALIZERS_SUPPORTED
-- Performing Test IS_WNO-MISSING-FIELD-INITIALIZERS_SUPPORTED - Success
....
....
-- Performing Test IS_WNO-UNUSED-CONST-VARIABLE_SUPPORTED - Failed
...
...
- Looking for clock_gettime in rt
-- Looking for clock_gettime in rt - not found
-- Configuring done
...
...
...
/usr/bin/ranlib: file: libgit2.a(winhttp.c.o) has no symbols
/usr/bin/ranlib: file: libgit2.a(realpath.c.o) has no symbols
/usr/bin/ranlib: file: libgit2.a(winhttp.c.o) has no symbols
/usr/bin/ranlib: file: libgit2.a(realpath.c.o) has no symbols
...
...
Was working prior to go 1.4
$ git pull
$ make install
...
could not determine kind of name for C.git_push_unpack_ok
Forgive me if this has already been addressed, but I don't quite understand how to use this binding in a serious project. Without tagged releases, I can't figure out how to use it against a stable version of libgit2. Is it not considered production-ready? Am I missing something?
I'm still getting familiar with git2go and libgit2, but I did some digging and it seems git_clone()
already does deallocate git_repository
: https://github.com/libgit2/libgit2/blob/development/src/clone.c#L425. So, having this finalizer seems unnecessary: https://github.com/libgit2/git2go/blob/make-static/clone.go#L53
When I install libgit2 using homebrew and then try to go build
git2go I get the following error:
# github.com/libgit2/git2go
37: error: use of undeclared identifier 'git_remote_create_cb'; did you mean 'git_remote_create'?
I see there is a branch with Remote support. It would be nice to be able to push to them as well.
Hi, it seems the git status is not implemented in git2go. It exists in libgit2... do you intend to implement it?
Reference:
https://libgit2.github.com/libgit2/#HEAD/group/status
The docs for git_submodule_*
funcs say "You must call git_submodule_free
when done with the submodule.โ However, git2goโs Submodule type doesnโt have a method to free itself. There should be one. I can submit a PR for this soon.
When I attempt to add a global config file using conf.AddFile(path, git.ConfigLevelGlobal, false)
and that file has an [include] section with a file pointing to ~/.gitconfig.local
, I receive the following error: The global file '/.gitconfig.local' doesn't exist: No such file or directory
. It seems that maybe it is looking for it in root instead of expanding ~ as $HOME?
Is this a user error, git2go or libgit2?
I pulled down libgit2/libgit2. The development branch is on 12f831fa1500bdcd1b9a2ef20c4897904983af8e currently. When I try to run this:
# github.com/libgit2/git2go
blob.go:3:18: error: git2.h: No such file or directory
blob.go:4:25: error: git2/errors.h: No such file or directory
All I'm doing is importing the library:
package main
import (
_ "github.com/libgit2/git2go"
"fmt"
)
func Main() {
fmt.Println("HI")
}
EDIT: I'm running go like so:
$ PKG_CONFIG_PATH=/Users/rick/p/libgit2/build go run main.go
Tried to go get latest git2go on my archlinux
-> % go get github.com/libgit2/git2go
1: error: 'git_packbuilder_insert_commit' undeclared (first use in this function)
1: note: each undeclared identifier is reported only once for each function it appears in
But got the errors above. I got libgit2 0.18.0-1, go 1.1.1
Greets.
The following functions (and possibly more) do not perform thread locking despite calling MakeGitError:
Thanks to @carlosmn for the pointer at #136 (comment).
For context, it's necessary to lock the OS thread because giterr_last
returns the last error object generated for the current thread.
If it'd be helpful, I could throw together a quick lint script using go/ast to add to Travis CI that would warn about funcs that call MakeGitError that don't contain:
runtime.LockOSThread()
defer runtime.UnlockOSThread()
It seems the git reset
is not implemented in git2go. As it exists in libgit2 [1], why it's not in git2go ?
$ go get github.com/libgit2/git2go
# github.com/libgit2/git2go
Undefined symbols for architecture x86_64:
"_git_blob_create_frombuffer", referenced from:
__cgo_bc0973baa668_Cfunc_git_blob_create_frombuffer in blob.cgo2.o
(maybe you meant: __cgo_bc0973baa668_Cfunc_git_blob_create_frombuffer)
"_git_blob_create_fromchunks", referenced from:
__go_git_blob_create_fromchunks in wrapper.o
(maybe you meant: __cgo_bc0973baa668_Cfunc__go_git_blob_create_fromchunks, __go_git_blob_create_fromchunks )
"_git_blob_rawcontent", referenced from:
__cgo_bc0973baa668_Cfunc_git_blob_rawcontent in blob.cgo2.o
(maybe you meant: __cgo_bc0973baa668_Cfunc_git_blob_rawcontent)
"_git_blob_rawsize", referenced from:
__cgo_bc0973baa668_Cfunc_git_blob_rawsize in blob.cgo2.o
(maybe you meant: __cgo_bc0973baa668_Cfunc_git_blob_rawsize)
.... full output here: https://gist.github.com/mattes/2511e7f3210bc2ec3300 ....
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
$ go version
go version go1.3 darwin/amd64
$ cmake --version
cmake version 3.0.0
$ pkg-config --version
0.28
Mac osx v. 10.9.4
Any plans on adding packbuilder support?
When trying to compile git2go I get the following error:
cannot load DWARF output from $WORK/github.com/libgit2/git2go/_obj//_cgo_.o: decoding dwarf section info at offset 0x0: too short
This can be replicated by building my repo (which uses libgit2) on a mac from homebrew using:
$ brew install jwaldrip/utils/git-get -v --HEAD
The formula can be viewed at:
https://github.com/jwaldrip/homebrew-utils/blob/master/git-get.rb
The Makefile the formula uses at:
https://github.com/jwaldrip/git-get/blob/master/Makefile
Hi,
would be cool to implement
git_repository_set_head
git_repository_set_head_detached
since I haven't really found any other sane way how to perform a checkout or a merge without these. Both Repository.CheckoutHead
and Repository.Merge
depend on HEAD
.
Hope that I am not saying complete bullshit, it's 3am and I am brain-dead.
Regards,
Ondrej Kupka
fedora: 20
go:1.1
libgit2: f28e4c97b38c1ec60dc6ce6e5306067ad24aeb8e (Tue Apr 1 2014)
git2go: 9cd1d12
I have a issue with the Reference.IsTag() method which appears to be unimplemented but Reference.IsBranch() works. I have checked the code base in both libgit2 and git2go and they bothe appear to be implemented the same.
git2go_play --repo ~/git/testrepo/
&{0x8ec2d0}
git2go_play: symbol lookup error: git2go_play: undefined symbol: git_reference_is_tag
Sample code
package main
import (
"github.com/libgit2/git2go"
"fmt"
"log"
"flag"
)
func main(){
repoPath := flag.String("repo", "~/git/testrepo", "path to the git repository")
flag.Parse()
repo, err := git.OpenRepository(*repoPath)
if err != nil {
log.Fatal(err)
}
fmt.Println(repo)
refs, err := repo.NewReferenceIterator()
if err != nil {
log.Fatal(err)
}
for ref := range refs.Iter() {
msg := ""
if ref.IsBranch() {
msg += "IsBranch"
}
if ref.IsTag() {
msg += "IsTag"
}
if ref.IsRemote(){
msg += "IsRemote"
}
fmt.Printf("%s: %s\n", msg, ref.Name())
}
}
Hi all,
Just this question, in the Go binding, is there a way to implement the git-upload-pack ?
Thank you
On Mac OSX, I run the following:
> brew install libgit2 --HEAD
# ... installs successfully from branch development
> go get github.com/libgit2/git2go
# # github.com/libgit2/git2go
# Godeps/_workspace/src/github.com/libgit2/git2go/wrapper.c:34:13: error: no member named 'progress' in 'struct git_remote_callbacks'
Also seems to be affecting my Travis CI builds: example
When I try to clone a specific tag, I run something like this:
git clone --branch v1.0.0 https://github.com/ministryofjustice/supervisor-formula.git vendor/supervisor
The above command succeeds without any hiccups.
I figured I could write a go func like below.
func CloneRepo(url string, tag string, path string) error {
opts := git.CloneOptions{
CheckoutBranch: tag,
}
repo, err := git.Clone(url, path, &opts)
if err != nil {
return err
}
fmt.Println(repo)
return nil
}
However, I'm getting the following error:
Failed to clone https://github.com/ministryofjustice/supervisor-formula.git Reference 'refs/remotes/origin/v1.0.0' not found
I'm guessing this is a lack of knowledge on my side, but I'm wondering whether I can accomplish something like this using the git package ?
Right now, this package requires custom manual steps for its installation:
Run
go get -d github.com/libgit2/git2go
to download the code and go to your$GOPATH/src/github.com/libgit2/git2go
dir. From there, we need to build the C code and put it into the resulting go binary.git submodule update --init # get libgit2 make install
will compile libgit2 and run
go install
such that it's statically linked to the git2go package.
This is inconvenient, it makes it harder to get than other Go packages (which are just go get
). Worst of all, this means that any other Go package that imports this one, even if the upstream package is completely go gettable, will no longer be 1 command to install.
I think it may be possible for you to change that, and thus improve the experience of anyone using this packages, and make it easy for others to import it and no incur the cost of manual dependency installation steps.
The way you can do that would be similar to how we did it with glfw3 package (currently on a branch, to be merged into master once GLFW 3.1 is released), which is a Go binding for a C library. It was discovered by @slimsag and you can see the discussion in the following issue and PR:
The general idea is that you vendor the C library source in a subfolder (potentially as a git submodule) and use cgo directives to link to it. Basically, everything you're doing now, except without needing the Makefile and scripts.
The main consideration is that you will need to replace the function of CMake with multiple .go files with build tags (which may require some work and maintenance), which is what we've done in glfw3:
Less configurable? Unable to modify CMAKE parameters?
Actually -- We can make build tags for any CMAKE configurable feature that we want (e.g. tell people to compile their application with
go install -tags "wayland" my/pkg
and a wayland client will be built instead of an X11 one, you can see how I did this here: https://github.com/go-gl/glfw3/blob/devel_glfw3.1/build.go)
But the end result is a go gettable package that is much easier for users. Just imagine:
To install
git2go
, rungo get -u github.com/libgit2/git2go
. Done.
What do you think? If this is something you're amendable to, I can assist with questions/answers about the approach and potentially try to make a PR.
After upgrading from go1.3 to go1.4, I'd get a runtime crash most of the time. It crashes for various reasons (nil tree walker callback, invalid heap pointer...). Here is a scaled down version of the code that demonstrates the problem (runtime crashes most of the time). Run this code with an argument pointing at a git repository like git2go.
package main
import (
"fmt"
"github.com/libgit2/git2go"
"os"
"strings"
)
type MyRepo struct {
*git.Repository
}
func (repository *MyRepo) foo(path string, treeEntry *git.TreeEntry) int {
if git.ObjectBlob != treeEntry.Type {
return 0 // continue
}
if !strings.HasSuffix(treeEntry.Name, ".go") {
return 0 // continue
}
blob, err := repository.Repository.LookupBlob(treeEntry.Id)
defer blob.Free()
if err != nil {
panic(err)
}
if blob.Size() > 10000 {
return 0 // continue
}
contents := blob.Contents()
if contents == nil {
panic("nil contents")
}
fmt.Printf("%q", path, treeEntry.Name, string(contents))
fmt.Println()
return 0 // continue
}
func main() {
filename := os.Args[1]
repository, err := git.OpenRepository(filename)
if err != nil {
panic(err)
}
defer repository.Free()
myRepo := MyRepo{repository}
revWalk, err := repository.Walk()
if err != nil {
panic(err)
}
defer revWalk.Free()
// Start out at the head
err = revWalk.PushHead()
if err != nil {
panic(err)
}
err = revWalk.Iterate(func(commit *git.Commit) bool {
defer commit.Free()
tree, err := commit.Tree()
if err != nil {
panic(err)
}
defer tree.Free()
err = tree.Walk(myRepo.foo)
if err != nil {
panic(err)
}
return true
})
if err != nil {
panic(err)
}
}
Some errors that come from the above code:
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x40f4299]
goroutine 1 [running]:
github.com/libgit2/git2go.CallbackGitTreeWalk(0x438a520, 0x51008e0, 0xc208071e40, 0x0)
/Users/maleticm/.gvm/pkgsets/go1.4/jack/src/github.com/libgit2/git2go/tree.go:99 +0x79
github.com/libgit2/git2go._Cfunc__go_git_treewalk(0x5100850, 0x0, 0xc208069e40, 0x0)
/Users/maleticm/.gvm/pkgsets/go1.4/jack/src/github.com/libgit2/git2go/:402 +0x43
github.com/libgit2/git2go.Tree.Walk(0x5100850, 0xc20802c018, 0x5100850, 0xc208069e80, 0x0, 0x0)
runtime: garbage collector found invalid heap pointer *(0xc208069cd0+0x10)=0xc208083e40 span=0xc20807e000-0xc208083800-0xc208084000 state=0
fatal error: invalid heap pointer
runtime stack:
runtime.throw(0x437df83)
/Users/maleticm/.gvm/gos/go1.4/src/runtime/panic.go:491 +0xad fp=0x7fff5fbfea18 sp=0x7fff5fbfe9e8
scanblock(0xc208069cd0, 0x20, 0x42c12e4)
/Users/maleticm/.gvm/gos/go1.4/src/runtime/mgc0.c:378 +0x551 fp=0x7fff5fbfeb58 sp=0x7fff5fbfea18
scanframe(0x7fff5fbfec60, 0x0, 0x1)
/Users/maleticm/.gvm/gos/go1.4/src/runtime/mgc0.c:740 +0x1c2 fp=0x7fff5fbfebc8 sp=0x7fff5fbfeb58
unexpected fault address 0xb01dfacedebac1e
fatal error: fault
[signal 0xb code=0x1 addr=0xb01dfacedebac1e pc=0x40f4299]
goroutine 1 [running, locked to thread]:
runtime.gothrow(0x426ec90, 0x5)
/Users/maleticm/.gvm/gos/go1.4/src/runtime/panic.go:503 +0x8e fp=0xc208069c40 sp=0xc208069c28
runtime.sigpanic()
/Users/maleticm/.gvm/gos/go1.4/src/runtime/sigpanic_unix.go:29 +0x261 fp=0xc208069c90 sp=0xc208069c40
github.com/libgit2/git2go.CallbackGitTreeWalk(0x438a520, 0x5009680, 0xc208073e40, 0x0)
Hi team!
I am creating a funny library with git2go/libgit2: gitql. But I think that set $LD_LIBRARY_PATH everytime before run it is a bad idea ๐
I would like know if there is other way because set that variable globally seems bad too
Thanks!
And congrats for this bind! ๐
The functionality to list remote tracking branches like "got br -a"?
$ git br -a
master
remotes/mirror/v1.0
remotes/mirror/v1.5
remotes/mirror/v2.0
Thanks!
Hi, when I call Repository.CreateBlobFromBuffer
with an empty buffer as argument, I get the following trace:
panic: runtime error: index out of range [recovered]
panic: runtime error: index out of range
goroutine 6 [running]:
runtime.panic(0x5e8620, 0x9bc217)
/usr/local/go/src/pkg/runtime/panic.c:266 +0xb6
testing.funcยท005()
/usr/local/go/src/pkg/testing/testing.go:385 +0xe8
runtime.panic(0x5e8620, 0x9bc217)
/usr/local/go/src/pkg/runtime/panic.c:248 +0x106
github.com/libgit2/git2go.(*Repository).CreateBlobFromBuffer(0xc2100002b0, 0x0, 0x0, 0x0, 0x0, ...)
/home/dev/go/src/github.com/libgit2/git2go/blob.go:40 +0x132
[...]
I'm building from ce7a12d
Now that libgit2/libgit2#2592 has been merged ๐
I edit checkout.go and add CheckoutTree method blow, but I don't know why the repo didn't changed after successful execute it.
func (v *Repository) CheckoutTree(treeish string, opts *CheckoutOpts) error {
var copts C.git_checkout_options
ptr := populateCheckoutOpts(&copts, opts)
obj, err := v.RevparseSingle(treeish)
if err != nil {
return err
}
defer obj.Free()
commit, err := v.LookupCommit(obj.Id())
if err != nil {
return err
}
tree, err := commit.Tree()
if err != nil {
return err
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_checkout_tree(v.ptr, tree.ptr, ptr)
if ret < 0 {
return MakeGitError(ret)
}
return nil
}
Hi, I am using arch linux and I am trying to go get git2go and I am having the next errors:
โ build git:(development) go get github.com/libgit2/git2go
# github.com/libgit2/git2go
1: error: 'GIT_CHECKOUT_NONE' undeclared (first use in this function)
1: error: 'GIT_CHECKOUT_SAFE_CREATE' undeclared (first use in this function)
1: error: 'GIT_CHECKOUT_DONT_UPDATE_INDEX' undeclared (first use in this function)
1: error: 'GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED' undeclared (first use in this function)
1: error: 'git_checkout_opts' undeclared (first use in this function)
1: error: 'git_checkout_head' undeclared (first use in this function)
1: error: 'GIT_CHECKOUT_FORCE' undeclared (first use in this function)
1: error: 'GIT_CHECKOUT_NO_REFRESH' undeclared (first use in this function)
1: error: 'GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH' undeclared (first use in this function)
1: error: 'GIT_CHECKOUT_SKIP_UNMERGED' undeclared (first use in this function)
1: error: 'GIT_CHECKOUT_USE_OURS' undeclared (first use in this function)
1: error: 'GIT_CHECKOUT_REMOVE_UNTRACKED' undeclared (first use in this function)
1: error: 'GIT_CHECKOUT_UPDATE_ONLY' undeclared (first use in this function)
1: error: 'git_checkout_index' undeclared (first use in this function)
1: error: 'GIT_CHECKOUT_SAFE' undeclared (first use in this function)
1: error: 'GIT_CHECKOUT_ALLOW_CONFLICTS' undeclared (first use in this function)
1: error: 'GIT_CHECKOUT_REMOVE_IGNORED' undeclared (first use in this function)
1: error: 'GIT_CHECKOUT_USE_THEIRS' undeclared (first use in this function)
1: error: 'GIT_CHECKOUT_UPDATE_SUBMODULES' undeclared (first use in this function)
I am using the latest libgit2 development branch (according to the day of posting this issue). What should I do?
I read in another issue that libgit2 via homebrew won't help, but if I don't have it installed with homebrew, then this: go get github.com/libgit2/git2go
produces:
# github.com/libgit2/git2go
./blob.go:4:10: fatal error: 'git2.h' file not found
#include <git2.h>
^
1 error generated.
but if I install libgit2 with homebrew then this step works but at make
step I get make: *** [install] Error 2
but no errors are reported above this line... confusing :( Any tips?
I've been trying (unsuccessfully so far) to use git2go to push changes from my local repo to a github repo.
Here is the gist containing the code I am using for now.
So while HTTPS works for cloning the remote repo I can't get it working for pushing. None of the error checks report anything but still the push does not go through
I've looked at the documentation of both git2go and libgit2, tests in the git2go repo and related questions on stack overflow and seem to be on the prescribed track but can't figure out exactly what's wrong with my implementation.
As this is the first location to learn about git2go , I'm posting it here as well in case it will help others.
Thanks !
For instance this commit, which is a breaking change :
It has been applied in git2go here (9c72700) and here (42fce02).
But on my machine I installed the standard version of libgit2 where the breaking change is not shipped, so I can't use git2go... Or I have to download the libgit2 sources and build them.
In case you missed it, I found this Linus comment about this libgit2 change in the subsurface mailing list :)
I'm seeing this when trying to test git2go @ 5eda8d6:
38: error: 'git_remote_check_cert' undeclared (first use in this function)
This is sourced from https://github.com/libgit2/git2go/blob/master/remote.go#L131 and does not have a corresponding entry anywhere in the libgit2 source (headers or C files).
Is this me or you? :) I'm not sure, I'm new to this project.
When building on Mac OSX I get the following error:
I am using the built in make install command which uses: script/build-libgit2-static.sh
$ make install
./script/build-libgit2-static.sh
+ VENDORED_PATH=vendor/libgit2
+ cd vendor/libgit2
+ mkdir -p install/lib
+ mkdir -p build
+ cd build
+ cmake -DTHREADSAFE=ON -DBUILD_CLAR=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS=-fPIC -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=../install ..
-- Could NOT find HTTP_Parser (missing: HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY)
-- http-parser was not found or is too old; using bundled 3rd-party sources.
-- Found Iconv: -L/usr/lib -liconv
CMake Error at /usr/local/Cellar/cmake/3.0.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:136 (message):
Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.0.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:343 (_FPHSA_FAILURE_MESSAGE)
/usr/local/Cellar/cmake/3.0.2/share/cmake/Modules/FindThreads.cmake:178 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:372 (FIND_PACKAGE)
-- Configuring incomplete, errors occurred!
See also "/Users/jwaldrip/dev/src/github.com/libgit2/git2go/vendor/libgit2/build/CMakeFiles/CMakeOutput.log".
See also "/Users/jwaldrip/dev/src/github.com/libgit2/git2go/vendor/libgit2/build/CMakeFiles/CMakeError.log".
make: *** [build-libgit2] Error 1
and now git2go is unable to build
$ go get github.com/libgit2/git2go
packbuilder.go:71: not enough arguments in call to _Cfunc_git_packbuilder_write
libgit2 version: 9d4db41a
Maybe should check set ptr = nil after git free and guard Free logic with ptr != nil to make sure it doesn't try to free invalid pointers?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.