Trebejo.Git.Local.Utils (Trebejo v2.0.0)

Copy Markdown View Source

Utility functions for Git operations — command execution, shell quoting, CLI availability checks, and credential setup.

Summary

Functions

Builds git options for a repository path and optional timeout.

Checks if gh is available.

Checks if glab is available.

Checks if a repository has uncommitted changes.

Runs a git command with options.

Runs a system command with telemetry instrumentation.

Sets up a credential helper for git.

Configures Git credentials (SSH key path or credential helper).

Sets up an SSH key for git.

Quotes a binary string for safe shell use.

Functions

build_git_opts(repo_path, timeout)

@spec build_git_opts(binary(), integer() | nil) :: keyword()

Builds git options for a repository path and optional timeout.

gh_available?()

@spec gh_available?() :: boolean()

Checks if gh is available.

glab_available?()

@spec glab_available?() :: boolean()

Checks if glab is available.

has_uncommitted_changes?(repo_path)

@spec has_uncommitted_changes?(binary()) :: boolean()

Checks if a repository has uncommitted changes.

run_git(git_args, opts \\ [])

@spec run_git(
  [binary()],
  keyword()
) :: {:ok, map()} | {:error, any()}

Runs a git command with options.

Builds a shell-quoted command line from git_args and dispatches it via run_system_cmd/3.

run_system_cmd(cmd, telemetry_cmd_line, opts)

@spec run_system_cmd(binary(), binary(), keyword()) :: {:ok, map()} | {:error, any()}

Runs a system command with telemetry instrumentation.

Emits [:apero, :git, :command, :start|:stop|:error] telemetry events.

setup_credential_helper(credential_helper)

@spec setup_credential_helper(binary()) :: :ok | {:error, binary()}

Sets up a credential helper for git.

setup_credentials(opts \\ [])

@spec setup_credentials(keyword()) :: :ok | {:error, binary()}

Configures Git credentials (SSH key path or credential helper).

setup_ssh_key(ssh_key)

@spec setup_ssh_key(binary()) :: :ok | {:error, binary()}

Sets up an SSH key for git.

shell_quote(str)

@spec shell_quote(binary()) :: binary()

Quotes a binary string for safe shell use.