GitOps.Git (Git Ops v2.11.0)

View Source

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

Summary

Functions

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.

Force-pushes a commit or tag ref to origin.

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()

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()

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_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.