Workspace.Git (Workspace v0.2.1)

View Source

Helper git related functions

Summary

Functions

Detects the changed files in the given directory.

Get changed files between the given head and base git references.

Get the git repo root of the given path

Returns a list of uncommitted files

Get list of untracked files

Types

change_type()

@type change_type() :: :uncommitted | :untracked | :modified

Functions

changed(opts \\ [])

@spec changed(opts :: keyword()) ::
  {:ok, [{binary(), change_type()}]} | {:error, binary()}

Detects the changed files in the given directory.

By default the following files are included:

  • Uncommitted files in the working directory
  • Untracked files in the working directory
  • If :base is provided it also includes:
    • The changed files between :base and HEAD if no :head is set.
    • The changed files between :base and :head if :head is set.

A list of tuples of the form {"path/to/changed/file", change_type} is returned, where change_type can be one of the following:

  • :uncommitted - for changed files under version control that are not committed
  • :untracked - for new files that are not under version control
  • :modified - for changed committed files between the HEAD and the BASE

Options

  • :cd (binary/0) - The git repo path, defaults to the current working directory.
  • :base (binary/0) - The base reference to use for comparing to the HEAD, can be a branch, a commit or any other git reference.
  • :head (binary/0) - The head to use for comparing to :base, if not set defaults to HEAD. Can be any git reference

changed_files(head, base, opts \\ [])

@spec changed_files(head :: binary(), base :: binary(), opts :: keyword()) ::
  {:ok, [binary()]} | {:error, binary()}

Get changed files between the given head and base git references.

Options

  • :cd (binary/0) - The git repo path, defaults to the current working directory.

root(opts \\ [])

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

Get the git repo root of the given path

Returns {:ok, path} in case of success or {:error, reason} in case of failure.

Options

  • :cd - the path to use for getting the git root, if not set defaults to the current working directory.

uncommitted_files(opts \\ [])

@spec uncommitted_files(opts :: keyword()) :: {:ok, [binary()]} | {:error, binary()}

Returns a list of uncommitted files

Uncommitted are considered the files that are staged but not committed yet.

Options

  • :cd (binary/0) - The git repo path, defaults to the current working directory.

untracked_files(opts \\ [])

@spec untracked_files(opts :: keyword()) :: {:ok, [binary()]} | {:error, binary()}

Get list of untracked files

Options

  • :cd (binary/0) - The git repo path, defaults to the current working directory.