diff --git a/README.md b/README.md index e0e1a1a..fe0c595 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,32 @@ # git-get +## Build + +How to build with libgit2 statically linked into a single executable without dependencies: + +- Install development packages for libssh2 and openssl: + ``` + sudo apt install libssh2-1-del libssl-dev + ``` + +- `git2go` library is added as a submodule (pointing to a correct v30 release). This, in turn, contains `libgit2` submodule. + To ensure the submodules are cloned run: + ``` + git submodule update --init --recursive + ``` + +- build the static `git2go` library: + ``` + cd static/git2go && make install-static + ``` + +- ensure our `git-get` module uses the static `git2go` library instead of the one downloaded by Go modules by having + the following line in `go.mod`: + ``` + replace github.com/libgit2/git2go/v30 => ./static/git2go + ``` + +- build `git-get` with `--tags static` flag: + ``` + go build -i --tags static + ``` diff --git a/git-get.go b/git-get.go new file mode 100644 index 0000000..7366acf --- /dev/null +++ b/git-get.go @@ -0,0 +1,22 @@ +package main + +import ( + "github.com/libgit2/git2go/v30" +) +import "fmt" + +func main() { + options := &git.CloneOptions{ + CheckoutOpts: nil, + FetchOptions: nil, + Bare: false, + CheckoutBranch: "", + RemoteCreateCallback: nil, + } + + repo, err := git.Clone("https://gitlab.com/grdl/dotfiles.git", "/tmp/dotfiles/", options) + if err != nil { + panic(err.Error()) + } + fmt.Println(repo.IsBare()) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..22e17b3 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module git-get + +go 1.14 + +require github.com/libgit2/git2go/v30 v30.0.3 + +replace github.com/libgit2/git2go/v30 => ./static/git2go + diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..57f5668 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/libgit2/git2go/v30 v30.0.3 h1:v+KRMhx85kHS0JzkPft7Wnt3+VUrYQrD/SQ77usTO/w= +github.com/libgit2/git2go/v30 v30.0.3/go.mod h1:YReiQ7xhMoyAL4ISYFLZt+OGqn6xtLqvTC1xJ9oAH7Y=