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

Copy Markdown View Source

Git branch operations — checkout, current branch, stash, create, delete.

Summary

Functions

Returns true if the given branch exists locally or remotely.

Checks out the main_branch of a repository, stashing uncommitted changes first if necessary.

Returns the currently checked-out branch name.

Returns true if the repository has stash entries.

Returns the list of all local branches.

Stashes uncommitted changes if the working tree is dirty.

Restores stashed changes.

Pushes stash entries in a repository.

Functions

branch_exists?(branch)

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

Returns true if the given branch exists locally or remotely.

checkout(repo)

@spec checkout(map()) :: {:ok, map()} | {:error, any()}

Checks out the main_branch of a repository, stashing uncommitted changes first if necessary.

create_branch(repo_path, branch_name)

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

Creates a new branch.

delete_branch(repo_path, branch_name)

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

Deletes a branch.

get_current_branch(repo_path)

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

Returns the currently checked-out branch name.

has_stash?(repo_path)

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

Returns true if the repository has stash entries.

list_local_branches(repo_path)

@spec list_local_branches(binary()) :: {:ok, [binary()]} | {:error, any()}

Returns the list of all local branches.

stash_if_needed(repo_path)

@spec stash_if_needed(binary()) ::
  {:ok, {:stashed, binary()} | :clean} | {:error, any()}

Stashes uncommitted changes if the working tree is dirty.

Returns {:ok, {:stashed, branch}}, {:ok, :clean}, or {:error, reason}.

stash_pop(repo_path)

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

Restores stashed changes.

stash_push(repo_path, opts \\ [])

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

Pushes stash entries in a repository.

Options

  • :message — stash description (default: "auto-stash")
  • :include_untracked — include untracked files (default: true)