bc_gitops_git (bc_gitops v0.7.0)

View Source

Git operations for bc_gitops.

This module wraps git commands for cloning, pulling, and querying repository state. It uses the system git command for maximum compatibility.

Git authentication is handled through standard git mechanisms: SSH keys, credential helpers, or inline URL credentials. For CI/CD environments, SSH deploy keys are recommended.

Summary

Functions

Checkout a specific ref (branch, tag, or commit).

Clone a repository to the local path.

Ensure the repository exists locally, cloning if necessary.

Get the commit log for the last N commits.

Get the current HEAD commit SHA.

Check if a path is a git repository.

Pull the latest changes from the remote repository.

Functions

checkout(LocalPath, Ref)

-spec checkout(binary(), binary()) -> ok | {error, term()}.

Checkout a specific ref (branch, tag, or commit).

clone(RepoUrl, LocalPath, Branch)

-spec clone(binary(), binary(), binary()) -> ok | {error, term()}.

Clone a repository to the local path.

ensure_repo(RepoUrl, LocalPath, Branch)

-spec ensure_repo(binary(), binary(), binary()) -> ok | {error, term()}.

Ensure the repository exists locally, cloning if necessary.

If the local path exists and is a git repository, this does nothing. Otherwise, it clones the repository.

get_commit_log(LocalPath, Count)

-spec get_commit_log(binary(), pos_integer()) -> {ok, [map()]} | {error, term()}.

Get the commit log for the last N commits.

Returns a list of maps with commit info.

get_head_commit(LocalPath)

-spec get_head_commit(binary()) -> {ok, binary()} | {error, term()}.

Get the current HEAD commit SHA.

is_repo(Path)

-spec is_repo(file:filename()) -> boolean().

Check if a path is a git repository.

pull(LocalPath, Branch)

-spec pull(binary(), binary()) -> {ok, binary()} | {error, term()}.

Pull the latest changes from the remote repository.

Returns the commit SHA after pulling.