GitOps.Git (Git Ops v2.12.0)

View Source

Helper functions for working with Git and fetching the tags/commits we care about.

Summary

Functions

The blob OID contents would hash to.

The subject line of a commit.

Commits files (a map of repo-relative path to contents) on top of base_ref using a temporary index, leaving the working tree untouched. Returns the new commit's SHA.

First-parent commit SHAs of HEAD that touch path, newest first.

The name of the currently checked out branch.

Commit info since a tag (or all commits), newest first.

The blob OID at ref:path, or nil when absent. Resolved from tree objects alone, so it never fetches blobs on a partial clone.

Force-pushes a commit or tag ref to origin.

The tree hash of the origin remote's branch, or nil when the branch does not exist there.

The tag names present on the origin remote, or the local tags when there is no reachable remote.

The contents of path at ref, or :error if it does not exist there.

All tags starting with prefix, newest version first.

Types

commit_info()

@type commit_info() :: %{
  hash: String.t(),
  message: String.t(),
  author_name: String.t(),
  author_email: String.t()
}

Functions

add!(repo, args)

@spec add!(Git.Repository.t(), [String.t()]) :: String.t()

blob_oid(repo, contents)

@spec blob_oid(Git.Repository.t(), String.t()) :: String.t()

The blob OID contents would hash to.

commit!(repo, args)

@spec commit!(Git.Repository.t(), [String.t()]) :: String.t()

commit_subject!(repo, sha)

@spec commit_subject!(Git.Repository.t(), String.t()) :: String.t()

The subject line of a commit.

commit_tree!(repo, base_ref, files, message)

@spec commit_tree!(
  Git.Repository.t(),
  String.t(),
  %{required(String.t()) => String.t()},
  String.t()
) ::
  String.t()

Commits files (a map of repo-relative path to contents) on top of base_ref using a temporary index, leaving the working tree untouched. Returns the new commit's SHA.

commits_touching!(repo, path, limit)

@spec commits_touching!(Git.Repository.t(), String.t(), pos_integer()) :: [String.t()]

First-parent commit SHAs of HEAD that touch path, newest first.

current_branch!(repo)

@spec current_branch!(Git.Repository.t()) :: String.t()

The name of the currently checked out branch.

get_commit_info(repo, since_tag \\ :all, opts \\ [])

@spec get_commit_info(Git.Repository.t(), String.t() | :all, Keyword.t()) :: [
  commit_info()
]

Commit info since a tag (or all commits), newest first.

Options:

  • :paths - pathspecs restricting which commits count (git pathspec syntax, so :^dir entries exclude).
  • :first_parent - follow only the first parent of merge commits.

hooks_path(repo)

@spec hooks_path(Git.Repository.t()) :: String.t() | no_return()

init!(repo_path)

@spec init!(String.t()) :: Git.Repository.t()

initial_commit_message()

oid_at(repo, ref, path)

@spec oid_at(Git.Repository.t(), String.t(), String.t()) :: String.t() | nil

The blob OID at ref:path, or nil when absent. Resolved from tree objects alone, so it never fetches blobs on a partial clone.

parse_git_log(git_log_output)

@spec parse_git_log(String.t()) :: [commit_info()]

push!(repo, source, target)

@spec push!(Git.Repository.t(), String.t(), String.t()) :: :ok

Force-pushes a commit or tag ref to origin.

remote_branch_tree(repo, branch)

@spec remote_branch_tree(Git.Repository.t(), String.t()) :: String.t() | nil

The tree hash of the origin remote's branch, or nil when the branch does not exist there.

remote_tags(repo)

@spec remote_tags(Git.Repository.t()) :: MapSet.t(String.t())

The tag names present on the origin remote, or the local tags when there is no reachable remote.

show(repo, ref, path)

@spec show(Git.Repository.t(), String.t(), String.t()) :: {:ok, String.t()} | :error

The contents of path at ref, or :error if it does not exist there.

tag!(repo, current_version)

@spec tag!(Git.Repository.t(), String.t() | [String.t()]) :: String.t()

tag_exists?(repo, tag)

@spec tag_exists?(Git.Repository.t(), String.t()) :: boolean()

tags(repo)

@spec tags(Git.Repository.t()) :: [String.t()]

tags(repo, prefix)

@spec tags(Git.Repository.t(), String.t()) :: [String.t()]

All tags starting with prefix, newest version first.

Unlike tags/1, returns an empty list when nothing matches, so callers can treat "never released" as a normal state.