Elixir libgit2 wrapper with GenServer-based concurrent access and Git wire protocol (push/fetch).
Originally created by Mario Flach (@redrabbit) as part of git.limo. Extracted and updated by @jtippett. Extended with Git wire protocol support and maintained by Sergey Moiseev.
libgit2 must be installed on your system:
brew install libgit2 # macOS
sudo apt-get install libgit2-dev # Ubuntu/Linux{:ex_git_engine, "~> 0.9"}Three abstraction layers:
ExGitEngine.Git— direct Erlang NIF bindings to libgit2ExGitEngine.GitAgent— GenServer API with caching and safe concurrent accessExGitEngine.GitRepo— protocol for extensible repository implementations with push/fetch hooks
Wire protocol:
ExGitEngine.WireProtocol— Git transport protocol (push/fetch)ExGitEngine.WireProtocol.ReceivePack— handlesgit pushExGitEngine.WireProtocol.UploadPack— handlesgit fetch/git pull
{:ok, agent} = ExGitEngine.GitAgent.start_link("/path/to/repo")
{:ok, ref} = ExGitEngine.GitAgent.reference_lookup(agent, "refs/heads/main")
{:ok, commit} = ExGitEngine.GitAgent.peel(agent, ref)
{:ok, message} = ExGitEngine.GitAgent.commit_message(agent, commit)Implement ExGitEngine.GitRepo to add custom push validation or post-push hooks:
defimpl ExGitEngine.GitRepo, for: MyRepo do
def get_agent(repo), do: {:ok, repo.agent_pid}
def pre_push(repo, cmds), do: :ok
def push(repo, cmds), do: {:ok, repo}
endMIT