Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git library for Go

Tags:

git

go

As a pet project, I want to develop a note taking app using git as storage backend. (I suspect this doesn't exist yet, given this guy's blog post: http://jarofgreen.co.uk/2012/08/how-about-a-mobile-note-app-backed-by-git/ )

Now, I'd like to take this as an opportunity to play around with Go a bit. However, I cannot seem to find any (not even the tiniest approach to) git library for Go. Is there actually any?

Obviously my knowledge of Go is non-existant, so writing bindings for libgit doesn't seem a fun way to start... (and I would probably resort to ruby, which I don't know either)

like image 315
vhdirk Avatar asked Nov 23 '12 16:11

vhdirk


People also ask

What is go-git?

go-git is a highly extensible git implementation library written in pure Go. It can be used to manipulate git repositories at low level (plumbing) or high level (porcelain), through an idiomatic Go API.

Is git written in Go?

Go-git is an open-source implementation of Git written in pure Go.

What is git bare repository?

What is a bare repository? A bare repository is the same as default, but no commits can be made in a bare repository. The changes made in projects cannot be tracked by a bare repository as it doesn't have a working tree. A working tree is a directory in which all the project files/sub-directories reside.


4 Answers

I'd say git2go is the git bindings library to use in Go. It is updated regularly and maintained by the people running libgit2.

If you are looking for a git implementation purely written in Go, go-git the most mature and active option.

like image 139
Fernando Á. Avatar answered Sep 18 '22 19:09

Fernando Á.


You can just shell out to git command using os/exec package from Go standard library.

like image 37
Victor Deryagin Avatar answered Sep 20 '22 19:09

Victor Deryagin


Since a few years ago, my team and I, we were coding a pure git implementation in Go, it avoids to have any c/c++ dependency and make it more flexible and easy to extend.

https://github.com/go-git/go-git

go-git aims to reach the completeness of libgit2 or jgit, nowadays covers the majority of the plumbing read operations and some of the main write operations, but lacks the main porcelain operations such as merges.

like image 23
mcuadros Avatar answered Sep 17 '22 19:09

mcuadros


What Victor proposed is indeed the "official" way to "script" Git as envisioned by its developers. Git's commands are divided in the two broad groups specifically for this purpose: the "plumbing" commands are low-level and inteneded mostly to be used by other programs; the "porcelain" command are intended to interact with the user, and call plumbing commands to do their work. Look inside the /usr/lib/git-core directory (might be different on your system) to get the idea of how many plumbing commands Git has.

On the other hand, Go supports linking with shared libraries via its cgo facility. You hence could try wrapping libgit2 with it. AFAIK, libgit2 is not yet fully on par with the Git itself, but it is able to read/write Git repositories, do branching etc — supposedly it will be enough for your task.

Okay, after I wrote all that, I scrolled down the "Bindings" entry on the libgit2's site and found go-git...

like image 20
kostix Avatar answered Sep 19 '22 19:09

kostix